Skip to content

fix(rest-api): allow clearing an ExpectedMachine BMC IP address#3678

Merged
chet merged 1 commit into
NVIDIA:mainfrom
chet:gh-issue-3630
Jul 19, 2026
Merged

fix(rest-api): allow clearing an ExpectedMachine BMC IP address#3678
chet merged 1 commit into
NVIDIA:mainfrom
chet:gh-issue-3630

Conversation

@chet

@chet chet commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

ExpectedMachine PATCH requests can now distinguish an explicit bmcIpAddress: null from an omitted field. Explicit null clears the address, while omission preserves it for an individual update. Batch requests keep the established contract that every item provides the same field set.

The request model now tracks presence separately from value, and both REST update handlers route explicit null through the existing ExpectedMachineDAO.Clear path. Non-null values and generic UpdateMultiple behavior are unchanged. The OpenAPI contract and generated SDK/docs describe the set, omit, and clear behavior.

Related issues

This supports #3630

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

Additional Notes

  • cargo make format-nightly
  • cargo make clippy
  • cargo make carbide-lints
  • go test -p 1 ./api/...
  • go test -p 1 ./db/...
  • Focused ExpectedMachine handler, model, and DAO regressions after the final review edits
  • Changed-line golangci-lint v2.12.2
  • go vet on changed API/DB packages
  • OpenAPI lint and generated SDK tests
  • Local CodeRabbit and independent reviewer passes

@chet
chet requested a review from a team as a code owner July 17, 2026 18:17
@chet

chet commented Jul 17, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai full_review, thanks!

@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

@chet Understood — I’ll perform a fresh, comprehensive review of #3678, including the request-presence semantics, batch grouping behavior, Core workflow propagation, OpenAPI/generated artifacts, and test coverage.

🐇🔍

✅ Action performed

Full review finished.

@github-actions

Copy link
Copy Markdown

@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Summary by CodeRabbit

  • New Features

    • BMC IP addresses can now be explicitly cleared by sending bmcIpAddress: null in both individual and batch updates.
    • Omitting bmcIpAddress preserves the current stored value.
    • Batch updates now support per-machine BMC IP set/clear behavior.
  • Bug Fixes

    • Invalid empty BMC IP values are rejected and do not trigger an update workflow; cleared values correctly propagate to workflow requests.
  • Documentation

    • Updated OpenAPI docs to spell out set, clear (null), preserve (omitted), and validation rules.
    • Clarified consistent field requirements for batch updates.
  • Tests

    • Added coverage for request JSON semantics and endpoint behavior for both single and batch updates.

Walkthrough

Explicit null BMC IP values now clear persisted ExpectedMachine addresses for single and batch PATCH requests. Omitted values remain unchanged, invalid empty strings are rejected, and request, database, workflow, test, and OpenAPI behavior is covered.

Changes

ExpectedMachine BMC IP semantics

Layer / File(s) Summary
Track BMC IP field presence
rest-api/api/pkg/api/model/expectedmachine.go, rest-api/api/pkg/api/model/expectedmachine_test.go
Update request decoding distinguishes omitted, null, and string BMC IP values while preserving validation and omitting nil values during marshaling.
Clear explicit null values
rest-api/api/pkg/api/handler/expectedmachine.go, rest-api/api/pkg/api/handler/expectedmachine_test.go
Single and batch handlers clear explicitly null BMC IP values inside database transactions before workflow execution, with coverage for preservation, updates, rejection, and clearing.
Validate clearing and documented semantics
rest-api/db/pkg/db/model/expectedmachine_test.go, rest-api/openapi/spec.yaml
DAO tests verify BMC IP clearing, and the OpenAPI specification documents null, omission, non-empty, and batch field behavior.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant APIClient
  participant UpdateExpectedMachineHandler
  participant ExpectedMachineDAO
  participant TemporalWorkflow
  APIClient->>UpdateExpectedMachineHandler: PATCH bmcIpAddress null
  UpdateExpectedMachineHandler->>ExpectedMachineDAO: Clear BmcIpAddress
  ExpectedMachineDAO-->>UpdateExpectedMachineHandler: Return cleared ExpectedMachine
  UpdateExpectedMachineHandler->>TemporalWorkflow: Execute update workflow
  TemporalWorkflow-->>APIClient: Return updated ExpectedMachine
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.11% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: allowing ExpectedMachine BMC IP clearing via explicit null.
Description check ✅ Passed The description is directly aligned with the changeset and clearly explains the new null-vs-omitted PATCH behavior.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ast-grep (0.44.1)
rest-api/docs/index.html

ast-grep timed out on this file


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

@github-actions

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-07-17 18:20:20 UTC | Commit: 59680ce

@chet

chet commented Jul 17, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai full_review, thanks!

@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

@chet Understood. I’ll perform a fresh, comprehensive review of #3678, with particular attention to PATCH presence semantics, mixed batch-update grouping, Core propagation, generated OpenAPI artifacts, and coverage of set/omit/clear behavior.

🐇🔍

✅ Action performed

Full review finished.

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

Actionable comments posted: 1

🤖 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 `@rest-api/openapi/spec.yaml`:
- Around line 21510-21512: Add an allowlist entry to
oasdiff-breaking-changes-ignore.txt for the
ExpectedMachineUpdateRequest.bmcIpAddress minLength change, covering both PATCH
endpoint usages. Keep the existing OpenAPI validation unchanged so empty strings
remain rejected.
🪄 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: c1392df9-4ecf-4001-bcb6-eef3d0216e13

📥 Commits

Reviewing files that changed from the base of the PR and between 0cd8acb and 59680ce.

⛔ Files ignored due to path filters (1)
  • rest-api/sdk/standard/model_expected_machine_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/model/expectedmachine.go
  • rest-api/api/pkg/api/model/expectedmachine_test.go
  • rest-api/db/pkg/db/model/expectedmachine.go
  • rest-api/db/pkg/db/model/expectedmachine_test.go
  • rest-api/docs/index.html
  • rest-api/openapi/spec.yaml

Comment thread rest-api/openapi/spec.yaml Outdated
`ExpectedMachine` PATCH requests can now distinguish an explicit `bmcIpAddress: null` from an omitted field. Explicit null clears the address, while omission continues through the existing update behavior for individual and batch requests.

Primary callouts are:

- `APIExpectedMachineUpdateRequest` now preserves omitted versus explicit `null`, and empty strings remain invalid.
- The REST update handlers route explicit null through the existing `ExpectedMachineDAO.Clear` path; non-null values still use the established update path.
- The OpenAPI contract and generated SDK/docs document the set/omit/clear behavior.

Tests added!

This supports NVIDIA#3630

Signed-off-by: Chet Nichols III <chetn@nvidia.com>
@chet

chet commented Jul 18, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Full review finished.

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
rest-api/api/pkg/api/handler/expectedmachine.go (1)

1543-1558: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Reject batches that mix BMC-IP omission with explicit presence.

Line 1556 records clears per item but never verifies that every item has the same bmcIpAddress presence. Consequently, a batch combining null with omission succeeds, violating the published batch contract. Validate HasBmcIpAddress() consistently across all items before any writes and add a regression test for the mixed-presence payload.

Proposed validation
 	bmcIPClearIDs := make([]uuid.UUID, 0)
-	for _, machineReq := range apiRequests {
+	hasBmcIPAddress := apiRequests[0].HasBmcIpAddress()
+	for i, machineReq := range apiRequests {
+		if machineReq.HasBmcIpAddress() != hasBmcIPAddress {
+			return cutil.NewAPIErrorResponse(
+				c,
+				http.StatusBadRequest,
+				fmt.Sprintf("bmcIpAddress field presence differs at batch index %d", i),
+				nil,
+			)
+		}

As per path instructions, “every item in a batch update must provide the same set of fields.” <path_instructions>

🤖 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/api/pkg/api/handler/expectedmachine.go` around lines 1543 - 1558,
Update the batch validation around the Expected Machine update loop to require
consistent HasBmcIpAddress() presence across every request, rejecting any batch
that mixes explicit null with omission before modifying credsByID or recording
clears. Preserve the existing nil-ID validation and add a regression test
covering a mixed-presence bmcIpAddress payload.

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.

Outside diff comments:
In `@rest-api/api/pkg/api/handler/expectedmachine.go`:
- Around line 1543-1558: Update the batch validation around the Expected Machine
update loop to require consistent HasBmcIpAddress() presence across every
request, rejecting any batch that mixes explicit null with omission before
modifying credsByID or recording clears. Preserve the existing nil-ID validation
and add a regression test covering a mixed-presence bmcIpAddress payload.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 7fd36417-8e7d-4570-9926-7e063c7f9f6f

📥 Commits

Reviewing files that changed from the base of the PR and between d538254 and b4ba508.

⛔ Files ignored due to path filters (2)
  • rest-api/sdk/standard/api_expected_machine.go is excluded by !rest-api/sdk/standard/api_*.go
  • rest-api/sdk/standard/model_expected_machine_update_request.go is excluded by !rest-api/sdk/standard/model_*.go
📒 Files selected for processing (7)
  • rest-api/api/pkg/api/handler/expectedmachine.go
  • rest-api/api/pkg/api/handler/expectedmachine_test.go
  • rest-api/api/pkg/api/model/expectedmachine.go
  • rest-api/api/pkg/api/model/expectedmachine_test.go
  • rest-api/db/pkg/db/model/expectedmachine_test.go
  • rest-api/docs/index.html
  • rest-api/openapi/spec.yaml

@chet
chet merged commit f757b03 into NVIDIA:main Jul 19, 2026
121 checks passed
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