Skip to content

Commit 762ad0d

Browse files
committed
test(machine-controller): move machine setup test from api-core
Move the OEM manager profile forwarding regression test into the machine controller crate and add local test defaults needed to run it there. Signed-off-by: Dmitry Porokh <dporokh@nvidia.com>
1 parent 3e99dd2 commit 762ad0d

8 files changed

Lines changed: 57 additions & 31 deletions

File tree

crates/api-core/src/test_support/default_config.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -125,19 +125,7 @@ pub fn get() -> CarbideConfig {
125125
)]
126126
.into_iter()
127127
.collect(),
128-
machine_state_controller: MachineStateControllerConfig {
129-
dpu_wait_time: Duration::seconds(1),
130-
power_down_wait: Duration::seconds(1),
131-
failure_retry_time: Duration::seconds(1),
132-
dpu_up_threshold: Duration::weeks(52),
133-
controller: StateControllerConfig::default(),
134-
scout_reporting_timeout: Duration::weeks(52),
135-
uefi_boot_wait: Duration::seconds(0),
136-
max_bios_config_retries: MachineStateControllerConfig::max_bios_config_retries_default(
137-
),
138-
polling_bios_setup_stuck_threshold:
139-
MachineStateControllerConfig::polling_bios_setup_stuck_threshold_default(),
140-
},
128+
machine_state_controller: MachineStateControllerConfig::test_default(),
141129
network_segment_state_controller: NetworkSegmentStateControllerConfig {
142130
network_segment_drain_time: Duration::seconds(2),
143131
controller: StateControllerConfig::default(),

crates/api-core/src/tests/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ mod machine_interfaces;
7575
mod machine_metadata;
7676
mod machine_network;
7777
mod machine_power;
78-
mod machine_setup;
7978
mod machine_states;
8079
mod machine_topology;
8180
pub mod machine_update_manager;

crates/machine-controller/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ uuid = { workspace = true, features = ["v4", "serde"] }
6666
version-compare = { workspace = true }
6767

6868
[dev-dependencies]
69+
carbide-redfish = { path = "../redfish", features = ["test-support"] }
70+
6971
figment = { workspace = true, features = ["env", "test", "toml"] }
7072
regex = { workspace = true }
7173
lazy_static = { workspace = true }

crates/machine-controller/src/config/controller.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,23 @@ pub struct MachineStateControllerConfig {
8484
}
8585

8686
impl MachineStateControllerConfig {
87+
#[cfg(any(test, feature = "test-support"))]
88+
pub fn test_default() -> Self {
89+
Self {
90+
dpu_wait_time: Duration::seconds(1),
91+
power_down_wait: Duration::seconds(1),
92+
failure_retry_time: Duration::seconds(1),
93+
dpu_up_threshold: Duration::weeks(52),
94+
controller: StateControllerConfig::default(),
95+
scout_reporting_timeout: Duration::weeks(52),
96+
uefi_boot_wait: Duration::seconds(0),
97+
max_bios_config_retries: MachineStateControllerConfig::max_bios_config_retries_default(
98+
),
99+
polling_bios_setup_stuck_threshold:
100+
MachineStateControllerConfig::polling_bios_setup_stuck_threshold_default(),
101+
}
102+
}
103+
87104
pub fn dpu_wait_time_default() -> Duration {
88105
Duration::minutes(5)
89106
}

crates/machine-controller/src/config/firmware_global.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ pub struct FirmwareGlobal {
9797
}
9898

9999
impl FirmwareGlobal {
100-
#[cfg(feature = "test-support")]
100+
#[cfg(any(test, feature = "test-support"))]
101101
pub fn test_default() -> Self {
102102
FirmwareGlobal {
103103
autoupdate: true,
@@ -116,7 +116,7 @@ impl FirmwareGlobal {
116116
}
117117
}
118118

119-
#[cfg(feature = "test-support")]
119+
#[cfg(any(test, feature = "test-support"))]
120120
pub fn get_retry_interval() -> Duration {
121121
Duration::seconds(1)
122122
}

crates/machine-controller/src/config/mod.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
* limitations under the License.
1616
*/
1717

18+
#[cfg(any(test, feature = "test-support"))]
19+
use std::collections::HashMap;
20+
1821
use model::machine::HostHealthConfig;
1922
use serde::{Deserialize, Serialize};
2023

@@ -46,6 +49,24 @@ pub struct MachineStateHandlerSiteConfig {
4649
pub dpu_enable_secure_boot: bool,
4750
}
4851

52+
impl MachineStateHandlerSiteConfig {
53+
#[cfg(any(test, feature = "test-support"))]
54+
pub fn test_default() -> Self {
55+
Self {
56+
firmware_global: FirmwareGlobal::test_default(),
57+
machine_state_controller: MachineStateControllerConfig::test_default(),
58+
host_health: HostHealthConfig::default(),
59+
selected_profile: libredfish::BiosProfileType::Performance,
60+
bios_profiles: HashMap::new(),
61+
oem_manager_profiles: HashMap::new(),
62+
dpa_enabled: true,
63+
dpf_enabled: false,
64+
spdm_enabled: false,
65+
dpu_enable_secure_boot: true,
66+
}
67+
}
68+
}
69+
4970
/// A UTC time window defined by a start and end timestamp.
5071
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
5172
pub struct TimePeriod {

crates/machine-controller/src/handler.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ mod helpers;
119119
mod machine_validation;
120120
mod power;
121121
mod sku;
122+
#[cfg(test)]
123+
mod test_machine_setup;
124+
122125
use bios_config::{
123126
BiosConfigJobAdvanceOutcome, BiosConfigOutcome, PollingBiosSetupOutcome,
124127
advance_bios_config_job, advance_polling_bios_setup, configure_host_bios,

crates/api-core/src/tests/machine_setup.rs renamed to crates/machine-controller/src/handler/test_machine_setup.rs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,21 @@
1717

1818
use std::collections::HashMap;
1919

20+
use carbide_redfish::libredfish::test_support::{RedfishSim, RedfishSimAction};
21+
use carbide_redfish::libredfish::{RedfishAuth, RedfishClientPool};
22+
use carbide_secrets::credentials::{CredentialKey, CredentialType};
23+
use libredfish::BiosProfileType;
24+
use libredfish::model::service_root::RedfishVendor;
25+
26+
use super::{MachineStateHandlerSiteConfig, call_machine_setup_and_handle_no_dpu_error};
27+
2028
/// Verify that `oem_manager_profiles` from the site config is forwarded to `machine_setup`.
2129
///
2230
/// This test catches regressions where the argument gets dropped or replaced with an empty map.
2331
#[tokio::test]
2432
async fn test_oem_manager_profiles_passed_to_machine_setup() {
25-
use carbide_redfish::libredfish::RedfishClientPool;
26-
use carbide_redfish::libredfish::test_support::{RedfishSim, RedfishSimAction};
27-
use libredfish::BiosProfileType;
28-
use libredfish::model::service_root::RedfishVendor;
33+
let mut config = MachineStateHandlerSiteConfig::test_default();
2934

30-
let mut config = crate::tests::common::api_fixtures::get_config();
3135
// Build an oem_manager_profiles map with a Dell R760 PSU Hot Spare setting.
3236
// This mirrors the fix for the Dell R760 PSU fan issue (nvbugs-5834644).
3337
config.oem_manager_profiles = HashMap::from([(
@@ -44,9 +48,6 @@ async fn test_oem_manager_profiles_passed_to_machine_setup() {
4448
)]),
4549
)]);
4650

47-
use carbide_redfish::libredfish::RedfishAuth;
48-
use carbide_secrets::credentials::{CredentialKey, CredentialType};
49-
5051
let sim = RedfishSim::default();
5152
let timepoint = sim.timepoint();
5253
let client = sim
@@ -61,13 +62,8 @@ async fn test_oem_manager_profiles_passed_to_machine_setup() {
6162
.await
6263
.unwrap();
6364

64-
let result = carbide_machine_controller::handler::call_machine_setup_and_handle_no_dpu_error(
65-
client.as_ref(),
66-
None,
67-
1,
68-
&config.machine_state_handler_site_config(),
69-
)
70-
.await;
65+
let result =
66+
call_machine_setup_and_handle_no_dpu_error(client.as_ref(), None, 1, &config).await;
7167

7268
assert!(result.is_ok());
7369

0 commit comments

Comments
 (0)