Skip to content

Commit 2b32fc6

Browse files
authored
[26/n] [reconfigurator-cli] add a way to temporarily hide a sled from inventory (#8500)
Simulate a sled in the middle of rebooting, or some other temporary issue causing the sled to not be present in an inventory collection.
1 parent 8d4cbae commit 2b32fc6

File tree

4 files changed

+368
-4
lines changed

4 files changed

+368
-4
lines changed

dev-tools/reconfigurator-cli/src/lib.rs

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ use nexus_reconfigurator_blippy::BlippyReportSortKey;
1919
use nexus_reconfigurator_planning::blueprint_builder::BlueprintBuilder;
2020
use nexus_reconfigurator_planning::example::ExampleSystemBuilder;
2121
use nexus_reconfigurator_planning::planner::Planner;
22-
use nexus_reconfigurator_planning::system::{SledBuilder, SystemDescription};
22+
use nexus_reconfigurator_planning::system::{
23+
SledBuilder, SledInventoryVisibility, SystemDescription,
24+
};
2325
use nexus_reconfigurator_simulation::{BlueprintId, SimState};
2426
use nexus_reconfigurator_simulation::{SimStateBuilder, SimTufRepoSource};
2527
use nexus_reconfigurator_simulation::{SimTufRepoDescription, Simulator};
@@ -374,6 +376,8 @@ struct SledSetArgs {
374376
enum SledSetCommand {
375377
/// set the policy for this sled
376378
Policy(SledSetPolicyArgs),
379+
#[clap(flatten)]
380+
Visibility(SledSetVisibilityCommand),
377381
}
378382

379383
#[derive(Debug, Args)]
@@ -383,6 +387,27 @@ struct SledSetPolicyArgs {
383387
policy: SledPolicyOpt,
384388
}
385389

390+
#[derive(Debug, Subcommand)]
391+
enum SledSetVisibilityCommand {
392+
/// mark a sled hidden from inventory
393+
InventoryHidden,
394+
/// mark a sled visible in inventory
395+
InventoryVisible,
396+
}
397+
398+
impl SledSetVisibilityCommand {
399+
fn to_visibility(&self) -> SledInventoryVisibility {
400+
match self {
401+
SledSetVisibilityCommand::InventoryHidden => {
402+
SledInventoryVisibility::Hidden
403+
}
404+
SledSetVisibilityCommand::InventoryVisible => {
405+
SledInventoryVisibility::Visible
406+
}
407+
}
408+
}
409+
}
410+
386411
#[derive(Clone, Copy, Debug, ValueEnum)]
387412
enum SledPolicyOpt {
388413
InService,
@@ -1227,6 +1252,30 @@ fn cmd_sled_set(
12271252
);
12281253
Ok(Some(format!("set sled {sled_id} policy to {policy}")))
12291254
}
1255+
SledSetCommand::Visibility(command) => {
1256+
let new = command.to_visibility();
1257+
let prev = system
1258+
.description_mut()
1259+
.sled_set_inventory_visibility(sled_id, new)?;
1260+
if prev == new {
1261+
Ok(Some(format!(
1262+
"sled {sled_id} inventory visibility was already set to \
1263+
{new}, so no changes were performed",
1264+
)))
1265+
} else {
1266+
sim.commit_and_bump(
1267+
format!(
1268+
"reconfigurator-cli sled-set inventory visibility: {} \
1269+
from {} to {}",
1270+
sled_id, prev, new,
1271+
),
1272+
state,
1273+
);
1274+
Ok(Some(format!(
1275+
"set sled {sled_id} inventory visibility: {prev} -> {new}"
1276+
)))
1277+
}
1278+
}
12301279
}
12311280
}
12321281

dev-tools/reconfigurator-cli/tests/input/cmds-noop-image-source.txt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# so that discretionary zones don't make their way onto it. (We're going to
33
# expunge it below to test that we don't try and update zone image sources
44
# on expunged sleds.)
5-
load-example --nsleds 6 --ndisks-per-sled 1 --sled-policy 5:non-provisionable
5+
load-example --nsleds 7 --ndisks-per-sled 1 --sled-policy 5:non-provisionable
66

77
sled-list
88

@@ -42,9 +42,25 @@ sled-update-install-dataset serial4 --from-repo repo-2.0.0.zip
4242
sled-update-install-dataset serial5 --to-target-release
4343
sled-set serial5 policy expunged
4444

45+
# On the seventh sled, update to the target release but hide the sled
46+
# from inventory. This should prevent changes to the blueprint for
47+
# this sled.
48+
sled-update-install-dataset serial6 --to-target-release
49+
sled-set serial6 inventory-hidden
50+
4551
# Generate an inventory and run a blueprint planning step.
4652
inventory-generate
4753
blueprint-plan latest eb0796d5-ab8a-4f7b-a884-b4aeacb8ab51
4854

4955
# This diff should show expected changes to the blueprint.
5056
blueprint-diff 8da82a8e-bf97-4fbd-8ddd-9f6462732cf1 latest
57+
58+
# Bring the hidden sled back.
59+
sled-set serial6 inventory-visible
60+
61+
# Run another inventory and blueprint planning step.
62+
inventory-generate
63+
blueprint-plan latest 61f451b3-2121-4ed6-91c7-a550054f6c21
64+
65+
# This diff should show changes to the sled that's back in inventory.
66+
blueprint-diff 58d5e830-0884-47d8-a7cd-b2b3751adeb4 latest

0 commit comments

Comments
 (0)