fix: add support to bmc-explorer for Delta powershelves#3455
Conversation
04e2385 to
350133b
Compare
Summary by CodeRabbit
WalkthroughAdds Delta power shelf support across mock Redfish services, chassis exploration, synthesized system reports, hardware classification, PSU power-state aggregation, integration tests, and expected inventory registration. ChangesDelta power shelf support
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant DeltaPowerShelfBmc
participant ChassisExplorer
participant ExplorationReporter
participant SiteExplorer
DeltaPowerShelfBmc->>ChassisExplorer: expose chassis and Delta PSU OEM states
ChassisExplorer->>ChassisExplorer: aggregate PSU states
ChassisExplorer->>ExplorationReporter: classify DeltaPowerShelf
ExplorationReporter->>SiteExplorer: build synthesized ComputerSystem report
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
🌿 Preview your docs: https://nvidia-preview-pull-request-3455.docs.buildwithfern.com/infra-controller |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
crates/bmc-explorer/src/chassis.rs (1)
489-505: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winConsolidate the power-shelf aggregation with the Lite-On path.
powershelf_power_statereproduces the exact on/off/unknown collapse already implemented byLiteOnSuppliesState::to_model(chassis.rs:520-535). Two copies of the same rule invite divergence over time. Consider having the Lite-On path delegate to this generic helper (both operate onOption<bool>per-supply flags), keeping a single source of truth for shelf-state aggregation.As per coding guidelines: "Duplicate code (copy/paste, similar logic, abstractions)."
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@crates/bmc-explorer/src/chassis.rs` around lines 489 - 505, Consolidate the duplicated power-state aggregation by updating LiteOnSuppliesState::to_model to delegate its per-supply Option<bool> flags to powershelf_power_state. Preserve the existing On, Off, and Unknown behavior while making powershelf_power_state the single implementation of the collapse rule.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@crates/bmc-mock/src/machine_info.rs`:
- Around line 825-833: Update delta_power_shelf to validate
delta_psu_power.len() against DEFAULT_PSU_POWER.len() before constructing the
DeltaPowerShelf or its PSU Cow, rejecting empty, short, and oversized vectors so
only the documented six-bay shape is produced; ensure the public helper path
also fails early through this validation.
---
Nitpick comments:
In `@crates/bmc-explorer/src/chassis.rs`:
- Around line 489-505: Consolidate the duplicated power-state aggregation by
updating LiteOnSuppliesState::to_model to delegate its per-supply Option<bool>
flags to powershelf_power_state. Preserve the existing On, Off, and Unknown
behavior while making powershelf_power_state the single implementation of the
collapse rule.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: fe2f9b5c-21d0-42d3-a80b-e0edff8fb079
⛔ Files ignored due to path filters (1)
Cargo.lockis excluded by!**/*.lock
📒 Files selected for processing (19)
Cargo.tomlcrates/bmc-explorer/Cargo.tomlcrates/bmc-explorer/src/chassis.rscrates/bmc-explorer/src/hw/mod.rscrates/bmc-explorer/src/lib.rscrates/bmc-explorer/tests/integration/powershelf_explore.rscrates/bmc-mock/src/bmc_state.rscrates/bmc-mock/src/hw/delta_power_shelf.rscrates/bmc-mock/src/hw/mod.rscrates/bmc-mock/src/lib.rscrates/bmc-mock/src/machine_info.rscrates/bmc-mock/src/mock_machine_router.rscrates/bmc-mock/src/redfish/computer_system.rscrates/bmc-mock/src/redfish/oem/mod.rscrates/bmc-mock/src/redfish/power_supply.rscrates/bmc-mock/src/redfish/service_root.rscrates/bmc-mock/src/test_support/mod.rscrates/machine-a-tron/src/host_machine.rscrates/machine-a-tron/src/machine_a_tron.rs
| fn delta_power_shelf(&self) -> hw::delta_power_shelf::DeltaPowerShelf<'_> { | ||
| hw::delta_power_shelf::DeltaPowerShelf { | ||
| bmc_mac_address: self.bmc_mac_address, | ||
| product_serial_number: Cow::Borrowed(&self.serial), | ||
| psu_power: self.delta_psu_power.as_deref().map_or( | ||
| Cow::Borrowed(hw::delta_power_shelf::DEFAULT_PSU_POWER), | ||
| Cow::Borrowed, | ||
| ), | ||
| } |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
Enforce the documented Delta PSU cardinality.
Because delta_psu_power is a public Vec<bool>, this code currently creates one PowerSupplyUnit per arbitrary entry. Empty, short, or oversized vectors therefore produce a mock that is not the documented six-bay Delta shelf and can let exploration tests exercise an invalid resource shape. Validate the length against DEFAULT_PSU_POWER.len() before constructing the Cow (the public helper should then fail early as well).
Proposed fix
fn delta_power_shelf(&self) -> hw::delta_power_shelf::DeltaPowerShelf<'_> {
+ let default_psu_power: &[bool] = hw::delta_power_shelf::DEFAULT_PSU_POWER;
+ let psu_power = self
+ .delta_psu_power
+ .as_deref()
+ .unwrap_or(default_psu_power);
+ assert_eq!(
+ psu_power.len(),
+ default_psu_power.len(),
+ "Delta power shelf PSU state count must match the default shelf",
+ );
+
hw::delta_power_shelf::DeltaPowerShelf {
bmc_mac_address: self.bmc_mac_address,
product_serial_number: Cow::Borrowed(&self.serial),
- psu_power: self.delta_psu_power.as_deref().map_or(
- Cow::Borrowed(hw::delta_power_shelf::DEFAULT_PSU_POWER),
- Cow::Borrowed,
- ),
+ psu_power: Cow::Borrowed(psu_power),
}
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| fn delta_power_shelf(&self) -> hw::delta_power_shelf::DeltaPowerShelf<'_> { | |
| hw::delta_power_shelf::DeltaPowerShelf { | |
| bmc_mac_address: self.bmc_mac_address, | |
| product_serial_number: Cow::Borrowed(&self.serial), | |
| psu_power: self.delta_psu_power.as_deref().map_or( | |
| Cow::Borrowed(hw::delta_power_shelf::DEFAULT_PSU_POWER), | |
| Cow::Borrowed, | |
| ), | |
| } | |
| fn delta_power_shelf(&self) -> hw::delta_power_shelf::DeltaPowerShelf<'_> { | |
| let default_psu_power: &[bool] = hw::delta_power_shelf::DEFAULT_PSU_POWER; | |
| let psu_power = self | |
| .delta_psu_power | |
| .as_deref() | |
| .unwrap_or(default_psu_power); | |
| assert_eq!( | |
| psu_power.len(), | |
| default_psu_power.len(), | |
| "Delta power shelf PSU state count must match the default shelf", | |
| ); | |
| hw::delta_power_shelf::DeltaPowerShelf { | |
| bmc_mac_address: self.bmc_mac_address, | |
| product_serial_number: Cow::Borrowed(&self.serial), | |
| psu_power: Cow::Borrowed(psu_power), | |
| } | |
| } |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@crates/bmc-mock/src/machine_info.rs` around lines 825 - 833, Update
delta_power_shelf to validate delta_psu_power.len() against
DEFAULT_PSU_POWER.len() before constructing the DeltaPowerShelf or its PSU Cow,
rejecting empty, short, and oversized vectors so only the documented six-bay
shape is produced; ensure the public helper path also fails early through this
validation.
🔍 Container Scan Summary
Per-CVE detail lives in the per-service |
fix: add support to bmc-explorer for Delta powershelves
Related issues
Type of Change
Breaking Changes
Testing
Additional Notes