Skip to content

[23/n] [reconfigurator-cli] allow setting sled policy in more situations#8491

Merged
sunshowers merged 3 commits into
mainfrom
sunshowers/spr/23n-reconfigurator-cli-allow-setting-sled-policy-in-more-situations
Jul 1, 2025
Merged

[23/n] [reconfigurator-cli] allow setting sled policy in more situations#8491
sunshowers merged 3 commits into
mainfrom
sunshowers/spr/23n-reconfigurator-cli-allow-setting-sled-policy-in-more-situations

Conversation

@sunshowers

Copy link
Copy Markdown
Contributor

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.

Depends on:

Created using spr 1.3.6-beta.1

[skip ci]
Created using spr 1.3.6-beta.1
Comment on lines +236 to +244
// Add more sleds if there's a shortfall.
if nsleds > self.sled_settings.len() {
self.sled_settings.extend(vec![
BuilderSledSettings::default();
nsleds - self.sled_settings.len()
]);
} else if nsleds < self.sled_settings.len() {
self.sled_settings.truncate(nsleds);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think all of this could instead be

self.sled_settings.resize_with(nsleds, BuilderSledSettings::default);

or maybe resize() instead of resize_with if BuilderSledSettings is cloneable.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh neat! somehow never knew about resize, TIL!

index: usize,
policy: SledPolicy,
) -> anyhow::Result<Self> {
if index >= self.sled_settings.len() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two comments, both pretty minor:

  • Could maybe use sled_settings.get_mut(index) to avoid the manual length check?
  • Is it useful for this method to return an error (as opposed to panicking directly)? It consumes self, so the caller presumably can't do anything useful with the system they're trying to build if they get this wrong. Scratch this one; saw how this is used elsewhere.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

Comment on lines +873 to +874
// _message is just something like "invalid variant: <value>".
// We choose to use our own message instead.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we change the error message on SledPolicyOpt itself so all its users get this nicer message?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah unfortunately SledPolicyOpt is generated by the ValueEnum proc macro. The error with clap is reasonable:

image

With load-example --sled-policy we get a different error message, but one that still conveys the same information:

image

Comment thread dev-tools/reconfigurator-cli/src/lib.rs Outdated

fn from_str(s: &str) -> Result<Self, Self::Err> {
let Some((index, policy)) = s.split_once(':') else {
return Err(anyhow!("invalid format, expected <index>:<policy>"));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tiny nit - could shorten this to

Suggested change
return Err(anyhow!("invalid format, expected <index>:<policy>"));
bail!("invalid format, expected <index>:<policy>");

or use s.split_once(':').context("...")?; to match the index parsing.

@sunshowers sunshowers changed the base branch from sunshowers/spr/main.23n-reconfigurator-cli-allow-setting-sled-policy-in-more-situations to main July 1, 2025 19:37
Created using spr 1.3.6-beta.1
@sunshowers sunshowers enabled auto-merge (squash) July 1, 2025 19:42
@sunshowers sunshowers merged commit fd2d5f4 into main Jul 1, 2025
16 checks passed
@sunshowers sunshowers deleted the sunshowers/spr/23n-reconfigurator-cli-allow-setting-sled-policy-in-more-situations branch July 1, 2025 21:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants