Skip to content

refactor(power-control): reuse loaded machines for endpoint resolution#4063

Open
kunzhao-nv wants to merge 3 commits into
NVIDIA:mainfrom
kunzhao-nv:perf/compute-power-control-routing
Open

refactor(power-control): reuse loaded machines for endpoint resolution#4063
kunzhao-nv wants to merge 3 commits into
NVIDIA:mainfrom
kunzhao-nv:perf/compute-power-control-routing

Conversation

@kunzhao-nv

@kunzhao-nv kunzhao-nv commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Description:

  • Reuse the machine map already loaded for rack-scale and standalone classification when resolving compute-tray endpoints.
  • Apply the shared resolution path to compute power control and firmware operations, avoiding redundant database queries.
  • Add coverage for mixed routing, unknown machine IDs, power-option failures, and endpoint-resolution errors as a patch for feat(power-control): route standalone vs rack-scale machines separately #3873.

Related issues

#3873

Type of Change

  • Add - New feature or capability
  • Change - Changes in existing functionality
  • Fix - Bug fixes
  • Remove - Removed features or deprecated functionality
  • Internal - Internal changes (refactoring, tests, docs, etc.)

Breaking Changes

  • This PR contains breaking changes

Testing

  • Unit tests added/updated
  • Integration tests added/updated
  • Manual testing performed
  • No testing required (docs, internal refactor, etc.)

…esolve

Power and firmware compute paths already load machines to classify
rack-scale vs standalone; resolve BMC endpoints from that map instead of
querying the machine table again.

Signed-off-by: Kun Zhao <kunzhao@nvidia.com>
Add unit coverage for mixed rack/standalone partitions, unknown ids that
do not abort the batch, power-option failures that skip dispatch, and
resolve-from-machines BMC gaps.

Signed-off-by: Kun Zhao <kunzhao@nvidia.com>
Signed-off-by: Kun Zhao <kunzhao@nvidia.com>
@kunzhao-nv
kunzhao-nv requested a review from a team as a code owner July 24, 2026 00:45
@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Compute-tray machine classification and endpoint resolution now reuse preloaded machine maps. Power-control and firmware handlers pass those maps through dispatch paths, while unresolved machines and credential or BMC gaps are reported per target. Unit tests cover partitioning and endpoint-resolution outcomes.

Changes

Compute-tray dispatch reuse

Layer / File(s) Summary
In-memory machine classification
crates/api-core/src/handlers/component_manager.rs
Machine partitioning now classifies caller-provided machine maps synchronously, and tests cover rack-scale, standalone, unknown, and power-option failure cases.
Compute-tray endpoint resolution
crates/api-core/src/handlers/component_manager.rs
Endpoint resolution uses the supplied credential manager and machine map, returns unresolved devices directly, and tests missing machines, BMC data, credentials, and successful endpoint creation.
Dispatch and firmware integration
crates/api-core/src/handlers/component_manager.rs
Power-control and firmware paths load machines once, pass the map into dispatch and endpoint resolution, and consume resolved endpoints with per-machine unresolved results.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

  • NVIDIA/infra-controller#3873: Refactors overlapping machine classification and compute-tray dispatch logic in the same component manager handler.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title is concise and accurately describes the main refactor around reusing loaded machines for endpoint resolution.
Description check ✅ Passed The description is clearly aligned with the refactor, tests, and issue it addresses.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@kunzhao-nv
kunzhao-nv requested a review from spydaNVIDIA July 24, 2026 00:46

@coderabbitai coderabbitai Bot left a comment

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.

🧹 Nitpick comments (2)
crates/api-core/src/handlers/component_manager.rs (2)

1835-1895: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add a direct test for dispatch_compute_tray_power_control.

This function is the key new integration point tying machines_by_id, resolve_compute_tray_endpoints_from_machines, and the ComputeTrayManager backend together, but the added tests only exercise its sub-pieces (prepare_dispatch_lists mirrors the classify/gate/partition step, and resolve_compute_tray_endpoints_from_machines is tested in isolation). Nothing here exercises the full path with a mock backend (success, partial backend failure, and mixed resolved/unresolved input), which is exactly the kind of critical, newly-reused path this PR is meant to harden.

A lightweight mock similar to ReconciliationComputeTrayManager (used in crates/machine-controller/tests/integration/maintenance.rs) would let you assert the ip_to_machine_id mapping and result assembly end-to-end.

🤖 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/api-core/src/handlers/component_manager.rs` around lines 1835 - 1895,
Add direct tests for dispatch_compute_tray_power_control using a lightweight
mock ComputeTrayManager, covering successful dispatch, partial backend failures,
and mixed resolved/unresolved machines. Assert that backend calls receive the
resolved endpoints, results use the resolved ip_to_machine_id mapping,
unresolved machines retain error results, and returned IPs match dispatched
endpoints.

3708-3743: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Test-double duplicates production decision logic — drift risk.

prepare_dispatch_lists hand-mirrors the classify → power-option gate → partition sequence from component_power_control's MachineIds arm, including a hardcoded error string ("failed to update power option: precondition"). If that production logic changes (new branch, different ordering, different error text), this double won't automatically reflect it, and the tests could keep passing against stale logic while the real handler diverges.

Consider extracting the real classify/gate/partition loop in component_power_control into a standalone function that both production code and these tests call directly, rather than re-implementing it here.

🤖 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/api-core/src/handlers/component_manager.rs` around lines 3708 - 3743,
Extract the classify, power-option validation, and rack-scale/standalone
partition logic from component_power_control’s MachineIds arm into a shared
standalone helper. Update both production code and prepare_dispatch_lists to
call that helper, preserving unknown-machine results, failed power-option
handling, partition outputs, and existing error text without duplicating the
decision sequence.
🤖 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.

Nitpick comments:
In `@crates/api-core/src/handlers/component_manager.rs`:
- Around line 1835-1895: Add direct tests for
dispatch_compute_tray_power_control using a lightweight mock ComputeTrayManager,
covering successful dispatch, partial backend failures, and mixed
resolved/unresolved machines. Assert that backend calls receive the resolved
endpoints, results use the resolved ip_to_machine_id mapping, unresolved
machines retain error results, and returned IPs match dispatched endpoints.
- Around line 3708-3743: Extract the classify, power-option validation, and
rack-scale/standalone partition logic from component_power_control’s MachineIds
arm into a shared standalone helper. Update both production code and
prepare_dispatch_lists to call that helper, preserving unknown-machine results,
failed power-option handling, partition outputs, and existing error text without
duplicating the decision sequence.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: f2dbcdcb-43b5-47f8-9877-20b3b8548649

📥 Commits

Reviewing files that changed from the base of the PR and between e588786 and 7e89d7c.

📒 Files selected for processing (1)
  • crates/api-core/src/handlers/component_manager.rs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants