[23/n] [reconfigurator-cli] allow setting sled policy in more situations#8491
Merged
sunshowers merged 3 commits intoJul 1, 2025
Conversation
Created using spr 1.3.6-beta.1 [skip ci]
Created using spr 1.3.6-beta.1
1 task
jgallagher
approved these changes
Jul 1, 2025
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); | ||
| } |
Contributor
There was a problem hiding this comment.
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.
Contributor
Author
There was a problem hiding this comment.
oh neat! somehow never knew about resize, TIL!
| index: usize, | ||
| policy: SledPolicy, | ||
| ) -> anyhow::Result<Self> { | ||
| if index >= self.sled_settings.len() { |
Contributor
There was a problem hiding this comment.
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.
Comment on lines
+873
to
+874
| // _message is just something like "invalid variant: <value>". | ||
| // We choose to use our own message instead. |
Contributor
There was a problem hiding this comment.
Can we change the error message on SledPolicyOpt itself so all its users get this nicer message?
Contributor
Author
|
|
||
| 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>")); |
Contributor
There was a problem hiding this comment.
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.
Created using spr 1.3.6-beta.1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


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: