| 1 |
use crate::domain::{GateKind, NodeId, TierId}; |
| 2 |
use anyhow::{Context, Result}; |
| 3 |
use serde::{Deserialize, Serialize}; |
| 4 |
use std::path::Path; |
| 5 |
|
| 6 |
#[derive(Debug, Clone, Serialize, Deserialize)] |
| 7 |
pub struct Topology { |
| 8 |
pub repo: RepoConfig, |
| 9 |
pub backup: BackupConfig, |
| 10 |
#[serde(rename = "tier")] |
| 11 |
pub tiers: Vec<Tier>, |
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#[serde(default, rename = "aux_repo")] |
| 17 |
pub aux_repos: Vec<AuxRepo>, |
| 18 |
} |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
#[derive(Debug, Clone, Serialize, Deserialize)] |
| 37 |
pub struct AuxRepo { |
| 38 |
|
| 39 |
pub name: String, |
| 40 |
|
| 41 |
|
| 42 |
pub bare_path: String, |
| 43 |
|
| 44 |
|
| 45 |
pub upstream: String, |
| 46 |
|
| 47 |
pub branch: String, |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
pub checkout_dir: String, |
| 54 |
} |
| 55 |
|
| 56 |
#[derive(Debug, Clone, Serialize, Deserialize)] |
| 57 |
pub struct RepoConfig { |
| 58 |
pub bare_path: String, |
| 59 |
pub branch: String, |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
#[serde(default)] |
| 66 |
pub upstream: Option<String>, |
| 67 |
} |
| 68 |
|
| 69 |
#[derive(Debug, Clone, Serialize, Deserialize)] |
| 70 |
pub struct BackupConfig { |
| 71 |
pub source: String, |
| 72 |
pub local_path: String, |
| 73 |
} |
| 74 |
|
| 75 |
#[derive(Debug, Clone, Serialize, Deserialize)] |
| 76 |
pub struct Tier { |
| 77 |
pub name: TierId, |
| 78 |
#[serde(default)] |
| 79 |
pub provisioned: bool, |
| 80 |
pub gates: Vec<Gate>, |
| 81 |
#[serde(default)] |
| 82 |
pub canary: CanaryPolicy, |
| 83 |
#[serde(default, rename = "node")] |
| 84 |
pub nodes: Vec<Node>, |
| 85 |
} |
| 86 |
|
| 87 |
#[derive(Debug, Clone, Serialize, Deserialize)] |
| 88 |
pub struct Node { |
| 89 |
pub name: NodeId, |
| 90 |
pub ssh_target: String, |
| 91 |
pub release_root: String, |
| 92 |
|
| 93 |
|
| 94 |
#[serde(default = "default_service_name")] |
| 95 |
pub service_name: String, |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
#[serde(default)] |
| 106 |
pub config_check_env_file: Option<String>, |
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
#[serde(default = "default_actuate")] |
| 111 |
pub actuate: Vec<String>, |
| 112 |
#[serde(default = "default_observe")] |
| 113 |
pub observe: Vec<String>, |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
#[serde(default)] |
| 121 |
pub health_url: Option<String>, |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
#[serde(default, rename = "companion")] |
| 129 |
pub companions: Vec<NodeCompanion>, |
| 130 |
} |
| 131 |
|
| 132 |
|
| 133 |
#[derive(Debug, Clone, Serialize, Deserialize)] |
| 134 |
pub struct NodeCompanion { |
| 135 |
|
| 136 |
pub name: String, |
| 137 |
|
| 138 |
|
| 139 |
pub install_path: String, |
| 140 |
|
| 141 |
|
| 142 |
pub service_name: String, |
| 143 |
} |
| 144 |
|
| 145 |
fn default_service_name() -> String { |
| 146 |
"makenotwork.service".into() |
| 147 |
} |
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
pub fn default_actuate() -> Vec<String> { |
| 153 |
vec!["deploy".into(), "restart".into()] |
| 154 |
} |
| 155 |
pub fn default_observe() -> Vec<String> { |
| 156 |
vec!["health".into()] |
| 157 |
} |
| 158 |
|
| 159 |
#[derive(Debug, Clone, Copy, Serialize, Deserialize, Default)] |
| 160 |
#[serde(rename_all = "snake_case")] |
| 161 |
pub enum CanaryPolicy { |
| 162 |
#[default] |
| 163 |
Sequential, |
| 164 |
Parallel, |
| 165 |
} |
| 166 |
|
| 167 |
impl CanaryPolicy { |
| 168 |
pub fn as_str(self) -> &'static str { |
| 169 |
match self { |
| 170 |
CanaryPolicy::Sequential => "sequential", |
| 171 |
CanaryPolicy::Parallel => "parallel", |
| 172 |
} |
| 173 |
} |
| 174 |
} |
| 175 |
|
| 176 |
#[derive(Debug, Clone, Serialize, Deserialize)] |
| 177 |
#[serde(tag = "kind", rename_all = "snake_case")] |
| 178 |
pub enum Gate { |
| 179 |
CargoTest, |
| 180 |
HardeningTest, |
| 181 |
Clippy, |
| 182 |
Fmt, |
| 183 |
CargoAudit, |
| 184 |
CargoDeny, |
| 185 |
MigrationDryRun, |
| 186 |
CodeSmoke, |
| 187 |
BootSmoke, |
| 188 |
NodeHealth, |
| 189 |
BurnIn { hours: u32 }, |
| 190 |
ManualConfirm, |
| 191 |
} |
| 192 |
|
| 193 |
impl Gate { |
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
pub fn kind(&self) -> GateKind { |
| 198 |
match self { |
| 199 |
Gate::CargoTest => GateKind::CargoTest, |
| 200 |
Gate::HardeningTest => GateKind::HardeningTest, |
| 201 |
Gate::Clippy => GateKind::Clippy, |
| 202 |
Gate::Fmt => GateKind::Fmt, |
| 203 |
Gate::CargoAudit => GateKind::CargoAudit, |
| 204 |
Gate::CargoDeny => GateKind::CargoDeny, |
| 205 |
Gate::MigrationDryRun => GateKind::MigrationDryRun, |
| 206 |
Gate::CodeSmoke => GateKind::CodeSmoke, |
| 207 |
Gate::BootSmoke => GateKind::BootSmoke, |
| 208 |
Gate::NodeHealth => GateKind::NodeHealth, |
| 209 |
Gate::BurnIn { .. } => GateKind::BurnIn, |
| 210 |
Gate::ManualConfirm => GateKind::ManualConfirm, |
| 211 |
} |
| 212 |
} |
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
pub fn runs_post_deploy(&self) -> bool { |
| 223 |
matches!(self, Gate::NodeHealth) |
| 224 |
} |
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
pub fn guards_promotion(&self) -> bool { |
| 235 |
matches!( |
| 236 |
self, |
| 237 |
Gate::NodeHealth | Gate::BurnIn { .. } | Gate::ManualConfirm |
| 238 |
) |
| 239 |
} |
| 240 |
} |
| 241 |
|
| 242 |
impl Topology { |
| 243 |
pub fn load(path: &Path) -> Result<Self> { |
| 244 |
let raw = std::fs::read_to_string(path) |
| 245 |
.with_context(|| format!("reading topology at {}", path.display()))?; |
| 246 |
let topo: Topology = toml::from_str(&raw)?; |
| 247 |
topo.validate()?; |
| 248 |
Ok(topo) |
| 249 |
} |
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
pub fn ensure_build_host_not_serving(&self, build_host: &str) -> Result<()> { |
| 258 |
for t in &self.tiers { |
| 259 |
if !t.provisioned || t.name.as_str() == "host" { |
| 260 |
continue; |
| 261 |
} |
| 262 |
for n in &t.nodes { |
| 263 |
if n.name.as_str() == build_host || n.ssh_target == build_host { |
| 264 |
anyhow::bail!( |
| 265 |
"build_host {build_host:?} is also node {} (ssh {}) in serving tier {} — \ |
| 266 |
the builder must not be a prod/serving node", |
| 267 |
n.name, |
| 268 |
n.ssh_target, |
| 269 |
t.name |
| 270 |
); |
| 271 |
} |
| 272 |
} |
| 273 |
} |
| 274 |
Ok(()) |
| 275 |
} |
| 276 |
|
| 277 |
#[cfg(test)] |
| 278 |
pub(crate) fn validate_for_test(&self) -> Result<()> { |
| 279 |
self.validate() |
| 280 |
} |
| 281 |
|
| 282 |
fn validate(&self) -> Result<()> { |
| 283 |
anyhow::ensure!( |
| 284 |
!self.tiers.is_empty(), |
| 285 |
"topology must declare at least one tier" |
| 286 |
); |
| 287 |
for t in &self.tiers { |
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
let is_build_tier = t.name.as_str() == "host"; |
| 293 |
if t.provisioned && t.nodes.is_empty() && !is_build_tier { |
| 294 |
anyhow::bail!("tier {} is provisioned but has no nodes", t.name); |
| 295 |
} |
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
if t.provisioned && !is_build_tier && !t.gates.iter().any(Gate::guards_promotion) { |
| 301 |
anyhow::bail!( |
| 302 |
"tier {} is provisioned to serve but declares no promotion gate \ |
| 303 |
(need at least one of node_health / burn_in / manual_confirm)", |
| 304 |
t.name |
| 305 |
); |
| 306 |
} |
| 307 |
} |
| 308 |
let mut seen_dirs: Vec<Vec<&str>> = Vec::new(); |
| 309 |
for aux in &self.aux_repos { |
| 310 |
anyhow::ensure!( |
| 311 |
!aux.name.is_empty() && !aux.bare_path.is_empty() && !aux.branch.is_empty(), |
| 312 |
"aux_repo entry has an empty name/bare_path/branch" |
| 313 |
); |
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
let dir = &aux.checkout_dir; |
| 319 |
let parts: Vec<&str> = dir.split('/').collect(); |
| 320 |
anyhow::ensure!( |
| 321 |
!dir.is_empty() |
| 322 |
&& !dir.contains('\\') |
| 323 |
&& parts |
| 324 |
.iter() |
| 325 |
.all(|c| !c.is_empty() && *c != "." && *c != ".."), |
| 326 |
"aux_repo {} has an unsafe checkout_dir {dir:?} (must be a relative path of \ |
| 327 |
plain components: no leading slash, empty segments, or dot-dot)", |
| 328 |
aux.name, |
| 329 |
); |
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
for prior in &seen_dirs { |
| 334 |
let common = prior.len().min(parts.len()); |
| 335 |
anyhow::ensure!( |
| 336 |
prior[..common] != parts[..common], |
| 337 |
"two aux_repo entries share or nest checkout_dir {dir:?}; \ |
| 338 |
they would clobber each other" |
| 339 |
); |
| 340 |
} |
| 341 |
seen_dirs.push(parts); |
| 342 |
} |
| 343 |
Ok(()) |
| 344 |
} |
| 345 |
} |
| 346 |
|
| 347 |
#[cfg(test)] |
| 348 |
mod tests { |
| 349 |
use super::*; |
| 350 |
|
| 351 |
|
| 352 |
fn topo_with_serving_gates(provisioned: bool, gates: &str) -> Topology { |
| 353 |
let raw = format!( |
| 354 |
r#" |
| 355 |
[repo] |
| 356 |
bare_path = "/tmp/repo.git" |
| 357 |
branch = "main" |
| 358 |
|
| 359 |
[backup] |
| 360 |
source = "ssh://prod/dump.sql.gz" |
| 361 |
local_path = "/tmp/dump.sql.gz" |
| 362 |
|
| 363 |
[[tier]] |
| 364 |
name = "b" |
| 365 |
provisioned = {provisioned} |
| 366 |
gates = [{gates}] |
| 367 |
[[tier.node]] |
| 368 |
name = "prod-1" |
| 369 |
ssh_target = "prod-1" |
| 370 |
release_root = "/srv/mnw" |
| 371 |
"# |
| 372 |
); |
| 373 |
toml::from_str(&raw).expect("parse test topology") |
| 374 |
} |
| 375 |
|
| 376 |
#[test] |
| 377 |
fn provisioned_serving_tier_with_no_gates_is_rejected() { |
| 378 |
let topo = topo_with_serving_gates(true, ""); |
| 379 |
let err = topo.validate_for_test().unwrap_err().to_string(); |
| 380 |
assert!(err.contains("no promotion gate"), "{err}"); |
| 381 |
} |
| 382 |
|
| 383 |
#[test] |
| 384 |
fn provisioned_serving_tier_with_only_build_gates_is_rejected() { |
| 385 |
|
| 386 |
|
| 387 |
let topo = topo_with_serving_gates( |
| 388 |
true, |
| 389 |
r#"{ kind = "cargo_test" }, { kind = "migration_dry_run" }"#, |
| 390 |
); |
| 391 |
let err = topo.validate_for_test().unwrap_err().to_string(); |
| 392 |
assert!(err.contains("no promotion gate"), "{err}"); |
| 393 |
} |
| 394 |
|
| 395 |
#[test] |
| 396 |
fn provisioned_serving_tier_with_a_promotion_gate_is_accepted() { |
| 397 |
let topo = topo_with_serving_gates(true, r#"{ kind = "node_health" }"#); |
| 398 |
assert!(topo.validate_for_test().is_ok()); |
| 399 |
} |
| 400 |
|
| 401 |
#[test] |
| 402 |
fn provisioned_serving_tier_with_only_boot_smoke_is_rejected() { |
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
let topo = topo_with_serving_gates(true, r#"{ kind = "boot_smoke" }"#); |
| 407 |
let err = topo.validate_for_test().unwrap_err().to_string(); |
| 408 |
assert!(err.contains("no promotion gate"), "{err}"); |
| 409 |
} |
| 410 |
|
| 411 |
#[test] |
| 412 |
fn unprovisioned_tier_with_empty_gates_is_skipped() { |
| 413 |
|
| 414 |
|
| 415 |
let topo = topo_with_serving_gates(false, ""); |
| 416 |
assert!(topo.validate_for_test().is_ok()); |
| 417 |
} |
| 418 |
|
| 419 |
#[test] |
| 420 |
fn build_host_matching_a_serving_node_is_rejected() { |
| 421 |
|
| 422 |
|
| 423 |
let topo = topo_with_serving_gates(true, r#"{ kind = "node_health" }"#); |
| 424 |
let err = topo |
| 425 |
.ensure_build_host_not_serving("prod-1") |
| 426 |
.unwrap_err() |
| 427 |
.to_string(); |
| 428 |
assert!(err.contains("must not be a prod/serving node"), "{err}"); |
| 429 |
} |
| 430 |
|
| 431 |
#[test] |
| 432 |
fn build_host_distinct_from_serving_nodes_is_accepted() { |
| 433 |
let topo = topo_with_serving_gates(true, r#"{ kind = "node_health" }"#); |
| 434 |
assert!(topo.ensure_build_host_not_serving("fw13").is_ok()); |
| 435 |
} |
| 436 |
|
| 437 |
#[test] |
| 438 |
fn node_companions_default_empty_and_parse_when_present() { |
| 439 |
|
| 440 |
let plain = topo_with_serving_gates(true, r#"{ kind = "node_health" }"#); |
| 441 |
assert!(plain.tiers[0].nodes[0].companions.is_empty()); |
| 442 |
|
| 443 |
|
| 444 |
let raw = r#" |
| 445 |
[repo] |
| 446 |
bare_path = "/tmp/repo.git" |
| 447 |
branch = "main" |
| 448 |
[backup] |
| 449 |
source = "s" |
| 450 |
local_path = "/tmp/d" |
| 451 |
[[tier]] |
| 452 |
name = "b" |
| 453 |
provisioned = true |
| 454 |
gates = [{ kind = "node_health" }] |
| 455 |
[[tier.node]] |
| 456 |
name = "prod-1" |
| 457 |
ssh_target = "makenotwork@alpha-west-1" |
| 458 |
release_root = "/opt/mnw" |
| 459 |
[[tier.node.companion]] |
| 460 |
name = "mnw-cli" |
| 461 |
install_path = "/opt/mnw-cli/mnw-cli" |
| 462 |
service_name = "mnw-cli.service" |
| 463 |
"#; |
| 464 |
let topo: Topology = toml::from_str(raw).expect("parse companion topology"); |
| 465 |
let c = &topo.tiers[0].nodes[0].companions; |
| 466 |
assert_eq!(c.len(), 1); |
| 467 |
assert_eq!(c[0].name, "mnw-cli"); |
| 468 |
assert_eq!(c[0].install_path, "/opt/mnw-cli/mnw-cli"); |
| 469 |
assert_eq!(c[0].service_name, "mnw-cli.service"); |
| 470 |
} |
| 471 |
|
| 472 |
fn topo_with_aux(aux_block: &str) -> Result<Topology> { |
| 473 |
let raw = format!( |
| 474 |
r#" |
| 475 |
[repo] |
| 476 |
bare_path = "/tmp/repo.git" |
| 477 |
branch = "main" |
| 478 |
[backup] |
| 479 |
source = "s" |
| 480 |
local_path = "/tmp/d" |
| 481 |
[[tier]] |
| 482 |
name = "b" |
| 483 |
provisioned = true |
| 484 |
gates = [{{ kind = "node_health" }}] |
| 485 |
[[tier.node]] |
| 486 |
name = "prod-1" |
| 487 |
ssh_target = "prod-1" |
| 488 |
release_root = "/srv/mnw" |
| 489 |
{aux_block} |
| 490 |
"# |
| 491 |
); |
| 492 |
let topo: Topology = toml::from_str(&raw)?; |
| 493 |
topo.validate_for_test()?; |
| 494 |
Ok(topo) |
| 495 |
} |
| 496 |
|
| 497 |
#[test] |
| 498 |
fn aux_repos_default_empty() { |
| 499 |
let topo = topo_with_aux("").expect("no aux_repo block is fine"); |
| 500 |
assert!(topo.aux_repos.is_empty()); |
| 501 |
} |
| 502 |
|
| 503 |
#[test] |
| 504 |
fn aux_repo_parses_all_fields() { |
| 505 |
let topo = topo_with_aux( |
| 506 |
r#" |
| 507 |
[[aux_repo]] |
| 508 |
name = "synckit" |
| 509 |
bare_path = "/srv/sando/synckit.git" |
| 510 |
upstream = "git@ssh.makenot.work:max/synckit.git" |
| 511 |
branch = "main" |
| 512 |
checkout_dir = "synckit""#, |
| 513 |
) |
| 514 |
.expect("valid aux_repo parses"); |
| 515 |
assert_eq!(topo.aux_repos.len(), 1); |
| 516 |
let a = &topo.aux_repos[0]; |
| 517 |
assert_eq!(a.name, "synckit"); |
| 518 |
assert_eq!(a.bare_path, "/srv/sando/synckit.git"); |
| 519 |
assert_eq!(a.upstream, "git@ssh.makenot.work:max/synckit.git"); |
| 520 |
assert_eq!(a.branch, "main"); |
| 521 |
assert_eq!(a.checkout_dir, "synckit"); |
| 522 |
} |
| 523 |
|
| 524 |
#[test] |
| 525 |
fn aux_repo_with_nested_checkout_dir_is_accepted() { |
| 526 |
let topo = topo_with_aux( |
| 527 |
r#" |
| 528 |
[[aux_repo]] |
| 529 |
name = "docengine" |
| 530 |
bare_path = "/srv/sando/docengine.git" |
| 531 |
upstream = "git@ssh.makenot.work:max/docengine.git" |
| 532 |
branch = "main" |
| 533 |
checkout_dir = "Libraries/docengine""#, |
| 534 |
) |
| 535 |
.expect("a nested checkout_dir is a valid location"); |
| 536 |
assert_eq!(topo.aux_repos[0].checkout_dir, "Libraries/docengine"); |
| 537 |
} |
| 538 |
|
| 539 |
#[test] |
| 540 |
fn aux_repo_with_traversing_checkout_dir_is_rejected() { |
| 541 |
for bad in [ |
| 542 |
"../escape", |
| 543 |
"a/../../escape", |
| 544 |
"a/./b", |
| 545 |
"a//b", |
| 546 |
"/abs", |
| 547 |
"a/", |
| 548 |
"..", |
| 549 |
".", |
| 550 |
] { |
| 551 |
let err = topo_with_aux(&format!( |
| 552 |
r#" |
| 553 |
[[aux_repo]] |
| 554 |
name = "x" |
| 555 |
bare_path = "/srv/sando/x.git" |
| 556 |
upstream = "u" |
| 557 |
branch = "main" |
| 558 |
checkout_dir = "{bad}""#, |
| 559 |
)) |
| 560 |
.unwrap_err() |
| 561 |
.to_string(); |
| 562 |
assert!(err.contains("unsafe checkout_dir"), "for {bad:?}: {err}"); |
| 563 |
} |
| 564 |
} |
| 565 |
|
| 566 |
#[test] |
| 567 |
fn aux_repos_sharing_a_checkout_dir_are_rejected() { |
| 568 |
let err = topo_with_aux( |
| 569 |
r#" |
| 570 |
[[aux_repo]] |
| 571 |
name = "one" |
| 572 |
bare_path = "/srv/sando/one.git" |
| 573 |
upstream = "u" |
| 574 |
branch = "main" |
| 575 |
checkout_dir = "shared" |
| 576 |
[[aux_repo]] |
| 577 |
name = "two" |
| 578 |
bare_path = "/srv/sando/two.git" |
| 579 |
upstream = "u" |
| 580 |
branch = "main" |
| 581 |
checkout_dir = "shared""#, |
| 582 |
) |
| 583 |
.unwrap_err() |
| 584 |
.to_string(); |
| 585 |
assert!(err.contains("share or nest checkout_dir"), "{err}"); |
| 586 |
} |
| 587 |
|
| 588 |
#[test] |
| 589 |
fn aux_repo_nested_inside_another_checkout_dir_is_rejected() { |
| 590 |
let err = topo_with_aux( |
| 591 |
r#" |
| 592 |
[[aux_repo]] |
| 593 |
name = "outer" |
| 594 |
bare_path = "/srv/sando/outer.git" |
| 595 |
upstream = "u" |
| 596 |
branch = "main" |
| 597 |
checkout_dir = "Libraries" |
| 598 |
[[aux_repo]] |
| 599 |
name = "inner" |
| 600 |
bare_path = "/srv/sando/inner.git" |
| 601 |
upstream = "u" |
| 602 |
branch = "main" |
| 603 |
checkout_dir = "Libraries/docengine""#, |
| 604 |
) |
| 605 |
.unwrap_err() |
| 606 |
.to_string(); |
| 607 |
assert!(err.contains("share or nest checkout_dir"), "{err}"); |
| 608 |
} |
| 609 |
|
| 610 |
#[test] |
| 611 |
fn real_sando_toml_loads_clean() { |
| 612 |
|
| 613 |
|
| 614 |
let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("../sando.toml"); |
| 615 |
Topology::load(&path).expect("shipped sando.toml must validate"); |
| 616 |
} |
| 617 |
|
| 618 |
fn shipped() -> Topology { |
| 619 |
let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("../sando.toml"); |
| 620 |
Topology::load(&path).expect("shipped sando.toml must validate") |
| 621 |
} |
| 622 |
|
| 623 |
#[test] |
| 624 |
fn shipping_to_the_last_provisioned_tier_needs_an_operator_signoff() { |
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
let topo = shipped(); |
| 634 |
let last = topo |
| 635 |
.tiers |
| 636 |
.iter() |
| 637 |
.rposition(|t| t.provisioned) |
| 638 |
.expect("some tier must be provisioned"); |
| 639 |
assert!(last > 0, "the production tier cannot be the first tier"); |
| 640 |
let guard = &topo.tiers[last - 1]; |
| 641 |
assert!( |
| 642 |
guard.gates.iter().any(|g| matches!(g, Gate::ManualConfirm)), |
| 643 |
"tier {} guards promotion into the last provisioned tier ({}), so it must require an operator sign-off; its gates are {:?}", |
| 644 |
guard.name, |
| 645 |
topo.tiers[last].name, |
| 646 |
guard |
| 647 |
.gates |
| 648 |
.iter() |
| 649 |
.map(|g| g.kind().as_str()) |
| 650 |
.collect::<Vec<_>>(), |
| 651 |
); |
| 652 |
} |
| 653 |
|
| 654 |
#[test] |
| 655 |
fn every_serving_node_has_a_readiness_probe() { |
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
let topo = shipped(); |
| 660 |
for tier in topo.tiers.iter().filter(|t| t.provisioned) { |
| 661 |
for node in &tier.nodes { |
| 662 |
assert!( |
| 663 |
node.health_url.is_some(), |
| 664 |
"node {} on tier {} has no health_url, so node_health proves only that systemd thinks the unit is running", |
| 665 |
node.name, |
| 666 |
tier.name, |
| 667 |
); |
| 668 |
} |
| 669 |
} |
| 670 |
} |
| 671 |
} |
| 672 |
|