-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[wicketd] allow starting multiple updates with one API call (#4039)
Extend `post_start_update` to allow starting updates on several sleds at once. This is not currently used (the TUI always updates one sled at a time), but will be used for command-line driven mupdates. If we're issuing updates on several sleds at once, we can encounter different kinds of errors for each sled. So instead of returning immediately, we collect errors into a vector and then return them all at once. This also required some refactoring in `update_tracker.rs`. To take care of all possible situations: 1. Add a new `SpawnUpdateDriver` trait, which has two methods: one to perform a one-time setup, and one to perform a spawn operation for each SP. 2. Add three implementations of `SpawnUpdateDriver`: `RealUpdateDriver` which is the actual implementation, `FakeUpdateDriver` which is used for tests, and `NeverUpdateDriver` which is an uninhabited type (empty enum, can never be constructed) and is used to perform pre-update checks but not the update itself. Happy to hear suggestions about how to make this better. One path I went down but rejected is using a typestate to indicate that update checks had passed -- then the caller could decide whether to perform the update or not. The problem is that for the typestate to be valid it would have to hold on to the `MutexGuard` (otherwise something could come in between and replace the task that we thought was finished), and that seems a bit fraught as you could accidentally attempt to lock the update data again. A callback-like approach, which was the previous implementation and which has been retained in this PR, does not have that pitfall. I tested this by spinning up sp-sim, mgs, and wicketd, and it worked as expected. Errors (e.g. no inventory present) were caught as expected.
- Loading branch information
1 parent
8fb68a2
commit b03dd6b
Showing
9 changed files
with
595 additions
and
302 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
//! Helpers and utility functions for wicketd. | ||
use std::fmt; | ||
|
||
use gateway_client::types::{SpIdentifier, SpType}; | ||
use itertools::Itertools; | ||
|
||
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Hash)] | ||
pub(crate) struct SpIdentifierDisplay(pub(crate) SpIdentifier); | ||
|
||
impl From<SpIdentifier> for SpIdentifierDisplay { | ||
fn from(id: SpIdentifier) -> Self { | ||
SpIdentifierDisplay(id) | ||
} | ||
} | ||
|
||
impl<'a> From<&'a SpIdentifier> for SpIdentifierDisplay { | ||
fn from(id: &'a SpIdentifier) -> Self { | ||
SpIdentifierDisplay(*id) | ||
} | ||
} | ||
|
||
impl fmt::Display for SpIdentifierDisplay { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
match self.0.type_ { | ||
SpType::Sled => write!(f, "sled {}", self.0.slot), | ||
SpType::Switch => write!(f, "switch {}", self.0.slot), | ||
SpType::Power => write!(f, "PSC {}", self.0.slot), | ||
} | ||
} | ||
} | ||
|
||
pub(crate) fn sps_to_string<S: Into<SpIdentifierDisplay>>( | ||
sps: impl IntoIterator<Item = S>, | ||
) -> String { | ||
sps.into_iter().map_into().join(", ") | ||
} |
Oops, something went wrong.