Skip to content

Commit fd2d5f4

Browse files
authored
[23/n] [reconfigurator-cli] allow setting sled policy in more situations (#8491)
Enable setting sled policy while loading up an initial example, and while adding a new sled. Also make it so that discretionary zones don't end up on non-provisionable sleds during the initial example.
1 parent d42c870 commit fd2d5f4

File tree

7 files changed

+646
-60
lines changed

7 files changed

+646
-60
lines changed

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

Lines changed: 67 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,10 @@ struct SledAddArgs {
337337
/// number of disks or pools
338338
#[clap(short = 'd', long, visible_alias = "npools", default_value_t = SledBuilder::DEFAULT_NPOOLS)]
339339
ndisks: u8,
340+
341+
/// The policy for the sled.
342+
#[clap(long, value_enum, default_value_t = SledPolicyOpt::InService)]
343+
policy: SledPolicyOpt,
340344
}
341345

342346
#[derive(Debug, Args)]
@@ -847,6 +851,44 @@ struct LoadExampleArgs {
847851
/// Do not create entries for disks in the blueprint.
848852
#[clap(long)]
849853
no_disks_in_blueprint: bool,
854+
855+
/// Set a 0-indexed sled's policy
856+
#[clap(long, value_name = "INDEX:POLICY")]
857+
sled_policy: Vec<LoadExampleSledPolicy>,
858+
}
859+
860+
#[derive(Clone, Debug)]
861+
struct LoadExampleSledPolicy {
862+
/// The index of the sled to set the policy for.
863+
index: usize,
864+
865+
/// The policy to set.
866+
policy: SledPolicy,
867+
}
868+
869+
impl FromStr for LoadExampleSledPolicy {
870+
type Err = anyhow::Error;
871+
872+
fn from_str(s: &str) -> Result<Self, Self::Err> {
873+
let (index, policy) = s
874+
.split_once(':')
875+
.context("invalid format, expected <index>:<policy>")?;
876+
let index = index.parse().with_context(|| {
877+
format!("error parsing sled index `{index}` as a usize")
878+
})?;
879+
let policy = SledPolicyOpt::from_str(
880+
policy, /* ignore_case */ false,
881+
)
882+
.map_err(|_message| {
883+
// _message is just something like "invalid variant: <value>".
884+
// We choose to use our own message instead.
885+
anyhow!(
886+
"invalid sled policy `{policy}` (possible values: {})",
887+
SledPolicyOpt::value_variants().iter().join(", "),
888+
)
889+
})?;
890+
Ok(LoadExampleSledPolicy { index, policy: policy.into() })
891+
}
850892
}
851893

852894
#[derive(Debug, Args)]
@@ -954,7 +996,10 @@ fn cmd_sled_add(
954996
) -> anyhow::Result<Option<String>> {
955997
let mut state = sim.current_state().to_mut();
956998
let sled_id = add.sled_id.unwrap_or_else(|| state.rng_mut().next_sled_id());
957-
let new_sled = SledBuilder::new().id(sled_id).npools(add.ndisks);
999+
let new_sled = SledBuilder::new()
1000+
.id(sled_id)
1001+
.npools(add.ndisks)
1002+
.policy(add.policy.into());
9581003
let system = state.system_mut();
9591004
system.description_mut().sled(new_sled)?;
9601005
// Figure out what serial number this sled was assigned.
@@ -1008,7 +1053,7 @@ fn cmd_sled_show(
10081053
let sled = planning_input.sled_lookup(args.filter, sled_id)?;
10091054
let sled_resources = &sled.resources;
10101055
let mut s = String::new();
1011-
swriteln!(s, "sled {}", sled_id);
1056+
swriteln!(s, "sled {} ({}, {})", sled_id, sled.policy, sled.state);
10121057
swriteln!(s, "serial {}", sled.baseboard_id.serial_number);
10131058
swriteln!(s, "subnet {}", sled_resources.subnet.net());
10141059
swriteln!(s, "SP active version: {:?}", sp_active_version);
@@ -2006,21 +2051,26 @@ fn cmd_load_example(
20062051
};
20072052
let rng = state.rng_mut().next_example_rng();
20082053

2009-
let (example, blueprint) =
2010-
ExampleSystemBuilder::new_with_rng(&sim.log, rng)
2011-
.nsleds(args.nsleds)
2012-
.ndisks_per_sled(args.ndisks_per_sled)
2013-
.nexus_count(
2014-
state
2015-
.config_mut()
2016-
.num_nexus()
2017-
.map_or(NEXUS_REDUNDANCY, |n| n.into()),
2018-
)
2019-
.external_dns_count(3)
2020-
.context("invalid external DNS zone count")?
2021-
.create_zones(!args.no_zones)
2022-
.create_disks_in_blueprint(!args.no_disks_in_blueprint)
2023-
.build();
2054+
let mut builder = ExampleSystemBuilder::new_with_rng(&sim.log, rng)
2055+
.nsleds(args.nsleds)
2056+
.ndisks_per_sled(args.ndisks_per_sled)
2057+
.nexus_count(
2058+
state
2059+
.config_mut()
2060+
.num_nexus()
2061+
.map_or(NEXUS_REDUNDANCY, |n| n.into()),
2062+
)
2063+
.external_dns_count(3)
2064+
.context("invalid external DNS zone count")?
2065+
.create_zones(!args.no_zones)
2066+
.create_disks_in_blueprint(!args.no_disks_in_blueprint);
2067+
for sled_policy in args.sled_policy {
2068+
builder = builder
2069+
.with_sled_policy(sled_policy.index, sled_policy.policy)
2070+
.context("setting sled policy")?;
2071+
}
2072+
2073+
let (example, blueprint) = builder.build();
20242074

20252075
// Generate the internal and external DNS configs based on the blueprint.
20262076
let sleds_by_id = make_sleds_by_id(&example.system)?;

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,19 @@ blueprint-diff 86db3308-f817-4626-8838-4085949a6a41
4545
blueprint-diff 02697f74-b14a-4418-90f0-c28b2a3a6aa9 86db3308-f817-4626-8838-4085949a6a41
4646
# You can specify them in the reverse order and see the opposite changes.
4747
blueprint-diff 86db3308-f817-4626-8838-4085949a6a41 02697f74-b14a-4418-90f0-c28b2a3a6aa9
48+
49+
# Load an example with a non-provisionable and an expunged sled.
50+
wipe all
51+
load-example --seed test-basic --nsleds 3 --sled-policy 1:non-provisionable --sled-policy 2:expunged --ndisks-per-sled 3
52+
53+
blueprint-list
54+
blueprint-show latest
55+
56+
# Plan a blueprint run -- this will cause zones and disks on the expunged
57+
# sled to be expunged.
58+
blueprint-plan latest
59+
blueprint-diff ade5749d-bdf3-4fab-a8ae-00bea01b3a5a latest
60+
61+
# Sled index out of bounds, will error out.
62+
wipe all
63+
load-example --seed test-basic --nsleds 3 --sled-policy 3:non-provisionable

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ sled-add dde1c0e2-b10d-4621-b420-f179f7a7a00a
1010
sled-list
1111
sled-show dde1c0e2-b10d-4621-b420-f179f7a7a00a
1212
sled-add 90c1102a-b9f5-4d88-92a2-60d54a2d98cc
13-
sled-add 04ef3330-c682-4a08-8def-fcc4bef31bcd
13+
sled-add 04ef3330-c682-4a08-8def-fcc4bef31bcd --policy non-provisionable
1414
sled-list
1515

1616
sled-update-sp dde1c0e2-b10d-4621-b420-f179f7a7a00a

0 commit comments

Comments
 (0)