Skip to content

Commit

Permalink
[π˜€π—½π—Ώ] initial version
Browse files Browse the repository at this point in the history
Created using spr 1.3.4
  • Loading branch information
sunshowers committed Sep 28, 2023
2 parents 8602e46 + 8cdae88 commit 716e79d
Show file tree
Hide file tree
Showing 10 changed files with 623 additions and 315 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

97 changes: 52 additions & 45 deletions openapi/wicketd.json
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,33 @@
}
}
},
"/update": {
"post": {
"summary": "An endpoint to start updating one or more sleds, switches and PSCs.",
"operationId": "post_start_update",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/StartUpdateParams"
}
}
},
"required": true
},
"responses": {
"204": {
"description": "resource updated"
},
"4XX": {
"$ref": "#/components/responses/Error"
},
"5XX": {
"$ref": "#/components/responses/Error"
}
}
}
},
"/update/{type}/{slot}": {
"get": {
"summary": "An endpoint to get the status of any update being performed or recently",
Expand Down Expand Up @@ -641,51 +668,6 @@
"$ref": "#/components/responses/Error"
}
}
},
"post": {
"summary": "An endpoint to start updating a sled.",
"operationId": "post_start_update",
"parameters": [
{
"in": "path",
"name": "slot",
"required": true,
"schema": {
"type": "integer",
"format": "uint32",
"minimum": 0
}
},
{
"in": "path",
"name": "type",
"required": true,
"schema": {
"$ref": "#/components/schemas/SpType"
}
}
],
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/StartUpdateOptions"
}
}
},
"required": true
},
"responses": {
"204": {
"description": "resource updated"
},
"4XX": {
"$ref": "#/components/responses/Error"
},
"5XX": {
"$ref": "#/components/responses/Error"
}
}
}
}
},
Expand Down Expand Up @@ -2761,6 +2743,31 @@
"skip_sp_version_check"
]
},
"StartUpdateParams": {
"type": "object",
"properties": {
"options": {
"description": "Options for the update.",
"allOf": [
{
"$ref": "#/components/schemas/StartUpdateOptions"
}
]
},
"targets": {
"description": "The SP identifiers to start the update with. Must be non-empty.",
"type": "array",
"items": {
"$ref": "#/components/schemas/SpIdentifier"
},
"uniqueItems": true
}
},
"required": [
"options",
"targets"
]
},
"StepComponentSummaryForGenericSpec": {
"type": "object",
"properties": {
Expand Down
43 changes: 30 additions & 13 deletions update-engine/src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1389,18 +1389,23 @@ mod tests {
test_cx
.run_filtered_test(
"all events passed in",
|buffer, event| buffer.add_event(event.clone()),
|buffer, event| {
buffer.add_event(event.clone());
true
},
WithDeltas::No,
)
.unwrap();

test_cx
.run_filtered_test(
"progress events skipped",
|buffer, event| {
if let Event::Step(event) = event {
|buffer, event| match event {
Event::Step(event) => {
buffer.add_step_event(event.clone());
true
}
Event::Progress(_) => false,
},
WithDeltas::Both,
)
Expand All @@ -1410,13 +1415,16 @@ mod tests {
.run_filtered_test(
"low-priority events skipped",
|buffer, event| match event {
Event::Step(event) => {
if event.kind.priority() == StepEventPriority::Low {
Event::Step(event) => match event.kind.priority() {
StepEventPriority::High => {
buffer.add_step_event(event.clone());
true
}
}
StepEventPriority::Low => false,
},
Event::Progress(event) => {
buffer.add_progress_event(event.clone());
true
}
},
WithDeltas::Both,
Expand All @@ -1427,13 +1435,16 @@ mod tests {
.run_filtered_test(
"low-priority and progress events skipped",
|buffer, event| match event {
Event::Step(event) => {
if event.kind.priority() == StepEventPriority::Low {
Event::Step(event) => match event.kind.priority() {
StepEventPriority::High => {
buffer.add_step_event(event.clone());
true
}
}
StepEventPriority::Low => false,
},
Event::Progress(_) => {
// Don't add progress events either.
// Don't add progress events.
false
}
},
WithDeltas::Both,
Expand Down Expand Up @@ -1565,7 +1576,10 @@ mod tests {
fn run_filtered_test(
&self,
event_fn_description: &str,
mut event_fn: impl FnMut(&mut EventBuffer<TestSpec>, &Event<TestSpec>),
mut event_fn: impl FnMut(
&mut EventBuffer<TestSpec>,
&Event<TestSpec>,
) -> bool,
with_deltas: WithDeltas,
) -> anyhow::Result<()> {
match with_deltas {
Expand All @@ -1590,7 +1604,10 @@ mod tests {

fn run_filtered_test_inner(
&self,
mut event_fn: impl FnMut(&mut EventBuffer<TestSpec>, &Event<TestSpec>),
mut event_fn: impl FnMut(
&mut EventBuffer<TestSpec>,
&Event<TestSpec>,
) -> bool,
with_deltas: bool,
) -> anyhow::Result<()> {
let description = format!("with deltas = {with_deltas}");
Expand All @@ -1609,7 +1626,7 @@ mod tests {

for (i, event) in self.generated_events.iter().enumerate() {
(event_fn)(&mut buffer, event);
buffer.add_event(event.clone());

let report = match last_seen_opt {
Some(last_seen) => buffer.generate_report_since(last_seen),
None => buffer.generate_report(),
Expand Down
11 changes: 6 additions & 5 deletions wicket/src/wicketd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use tokio::time::{interval, Duration, MissedTickBehavior};
use wicketd_client::types::{
AbortUpdateOptions, ClearUpdateStateOptions, GetInventoryParams,
GetInventoryResponse, GetLocationResponse, IgnitionCommand, SpIdentifier,
SpType, StartUpdateOptions,
SpType, StartUpdateOptions, StartUpdateParams,
};

use crate::events::EventReportMap;
Expand Down Expand Up @@ -164,10 +164,11 @@ impl WicketdManager {
tokio::spawn(async move {
let update_client =
create_wicketd_client(&log, addr, WICKETD_TIMEOUT);
let sp: SpIdentifier = component_id.into();
let response = match update_client
.post_start_update(sp.type_, sp.slot, &options)
.await
let params = StartUpdateParams {
targets: vec![component_id.into()],
options,
};
let response = match update_client.post_start_update(&params).await
{
Ok(_) => Ok(()),
Err(error) => Err(error.to_string()),
Expand Down
1 change: 1 addition & 0 deletions wicketd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ hubtools.workspace = true
http.workspace = true
hyper.workspace = true
illumos-utils.workspace = true
itertools.workspace = true
reqwest.workspace = true
schemars.workspace = true
serde.workspace = true
Expand Down
41 changes: 41 additions & 0 deletions wicketd/src/helpers.rs
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(", ")
}
Loading

0 comments on commit 716e79d

Please sign in to comment.