Skip to content

Commit

Permalink
faux-mgs: Move majority of implementation into gateway-sp-comms (#1579
Browse files Browse the repository at this point in the history
)
  • Loading branch information
jgallagher authored Aug 17, 2022
1 parent 1c55cc9 commit 419b1d1
Show file tree
Hide file tree
Showing 10 changed files with 1,086 additions and 589 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

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

70 changes: 53 additions & 17 deletions gateway-sp-comms/src/communicator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ impl Communicator {
self.request_response(
&controller,
request,
ResponseKindExt::try_into_ignition_state,
ResponseKindExt::expect_ignition_state,
Some(timeout),
)
.await
Expand All @@ -153,7 +153,7 @@ impl Communicator {
.request_response(
&controller,
request,
ResponseKindExt::try_into_bulk_ignition_state,
ResponseKindExt::expect_bulk_ignition_state,
Some(timeout),
)
.await?;
Expand Down Expand Up @@ -197,7 +197,7 @@ impl Communicator {
self.request_response(
&controller,
request,
ResponseKindExt::try_into_ignition_command_ack,
ResponseKindExt::expect_ignition_command_ack,
Some(timeout),
)
.await
Expand Down Expand Up @@ -328,7 +328,7 @@ impl Communicator {
self.request_response(
&sp,
RequestKind::SerialConsoleWrite(packet),
ResponseKindExt::try_into_serial_console_write_ack,
ResponseKindExt::expect_serial_console_write_ack,
Some(timeout),
)
.await
Expand Down Expand Up @@ -370,7 +370,7 @@ impl Communicator {
self.request_response(
&sp,
request,
ResponseKindExt::try_into_sp_state,
ResponseKindExt::expect_sp_state,
timeout,
)
.await
Expand Down Expand Up @@ -439,19 +439,25 @@ impl Communicator {
pub(crate) trait ResponseKindExt {
fn name(&self) -> &'static str;

fn try_into_discover(self) -> Result<DiscoverResponse, BadResponseType>;
fn expect_discover(self) -> Result<DiscoverResponse, BadResponseType>;

fn try_into_ignition_state(self) -> Result<IgnitionState, BadResponseType>;
fn expect_ignition_state(self) -> Result<IgnitionState, BadResponseType>;

fn try_into_bulk_ignition_state(
fn expect_bulk_ignition_state(
self,
) -> Result<BulkIgnitionState, BadResponseType>;

fn try_into_ignition_command_ack(self) -> Result<(), BadResponseType>;
fn expect_ignition_command_ack(self) -> Result<(), BadResponseType>;

fn try_into_sp_state(self) -> Result<SpState, BadResponseType>;
fn expect_sp_state(self) -> Result<SpState, BadResponseType>;

fn try_into_serial_console_write_ack(self) -> Result<(), BadResponseType>;
fn expect_serial_console_write_ack(self) -> Result<(), BadResponseType>;

fn expect_update_start_ack(self) -> Result<(), BadResponseType>;

fn expect_update_chunk_ack(self) -> Result<(), BadResponseType>;

fn expect_sys_reset_prepare_ack(self) -> Result<(), BadResponseType>;
}

impl ResponseKindExt for ResponseKind {
Expand Down Expand Up @@ -483,7 +489,7 @@ impl ResponseKindExt for ResponseKind {
}
}

fn try_into_discover(self) -> Result<DiscoverResponse, BadResponseType> {
fn expect_discover(self) -> Result<DiscoverResponse, BadResponseType> {
match self {
ResponseKind::Discover(discover) => Ok(discover),
other => Err(BadResponseType {
Expand All @@ -493,7 +499,7 @@ impl ResponseKindExt for ResponseKind {
}
}

fn try_into_ignition_state(self) -> Result<IgnitionState, BadResponseType> {
fn expect_ignition_state(self) -> Result<IgnitionState, BadResponseType> {
match self {
ResponseKind::IgnitionState(state) => Ok(state),
other => Err(BadResponseType {
Expand All @@ -503,7 +509,7 @@ impl ResponseKindExt for ResponseKind {
}
}

fn try_into_bulk_ignition_state(
fn expect_bulk_ignition_state(
self,
) -> Result<BulkIgnitionState, BadResponseType> {
match self {
Expand All @@ -515,7 +521,7 @@ impl ResponseKindExt for ResponseKind {
}
}

fn try_into_ignition_command_ack(self) -> Result<(), BadResponseType> {
fn expect_ignition_command_ack(self) -> Result<(), BadResponseType> {
match self {
ResponseKind::IgnitionCommandAck => Ok(()),
other => Err(BadResponseType {
Expand All @@ -525,7 +531,7 @@ impl ResponseKindExt for ResponseKind {
}
}

fn try_into_sp_state(self) -> Result<SpState, BadResponseType> {
fn expect_sp_state(self) -> Result<SpState, BadResponseType> {
match self {
ResponseKind::SpState(state) => Ok(state),
other => Err(BadResponseType {
Expand All @@ -535,7 +541,7 @@ impl ResponseKindExt for ResponseKind {
}
}

fn try_into_serial_console_write_ack(self) -> Result<(), BadResponseType> {
fn expect_serial_console_write_ack(self) -> Result<(), BadResponseType> {
match self {
ResponseKind::SerialConsoleWriteAck => Ok(()),
other => Err(BadResponseType {
Expand All @@ -544,6 +550,36 @@ impl ResponseKindExt for ResponseKind {
}),
}
}

fn expect_update_start_ack(self) -> Result<(), BadResponseType> {
match self {
ResponseKind::UpdateStartAck => Ok(()),
other => Err(BadResponseType {
expected: response_kind_names::UPDATE_START_ACK,
got: other.name(),
}),
}
}

fn expect_update_chunk_ack(self) -> Result<(), BadResponseType> {
match self {
ResponseKind::UpdateChunkAck => Ok(()),
other => Err(BadResponseType {
expected: response_kind_names::UPDATE_CHUNK_ACK,
got: other.name(),
}),
}
}

fn expect_sys_reset_prepare_ack(self) -> Result<(), BadResponseType> {
match self {
ResponseKind::SysResetPrepareAck => Ok(()),
other => Err(BadResponseType {
expected: response_kind_names::SYS_RESET_PREPARE_ACK,
got: other.name(),
}),
}
}
}

mod response_kind_names {
Expand Down
1 change: 1 addition & 0 deletions gateway-sp-comms/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
mod communicator;
mod management_switch;
mod recv_handler;
pub mod single_sp;
mod timeout;

pub use usdt::register_probes;
Expand Down
2 changes: 1 addition & 1 deletion gateway-sp-comms/src/management_switch/location_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ async fn discover_sps(
.request_response(
&recv_handler,
RequestKind::Discover,
ResponseKindExt::try_into_discover,
ResponseKindExt::expect_discover,
// TODO should this timeout be configurable or itself
// have some kind of backoff? we're inside a
// `backoff::retry()` loop, but if an SP is alive but
Expand Down
Loading

0 comments on commit 419b1d1

Please sign in to comment.