Skip to content

Commit 8a92e14

Browse files
authored
reconfigurator-cli could let you set SP versions (#8273)
1 parent d333576 commit 8a92e14

File tree

10 files changed

+441
-9
lines changed

10 files changed

+441
-9
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 67 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ fn process_command(
208208
Commands::SledRemove(args) => cmd_sled_remove(sim, args),
209209
Commands::SledShow(args) => cmd_sled_show(sim, args),
210210
Commands::SledSetPolicy(args) => cmd_sled_set_policy(sim, args),
211+
Commands::SledUpdateSp(args) => cmd_sled_update_sp(sim, args),
211212
Commands::SiloList => cmd_silo_list(sim),
212213
Commands::SiloAdd(args) => cmd_silo_add(sim, args),
213214
Commands::SiloRemove(args) => cmd_silo_remove(sim, args),
@@ -261,6 +262,8 @@ enum Commands {
261262
SledShow(SledArgs),
262263
/// set a sled's policy
263264
SledSetPolicy(SledSetPolicyArgs),
265+
/// simulate updating the sled's SP versions
266+
SledUpdateSp(SledUpdateSpArgs),
264267

265268
/// list silos
266269
SiloList,
@@ -372,6 +375,20 @@ impl From<SledPolicyOpt> for SledPolicy {
372375
}
373376
}
374377

378+
#[derive(Debug, Args)]
379+
struct SledUpdateSpArgs {
380+
/// id of the sled
381+
sled_id: SledUuid,
382+
383+
/// sets the version reported for the SP active slot
384+
#[clap(long, required_unless_present_any = &["inactive"])]
385+
active: Option<ArtifactVersion>,
386+
387+
/// sets the version reported for the SP inactive slot
388+
#[clap(long, required_unless_present_any = &["active"])]
389+
inactive: Option<ExpectedVersion>,
390+
}
391+
375392
#[derive(Debug, Args)]
376393
struct SledRemoveArgs {
377394
/// id of the sled
@@ -885,18 +902,22 @@ fn cmd_sled_show(
885902
args: SledArgs,
886903
) -> anyhow::Result<Option<String>> {
887904
let state = sim.current_state();
888-
let planning_input = state
889-
.system()
890-
.description()
905+
let description = state.system().description();
906+
let sled_id = args.sled_id;
907+
let sp_active_version = description.sled_sp_active_version(sled_id)?;
908+
let sp_inactive_version = description.sled_sp_inactive_version(sled_id)?;
909+
let planning_input = description
891910
.to_planning_input_builder()
892911
.context("failed to generate planning_input builder")?
893912
.build();
894-
let sled_id = args.sled_id;
895-
let sled_resources =
896-
&planning_input.sled_lookup(args.filter, sled_id)?.resources;
913+
let sled = planning_input.sled_lookup(args.filter, sled_id)?;
914+
let sled_resources = &sled.resources;
897915
let mut s = String::new();
898916
swriteln!(s, "sled {}", sled_id);
917+
swriteln!(s, "serial {}", sled.baseboard_id.serial_number);
899918
swriteln!(s, "subnet {}", sled_resources.subnet.net());
919+
swriteln!(s, "SP active version: {:?}", sp_active_version);
920+
swriteln!(s, "SP inactive version: {:?}", sp_inactive_version);
900921
swriteln!(s, "zpools ({}):", sled_resources.zpools.len());
901922
for (zpool, disk) in &sled_resources.zpools {
902923
swriteln!(s, " {:?}", zpool);
@@ -924,6 +945,46 @@ fn cmd_sled_set_policy(
924945
Ok(Some(format!("set sled {} policy to {}", args.sled_id, args.policy)))
925946
}
926947

948+
fn cmd_sled_update_sp(
949+
sim: &mut ReconfiguratorSim,
950+
args: SledUpdateSpArgs,
951+
) -> anyhow::Result<Option<String>> {
952+
let mut labels = Vec::new();
953+
if let Some(active) = &args.active {
954+
labels.push(format!("active -> {}", active));
955+
}
956+
if let Some(inactive) = &args.inactive {
957+
labels.push(format!("inactive -> {}", inactive));
958+
}
959+
960+
assert!(
961+
!labels.is_empty(),
962+
"clap configuration requires that at least one argument is specified"
963+
);
964+
965+
let mut state = sim.current_state().to_mut();
966+
state.system_mut().description_mut().sled_update_sp_versions(
967+
args.sled_id,
968+
args.active,
969+
args.inactive,
970+
)?;
971+
972+
sim.commit_and_bump(
973+
format!(
974+
"reconfigurator-cli sled-update-sp: {}: {}",
975+
args.sled_id,
976+
labels.join(", "),
977+
),
978+
state,
979+
);
980+
981+
Ok(Some(format!(
982+
"set sled {} SP versions: {}",
983+
args.sled_id,
984+
labels.join(", ")
985+
)))
986+
}
987+
927988
fn cmd_inventory_list(
928989
sim: &mut ReconfiguratorSim,
929990
) -> anyhow::Result<Option<String>> {

dev-tools/reconfigurator-cli/tests/input/cmds.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@ sled-add 90c1102a-b9f5-4d88-92a2-60d54a2d98cc
1313
sled-add 04ef3330-c682-4a08-8def-fcc4bef31bcd
1414
sled-list
1515

16+
sled-update-sp dde1c0e2-b10d-4621-b420-f179f7a7a00a
17+
sled-update-sp dde1c0e2-b10d-4621-b420-f179f7a7a00a --active 1.0.0
18+
sled-show dde1c0e2-b10d-4621-b420-f179f7a7a00a
19+
sled-update-sp dde1c0e2-b10d-4621-b420-f179f7a7a00a --inactive 2.0.0
20+
sled-show dde1c0e2-b10d-4621-b420-f179f7a7a00a
21+
sled-update-sp dde1c0e2-b10d-4621-b420-f179f7a7a00a --active 3.0.0
22+
sled-show dde1c0e2-b10d-4621-b420-f179f7a7a00a
23+
sled-update-sp dde1c0e2-b10d-4621-b420-f179f7a7a00a --active 4.0.0 --inactive invalid
24+
sled-show dde1c0e2-b10d-4621-b420-f179f7a7a00a
25+
sled-update-sp dde1c0e2-b10d-4621-b420-f179f7a7a00a --active 4.0.0 --inactive 5.0.0
26+
sled-show dde1c0e2-b10d-4621-b420-f179f7a7a00a
27+
1628
inventory-generate
1729
inventory-list
1830

dev-tools/reconfigurator-cli/tests/output/cmds-example-stdout

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ T ENA ID PARENT
3737

3838
> sled-show 2eb69596-f081-4e2d-9425-9994926e0832
3939
sled 2eb69596-f081-4e2d-9425-9994926e0832
40+
serial serial1
4041
subnet fd00:1122:3344:102::/64
42+
SP active version: Some("0.0.1")
43+
SP inactive version: None
4144
zpools (10):
4245
088ed702-551e-453b-80d7-57700372a844 (zpool)
4346
SledDisk { disk_identity: DiskIdentity { vendor: "fake-vendor", model: "fake-model", serial: "serial-088ed702-551e-453b-80d7-57700372a844" }, disk_id: b2850ccb-4ac7-4034-aeab-b1cd582d407b (physical_disk), policy: InService, state: Active }
@@ -395,7 +398,10 @@ T ENA ID PARENT
395398

396399
> sled-show 89d02b1b-478c-401a-8e28-7a26f74fa41b
397400
sled 89d02b1b-478c-401a-8e28-7a26f74fa41b
401+
serial serial0
398402
subnet fd00:1122:3344:101::/64
403+
SP active version: Some("0.0.1")
404+
SP inactive version: None
399405
zpools (4):
400406
44fa7024-c2bc-4d2c-b478-c4997e4aece8 (zpool)
401407
SledDisk { disk_identity: DiskIdentity { vendor: "fake-vendor", model: "fake-model", serial: "serial-44fa7024-c2bc-4d2c-b478-c4997e4aece8" }, disk_id: 2a15b33c-dd0e-45b7-aba9-d05f40f030ff (physical_disk), policy: InService, state: Active }
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
error: the following required arguments were not provided:
2+
--active <ACTIVE>
3+
--inactive <INACTIVE>
4+
5+
Usage: sled-update-sp --active <ACTIVE> --inactive <INACTIVE> <SLED_ID>
6+
7+
For more information, try '--help'.

0 commit comments

Comments
 (0)