Skip to content

Commit 2effb2a

Browse files
authored
refactor(bmc-mock): avoid cloning machine info for BMC mock setup (#2779)
Change BMC mock router construction to borrow `MachineInfo` and store only the derived SSH prompt behavior in `BmcMockWrapper`. ## Related issues This is preliminary refactor before #2617 ## Type of Change - [ ] **Add** - New feature or capability - [ ] **Change** - Changes in existing functionality - [ ] **Fix** - Bug fixes - [ ] **Remove** - Removed features or deprecated functionality - [x] **Internal** - Internal changes (refactoring, tests, docs, etc.) ## Breaking Changes <!-- If checked, describe the breaking changes and migration steps --> <!-- Breaking changes are not generally permitted, please discuss on a GitHub discussion or with the development team if you believe you need to break a backward compatibility guarantee --> - [ ] **This PR contains breaking changes** ## Testing - [ ] Unit tests added/updated - [ ] Integration tests added/updated - [ ] Manual testing performed - [x] No testing required (docs, internal refactor, etc.) ## Additional Notes Signed-off-by: Dmitry Porokh <dporokh@nvidia.com>
1 parent 86dd05c commit 2effb2a

7 files changed

Lines changed: 26 additions & 29 deletions

File tree

crates/bmc-mock/src/machine_info.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,27 +37,24 @@ pub enum MachineInfo {
3737
Dpu(DpuMachineInfo),
3838
}
3939

40-
#[derive(Debug, Clone, Serialize, Deserialize)]
40+
#[derive(Debug, Clone)]
4141
pub struct HostMachineInfo {
4242
pub hw_type: HostHardwareType,
4343
pub bmc_mac_address: MacAddress,
4444
pub serial: String,
4545
pub dpus: Vec<DpuMachineInfo>,
4646
pub non_dpu_mac_address: Option<MacAddress>,
47-
#[serde(default)]
4847
pub nvos_mac_addresses: Vec<MacAddress>,
49-
#[serde(default)]
5048
pub switch_serial_number: Option<String>,
5149
}
5250

53-
#[derive(Debug, Clone, Serialize, Deserialize)]
51+
#[derive(Debug, Clone)]
5452
pub struct DpuMachineInfo {
5553
pub hw_type: HostHardwareType,
5654
pub bmc_mac_address: MacAddress,
5755
pub host_mac_address: MacAddress,
5856
pub oob_mac_address: MacAddress,
5957
pub serial: String,
60-
#[serde(flatten)]
6158
pub settings: DpuSettings,
6259
}
6360

crates/bmc-mock/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ fn default_host_mock() -> Router {
156156
let command_channel = spawn_qemu_reboot_handler();
157157
let callbacks = Arc::new(ChannelCallbacks::new(command_channel));
158158
bmc_mock::machine_router(
159-
MachineInfo::Host(HostMachineInfo::new(
159+
&MachineInfo::Host(HostMachineInfo::new(
160160
HostHardwareType::WiwynnGB200Nvl,
161161
vec![DpuMachineInfo::default(), DpuMachineInfo::default()],
162162
)),

crates/bmc-mock/src/mock_machine_router.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl AddRoutes for Router<BmcState> {
6262
/// Return an axum::Router that mocks various redfish calls to match
6363
/// the provided MachineInfo.
6464
pub fn machine_router(
65-
machine_info: MachineInfo,
65+
machine_info: &MachineInfo,
6666
callbacks: Arc<dyn Callbacks>,
6767
mat_host_id: String,
6868
redfish_auth: bool,
@@ -86,7 +86,7 @@ pub fn machine_router(
8686
.add_routes(crate::redfish::session_service::add_routes)
8787
.add_routes(|routes| crate::redfish::computer_system::add_routes(routes, bmc_vendor))
8888
.add_routes(crate::ipmi::add_routes);
89-
let router = match &machine_info {
89+
let router = match machine_info {
9090
MachineInfo::Dpu(_) => {
9191
router.add_routes(crate::redfish::oem::nvidia::bluefield::add_routes)
9292
}

crates/bmc-mock/src/redfish/expander_router.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ mod tests {
257257
fn test_host_mock() -> Router {
258258
let callbacks = Arc::new(TestCallbacks {});
259259
crate::machine_router(
260-
MachineInfo::Host(HostMachineInfo::new(
260+
&MachineInfo::Host(HostMachineInfo::new(
261261
HostHardwareType::DellPowerEdgeR750,
262262
vec![DpuMachineInfo::default()],
263263
)),

crates/bmc-mock/src/test_support/mod.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ async fn test_bmc((router, state): (axum::Router, BmcState)) -> TestBmcHandle {
7373

7474
pub async fn wiwynn_gb200_bmc() -> TestBmcHandle {
7575
test_bmc(machine_router(
76-
MachineInfo::Host(HostMachineInfo::new(
76+
&MachineInfo::Host(HostMachineInfo::new(
7777
HostHardwareType::WiwynnGB200Nvl,
7878
vec![
7979
DpuMachineInfo::new(HostHardwareType::WiwynnGB200Nvl, DpuSettings::default()),
@@ -89,7 +89,7 @@ pub async fn wiwynn_gb200_bmc() -> TestBmcHandle {
8989

9090
pub async fn lenovo_gb300_bmc() -> TestBmcHandle {
9191
test_bmc(machine_router(
92-
MachineInfo::Host(HostMachineInfo::new(
92+
&MachineInfo::Host(HostMachineInfo::new(
9393
HostHardwareType::LenovoGB300Nvl,
9494
vec![DpuMachineInfo::new(
9595
HostHardwareType::LenovoGB300Nvl,
@@ -105,7 +105,7 @@ pub async fn lenovo_gb300_bmc() -> TestBmcHandle {
105105

106106
pub async fn dgx_gb300_bmc() -> TestBmcHandle {
107107
test_bmc(machine_router(
108-
MachineInfo::Host(HostMachineInfo::new(
108+
&MachineInfo::Host(HostMachineInfo::new(
109109
HostHardwareType::NvidiaDgxGb300,
110110
vec![DpuMachineInfo::new(
111111
HostHardwareType::NvidiaDgxGb300,
@@ -121,7 +121,7 @@ pub async fn dgx_gb300_bmc() -> TestBmcHandle {
121121

122122
pub async fn supermicro_gb300_bmc() -> TestBmcHandle {
123123
test_bmc(machine_router(
124-
MachineInfo::Host(HostMachineInfo::new(
124+
&MachineInfo::Host(HostMachineInfo::new(
125125
HostHardwareType::SupermicroGb300Nvl,
126126
vec![DpuMachineInfo::new(
127127
HostHardwareType::SupermicroGb300Nvl,
@@ -137,7 +137,7 @@ pub async fn supermicro_gb300_bmc() -> TestBmcHandle {
137137

138138
pub async fn generic_supermicro_bmc() -> TestBmcHandle {
139139
test_bmc(machine_router(
140-
MachineInfo::Host(HostMachineInfo::new(
140+
&MachineInfo::Host(HostMachineInfo::new(
141141
HostHardwareType::GenericSupermicro,
142142
vec![],
143143
)),
@@ -150,7 +150,7 @@ pub async fn generic_supermicro_bmc() -> TestBmcHandle {
150150

151151
pub async fn liteon_powershelf_bmc() -> TestBmcHandle {
152152
test_bmc(machine_router(
153-
MachineInfo::Host(HostMachineInfo::new(
153+
&MachineInfo::Host(HostMachineInfo::new(
154154
HostHardwareType::LiteOnPowerShelf,
155155
vec![],
156156
)),
@@ -163,7 +163,7 @@ pub async fn liteon_powershelf_bmc() -> TestBmcHandle {
163163

164164
pub async fn nvidia_switch_nd5200_ld_bmc() -> TestBmcHandle {
165165
test_bmc(machine_router(
166-
MachineInfo::Host(HostMachineInfo::new(
166+
&MachineInfo::Host(HostMachineInfo::new(
167167
HostHardwareType::NvidiaSwitchNd5200Ld,
168168
vec![],
169169
)),
@@ -176,7 +176,7 @@ pub async fn nvidia_switch_nd5200_ld_bmc() -> TestBmcHandle {
176176

177177
pub async fn dell_poweredge_r750_bmc() -> TestBmcHandle {
178178
test_bmc(machine_router(
179-
MachineInfo::Host(HostMachineInfo::new(
179+
&MachineInfo::Host(HostMachineInfo::new(
180180
HostHardwareType::DellPowerEdgeR750,
181181
vec![],
182182
)),
@@ -189,7 +189,7 @@ pub async fn dell_poweredge_r750_bmc() -> TestBmcHandle {
189189

190190
pub async fn dell_poweredge_r750_bluefield3_bmc(settings: DpuSettings) -> TestBmcHandle {
191191
test_bmc(machine_router(
192-
MachineInfo::Dpu(DpuMachineInfo::new(
192+
&MachineInfo::Dpu(DpuMachineInfo::new(
193193
HostHardwareType::DellPowerEdgeR750,
194194
settings,
195195
)),
@@ -202,7 +202,7 @@ pub async fn dell_poweredge_r750_bluefield3_bmc(settings: DpuSettings) -> TestBm
202202

203203
pub async fn generic_ami_bmc() -> TestBmcHandle {
204204
test_bmc(machine_router(
205-
MachineInfo::Host(HostMachineInfo::new(HostHardwareType::GenericAmi, vec![])),
205+
&MachineInfo::Host(HostMachineInfo::new(HostHardwareType::GenericAmi, vec![])),
206206
Arc::new(NoopCallbacks),
207207
"test-host-id".to_string(),
208208
false,
@@ -224,7 +224,7 @@ mod test {
224224
async fn transport_supports_expand_query_through_mock_expander() {
225225
let client = AxumRouterHttpClient::new(
226226
machine_router(
227-
MachineInfo::Host(HostMachineInfo::new(
227+
&MachineInfo::Host(HostMachineInfo::new(
228228
HostHardwareType::DellPowerEdgeR750,
229229
vec![],
230230
)),

crates/machine-a-tron/src/bmc_mock_wrapper.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use crate::mock_ssh_server::{MockSshServerHandle, PromptBehavior};
3636
/// either a DPU or a Host. It will rewrite certain responses to customize them for the machines
3737
/// machine-a-tron is mocking.
3838
pub struct BmcMockWrapper {
39-
machine_info: MachineInfo,
39+
ssh_prompt_behavior: PromptBehavior,
4040
app_context: Arc<MachineATronContext>,
4141
bmc_mock_router: Router,
4242
bmc_mock_state: BmcState,
@@ -45,17 +45,20 @@ pub struct BmcMockWrapper {
4545

4646
impl BmcMockWrapper {
4747
pub fn new(
48-
machine_info: MachineInfo,
48+
machine_info: &MachineInfo,
4949
app_context: Arc<MachineATronContext>,
5050
callbacks: Arc<dyn Callbacks>,
5151
hostname: Arc<dyn HostnameQuerying>,
5252
host_id: Uuid,
5353
) -> Self {
5454
let (bmc_mock_router, bmc_mock_state) =
55-
bmc_mock::machine_router(machine_info.clone(), callbacks, host_id.to_string(), true);
55+
bmc_mock::machine_router(machine_info, callbacks, host_id.to_string(), true);
5656

5757
BmcMockWrapper {
58-
machine_info,
58+
ssh_prompt_behavior: match machine_info {
59+
MachineInfo::Host(_) => PromptBehavior::Dell,
60+
MachineInfo::Dpu(_) => PromptBehavior::Dpu,
61+
},
5962
app_context,
6063
bmc_mock_router,
6164
bmc_mock_state,
@@ -120,10 +123,7 @@ impl BmcMockWrapper {
120123
user: "root".to_string(),
121124
password: "password".to_string(),
122125
}),
123-
match self.machine_info {
124-
MachineInfo::Host(_) => PromptBehavior::Dell,
125-
MachineInfo::Dpu(_) => PromptBehavior::Dpu,
126-
},
126+
self.ssh_prompt_behavior,
127127
)
128128
.await
129129
.map_err(|error| {

crates/machine-a-tron/src/machine_state_machine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,7 @@ impl MachineStateMachine {
933933
ip_address: Ipv4Addr,
934934
) -> Result<(Option<Arc<BmcMockWrapperHandle>>, BmcState), MachineStateError> {
935935
let mut bmc_mock = BmcMockWrapper::new(
936-
self.machine_info.clone(),
936+
&self.machine_info,
937937
self.app_context.clone(),
938938
Arc::new(LiveStateCallbacks::new(
939939
self.live_state.clone(),

0 commit comments

Comments
 (0)