Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions crates/api-test-helper/src/mock_rms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,11 @@ pub struct MockRmsApi {
enable_scale_up_fabric_telemetry_interface_calls:
Mutex<Vec<rms::EnableScaleUpFabricTelemetryInterfaceRequest>>,

// Switch password calls.
update_switch_system_password_responses:
Mutex<VecDeque<Result<rms::UpdateSwitchSystemPasswordResponse, RackManagerError>>>,
update_switch_system_password_calls: Mutex<Vec<rms::UpdateSwitchSystemPasswordRequest>>,

// Version (no request type).
version_responses: Mutex<VecDeque<Result<(), RackManagerError>>>,
version_call_count: Mutex<u32>,
Expand Down Expand Up @@ -255,6 +260,8 @@ impl MockRmsApi {
configure_scale_up_fabric_manager_calls: Default::default(),
enable_scale_up_fabric_telemetry_interface_responses: Default::default(),
enable_scale_up_fabric_telemetry_interface_calls: Default::default(),
update_switch_system_password_responses: Default::default(),
update_switch_system_password_calls: Default::default(),
version_responses: Default::default(),
version_call_count: Default::default(),
}
Expand Down Expand Up @@ -513,6 +520,16 @@ impl MockRmsApi {
rms::EnableScaleUpFabricTelemetryInterfaceResponse
);

// Switch password
impl_enqueue_inspect!(
enqueue_update_switch_system_password,
update_switch_system_password_calls,
update_switch_system_password_responses,
update_switch_system_password_calls,
rms::UpdateSwitchSystemPasswordRequest,
rms::UpdateSwitchSystemPasswordResponse
);

// Version (special — no request type)
pub async fn enqueue_version(&self, resp: Result<(), RackManagerError>) {
self.version_responses.lock().await.push_back(resp);
Expand Down Expand Up @@ -675,9 +692,13 @@ impl RmsApi for MockRmsApi {
}
async fn update_switch_system_password(
&self,
_cmd: rms::UpdateSwitchSystemPasswordRequest,
cmd: rms::UpdateSwitchSystemPasswordRequest,
) -> Result<rms::UpdateSwitchSystemPasswordResponse, RackManagerError> {
Ok(rms::UpdateSwitchSystemPasswordResponse::default())
self.update_switch_system_password_calls
.lock()
.await
.push(cmd);
pop_or_err(&mut self.update_switch_system_password_responses.lock().await)
}
async fn get_power_state(
&self,
Expand Down
57 changes: 55 additions & 2 deletions crates/api/src/rack/rms_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ pub mod test_support {
Arc<Mutex<Vec<rms::SetPowerStateByDeviceListRequest>>>,
queued_set_power_state_by_device_list_responses:
Arc<Mutex<VecDeque<Result<rms::SetPowerStateByDeviceListResponse, RackManagerError>>>>,
submitted_switch_system_password_requests:
Arc<Mutex<Vec<rms::UpdateSwitchSystemPasswordRequest>>>,
queued_switch_system_password_responses:
Arc<Mutex<VecDeque<Result<rms::UpdateSwitchSystemPasswordResponse, RackManagerError>>>>,
}

impl Default for RmsSim {
Expand All @@ -98,6 +102,8 @@ pub mod test_support {
queued_set_power_state_by_device_list_responses: Arc::new(Mutex::new(
VecDeque::new(),
)),
submitted_switch_system_password_requests: Arc::new(Mutex::new(Vec::new())),
queued_switch_system_password_responses: Arc::new(Mutex::new(VecDeque::new())),
}
}
}
Expand Down Expand Up @@ -137,6 +143,12 @@ pub mod test_support {
queued_set_power_state_by_device_list_responses: self
.queued_set_power_state_by_device_list_responses
.clone(),
submitted_switch_system_password_requests: self
.submitted_switch_system_password_requests
.clone(),
queued_switch_system_password_responses: self
.queued_switch_system_password_responses
.clone(),
}
}

Expand Down Expand Up @@ -242,6 +254,16 @@ pub mod test_support {
.push_back(response);
}

pub async fn queue_update_switch_system_password_response(

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.

any idea why its queue_ ?

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.

switch_system_password_responses looks good !

&self,
response: Result<rms::UpdateSwitchSystemPasswordResponse, RackManagerError>,
) {
self.queued_switch_system_password_responses
.lock()
.await
.push_back(response);
}

/// Snapshot the recorded `SetPowerStateByDeviceList` requests, in
/// the order they were received.
pub async fn submitted_set_power_state_by_device_list_requests(
Expand All @@ -252,6 +274,15 @@ pub mod test_support {
.await
.clone()
}

pub async fn submitted_switch_system_password_requests(
&self,
) -> Vec<rms::UpdateSwitchSystemPasswordRequest> {
self.submitted_switch_system_password_requests
.lock()
.await
.clone()
}
}

#[derive(Debug, Clone)]
Expand All @@ -274,6 +305,10 @@ pub mod test_support {
Arc<Mutex<Vec<rms::SetPowerStateByDeviceListRequest>>>,
queued_set_power_state_by_device_list_responses:
Arc<Mutex<VecDeque<Result<rms::SetPowerStateByDeviceListResponse, RackManagerError>>>>,
submitted_switch_system_password_requests:
Arc<Mutex<Vec<rms::UpdateSwitchSystemPasswordRequest>>>,
queued_switch_system_password_responses:
Arc<Mutex<VecDeque<Result<rms::UpdateSwitchSystemPasswordResponse, RackManagerError>>>>,
}

#[async_trait::async_trait]
Expand Down Expand Up @@ -310,9 +345,17 @@ pub mod test_support {
}
async fn update_switch_system_password(
&self,
_cmd: rms::UpdateSwitchSystemPasswordRequest,
cmd: rms::UpdateSwitchSystemPasswordRequest,
) -> Result<rms::UpdateSwitchSystemPasswordResponse, RackManagerError> {
Ok(rms::UpdateSwitchSystemPasswordResponse::default())
self.submitted_switch_system_password_requests
.lock()
.await
.push(cmd);
self.queued_switch_system_password_responses
.lock()
.await
.pop_front()
.unwrap_or_else(|| Ok(successful_switch_system_password_response()))
}
async fn set_power_state(
&self,
Expand Down Expand Up @@ -572,4 +615,14 @@ pub mod test_support {
}))
}
}

fn successful_switch_system_password_response() -> rms::UpdateSwitchSystemPasswordResponse {
rms::UpdateSwitchSystemPasswordResponse {
response: Some(rms::NodeBatchResponse {
status: rms::ReturnCode::Success as i32,
message: "Updated switch system password on 0 of 0 devices".to_string(),
..Default::default()
}),
}
}
}
Loading
Loading