Skip to content

fix(rest-api): keep expected hardware BMC MACs immutable - #4642

Merged
pbreton merged 4 commits into
NVIDIA:mainfrom
pbreton:codex/issue-4362-immutable-bmc-mac
Aug 6, 2026
Merged

fix(rest-api): keep expected hardware BMC MACs immutable#4642
pbreton merged 4 commits into
NVIDIA:mainfrom
pbreton:codex/issue-4362-immutable-bmc-mac

Conversation

@pbreton

@pbreton pbreton commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Expected Switch and Expected Power Shelf PATCH requests currently accept a changed bmcMacAddress and update Cloud storage, while Core identifies and updates these resources by UUID without changing their physical BMC MAC. A successful request can therefore leave Cloud, Core, and Flow disagreeing about the hardware identity.

This change rejects physical BMC MAC replacements after site authorization and before any database or workflow mutation. Omitted values and formatting-equivalent reassertions remain accepted, and the stored spelling is preserved. The implementation reuses the normalized comparison already applied to Expected Machines and documents the update fields as deprecated and immutable in OpenAPI.

Related issues

Fixes #4362

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.)

Validation performed:

  • make rest-api/test-api
  • go vet ./api/...
  • (cd rest-api/sdk/standard && go test ./... -count=1)
  • make rest-api/lint-openapi
  • make rest-api/generate-sdk
  • make rest-api/publish-openapi
  • OpenAPI compatibility check with CI-pinned oasdiff v1.18.2 (no breaking changes)
  • git diff --check upstream/main...HEAD

Additional Notes

This is an attempt at fully automated issue resolution using Codex with Sol 5.6 Medium.

Reject physical BMC MAC replacements for expected switches and power shelves while accepting formatting-equivalent reassertions. Preserve the stored identity passed to Core and mark the update fields deprecated in OpenAPI and the generated SDK.

Fixes NVIDIA#4362

Signed-off-by: Patrice Breton <pbreton@nvidia.com>
@copy-pr-bot

copy-pr-bot Bot commented Aug 6, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: c46dde67-1f4e-4d30-ac94-f83a0302c409

📥 Commits

Reviewing files that changed from the base of the PR and between cd3594f and 159b73c.

⛔ Files ignored due to path filters (2)
  • rest-api/sdk/standard/model_expected_power_shelf_update_request.go is excluded by !rest-api/sdk/standard/model_*.go
  • rest-api/sdk/standard/model_expected_switch_update_request.go is excluded by !rest-api/sdk/standard/model_*.go
📒 Files selected for processing (6)
  • rest-api/api/pkg/api/handler/expectedmachine.go
  • rest-api/api/pkg/api/handler/expectedmachine_test.go
  • rest-api/api/pkg/api/handler/expectedpowershelf.go
  • rest-api/api/pkg/api/handler/expectedswitch.go
  • rest-api/docs/index.html
  • rest-api/openapi/spec.yaml
🚧 Files skipped from review as they are similar to previous changes (4)
  • rest-api/openapi/spec.yaml
  • rest-api/api/pkg/api/handler/expectedpowershelf.go
  • rest-api/api/pkg/api/handler/expectedmachine.go
  • rest-api/api/pkg/api/handler/expectedswitch.go

Summary by CodeRabbit

  • Bug Fixes

    • Prevented BMC MAC address changes when updating Expected Machines, Power Shelves, and Switches.
    • Equivalent MAC address formatting is accepted without changing the stored identity.
    • Invalid MAC changes return a clear HTTP 400 validation error and do not trigger update workflows.
  • Documentation

    • Marked affected BMC MAC fields as deprecated and documented their immutable update behavior.

Walkthrough

Expected Switch and Expected Power Shelf updates now reject physical BMC MAC changes before mutation. Equivalent MAC formatting remains compatible. ExpectedMachine helper names are generalized, and the OpenAPI contract documents immutable MAC fields.

Changes

BMC MAC immutability

Layer / File(s) Summary
Generalized ExpectedMachine MAC helpers
rest-api/api/pkg/api/handler/expectedmachine.go, rest-api/api/pkg/api/handler/expectedmachine_test.go
MAC immutability helpers and their test references use component-neutral names.
Switch and power shelf update enforcement
rest-api/api/pkg/api/handler/expectedpowershelf.go, rest-api/api/pkg/api/handler/expectedpowershelf_test.go, rest-api/api/pkg/api/handler/expectedswitch.go, rest-api/api/pkg/api/handler/expectedswitch_test.go, rest-api/openapi/spec.yaml
Handlers reject physical MAC changes with HTTP 400 before mutation. Tests cover equivalent formatting, persistence, response values, errors, and workflow calls. OpenAPI fields are deprecated and documented as immutable.

Estimated code review effort: 2 (Simple) | ~15 minutes

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Linked Issues check ❓ Inconclusive The reviewable changes satisfy the issue requirements, but generated SDK updates cannot be verified because two SDK model files were excluded by path filters. Provide or review the excluded SDK model files to confirm that both update fields are documented as immutable or deprecated.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the primary change: preserving BMC MAC immutability for expected hardware.
Description check ✅ Passed The description directly explains the BMC MAC immutability fix, compatibility behavior, documentation changes, and validation performed.
Out of Scope Changes check ✅ Passed The handler, test, helper, and OpenAPI changes directly support BMC MAC immutability and the linked issue objectives.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@pbreton

pbreton commented Aug 6, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai full review.

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

@pbreton I will perform a complete review of pull request #4642.

✅ Action performed

Full review finished.

@thossain-nv thossain-nv added the rest-api Add this label when an issue or PR concerns NICo REST API label Aug 6, 2026 — with ChatGPT Codex Connector

@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 (1)
rest-api/openapi/spec.yaml (1)

24258-24262: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add the missing "stored spelling preserved" and "HTTP 400" details to both bmcMacAddress update descriptions.

Both descriptions state that a formatting-equivalent MAC is accepted and a physical MAC change is rejected, but neither states two required facts:

  • The response code for a rejected physical MAC change is HTTP 400.
  • Resubmitting a formatting-equivalent MAC does not change the stored spelling; the originally stored value is preserved.

Add both facts to the ExpectedPowerShelfUpdateRequest.bmcMacAddress description (Line 24260) and the ExpectedSwitchUpdateRequest.bmcMacAddress description (Line 24824).

As per path instructions for rest-api/openapi/spec.yaml: "Update descriptions must state that clients should omit these fields, formatting-equivalent MAC values remain accepted for compatibility, physical MAC changes are rejected with HTTP 400, and the stored spelling is preserved."

📝 Proposed description updates
         bmcMacAddress:
           type:
             - string
             - 'null'
           pattern: '^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$'
           deprecated: true
           description: |-
             Immutable MAC address of the Expected Power Shelf's BMC (Baseboard Management Controller).
-            Omit this field when updating. A formatting-equivalent value is accepted for compatibility,
-            but changing the physical MAC address is rejected.
+            Omit this field when updating. A formatting-equivalent value is accepted for compatibility
+            and the stored spelling is preserved; changing the physical MAC address is rejected with
+            HTTP 400.

Apply the equivalent change to ExpectedSwitchUpdateRequest.bmcMacAddress.

Also applies to: 24822-24826

🤖 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 `@rest-api/openapi/spec.yaml` around lines 24258 - 24262, Update the
bmcMacAddress descriptions in ExpectedPowerShelfUpdateRequest and
ExpectedSwitchUpdateRequest to state that clients should omit the field when
updating, formatting-equivalent MAC values remain accepted for compatibility,
physical MAC changes are rejected with HTTP 400, and resubmission preserves the
originally stored spelling.

Source: Path instructions

🤖 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 `@rest-api/openapi/spec.yaml`:
- Around line 24258-24262: Update the bmcMacAddress descriptions in
ExpectedPowerShelfUpdateRequest and ExpectedSwitchUpdateRequest to state that
clients should omit the field when updating, formatting-equivalent MAC values
remain accepted for compatibility, physical MAC changes are rejected with HTTP
400, and resubmission preserves the originally stored spelling.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 9acc80dd-a960-4a12-9b62-77e537c14591

📥 Commits

Reviewing files that changed from the base of the PR and between 4effae5 and cd3594f.

⛔ Files ignored due to path filters (2)
  • rest-api/sdk/standard/model_expected_power_shelf_update_request.go is excluded by !rest-api/sdk/standard/model_*.go
  • rest-api/sdk/standard/model_expected_switch_update_request.go is excluded by !rest-api/sdk/standard/model_*.go
📒 Files selected for processing (8)
  • rest-api/api/pkg/api/handler/expectedmachine.go
  • rest-api/api/pkg/api/handler/expectedmachine_test.go
  • rest-api/api/pkg/api/handler/expectedpowershelf.go
  • rest-api/api/pkg/api/handler/expectedpowershelf_test.go
  • rest-api/api/pkg/api/handler/expectedswitch.go
  • rest-api/api/pkg/api/handler/expectedswitch_test.go
  • rest-api/docs/index.html
  • rest-api/openapi/spec.yaml

pbreton added 3 commits August 5, 2026 18:02
Signed-off-by: Patrice Breton <pbreton@nvidia.com>
Signed-off-by: Patrice Breton <pbreton@nvidia.com>
Signed-off-by: Patrice Breton <pbreton@nvidia.com>
@pbreton
pbreton marked this pull request as ready for review August 6, 2026 05:21
@pbreton
pbreton requested a review from a team as a code owner August 6, 2026 05:21
@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown

@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown

🔐 TruffleHog Secret Scan

No secrets or credentials found!

Your code has been scanned for 700+ types of secrets and credentials. All clear! 🎉

🔗 View scan details

🕐 Last updated: 2026-08-06 05:23:37 UTC | Commit: 159b73c

@thossain-nv thossain-nv 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.

Looks good, thanks @pbreton

@pbreton
pbreton merged commit d384d49 into NVIDIA:main Aug 6, 2026
130 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

rest-api Add this label when an issue or PR concerns NICo REST API

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(rest-api): keep switch and power-shelf BMC MAC identities immutable

2 participants