Skip to content
This repository was archived by the owner on Jun 2, 2026. It is now read-only.

chore: Apply the new FromProto/ToProto modeling to InfiniBandPartition#594

Closed
chet wants to merge 1 commit into
NVIDIA:mainfrom
chet:proto-infinibandpartition-receivers
Closed

chore: Apply the new FromProto/ToProto modeling to InfiniBandPartition#594
chet wants to merge 1 commit into
NVIDIA:mainfrom
chet:proto-infinibandpartition-receivers

Conversation

@chet

@chet chet commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Description

Brings InfiniBandPartition in line with the proto-modeling changes. The handler keeps its REST surface; Create and Update route through ToProto on the API request types and the entity gains the full round-trip plus a delete-request builder. The entity also picks up the typed Labels field per the InstanceType reference in #540 -- it reaches Labels.ToProto() / Labels.FromProto(...) directly.

Primary callouts are:

  • API request side: APIInfiniBandPartitionCreateRequest.ToProto(ibp) and APIInfiniBandPartitionUpdateRequest.ToProto(ibp); both source corresponding fields via ibp.ToProto().
  • Entity side: InfiniBandPartition.ToProto, FromProto, and ToDeletionRequestProto. There's also a new InfiniBandPartition.Validate() so site-driven FromProto callers can do FromProto + Validate -- mirroring the MachineCapability pattern (which went in at chore: Apply the new FromProto/ToProto modeling to MachineCapability #569).
  • InfiniBandPartitionStatus is now a typed string with its own .FromProto(state) and .Message() methods, replacing the InfiniBandPartitionStatusFromProto(state) helper that split a single proto state into (status, message). The workflow activity caller is just a two-liner now.
  • Handler simplified to one-liners, and the inline cwssaws / model/util imports drop.

As part of the new typed InfiniBandPartitionStatus (and the already-typed Labels), the typing propagates through the API and DAO layers, but nothing changes on the wire -- JSON serialization of type X string is identical to string, the OpenAPI spec still just says "string", and the SDK is unaffected.

Tests added!

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

Type of Change

  • Feature - New feature or functionality (feat:)
  • Fix - Bug fixes (fix:)
  • Chore - Modification or removal of existing functionality (chore:)
  • Refactor - Refactoring of existing functionality (refactor:)
  • Docs - Changes in documentation or OpenAPI schema (docs:)
  • CI - Changes in GitHub workflows. Requires additional scrutiny (ci:)
  • Version - Issuing a new release version (version:)

Services Affected

  • API - API models or endpoints updated
  • Workflow - Workflow service updated
  • DB - DB DAOs or migrations updated
  • Site Manager - Site Manager updated
  • Cert Manager - Cert Manager updated
  • Site Agent - Site Agent updated
  • Flow - Flow service updated
  • Powershelf Manager - Powershelf Manager updated
  • NVSwitch Manager - NVSwitch Manager updated

Related Issues (Optional)

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

@chet chet requested a review from a team as a code owner June 1, 2026 18:30
@coderabbitai

coderabbitai Bot commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Summary by CodeRabbit

  • Tests

    • Added proto-conversion tests and extended validation (description length); updated many test fixtures to use typed status values.
  • Refactor

    • Standardized typed status across API, DB, and workflow layers; introduced request-mapping helpers and tightened validation for partition inputs.
  • Bug Fixes

    • Fixed status handling and conversions to ensure consistent, correct status values and status-detail writing across workflows and records.

Walkthrough

This PR converts InfiniBandPartition status handling to a typed cdbm.InfiniBandPartitionStatus enum across DB models, API models/handlers, workflow activity, and tests; adds API ToProto helpers for workflow requests; and updates validation and test fixtures to use typed status pointers.

Changes

InfiniBandPartition Status Typed Enum Refactor

Layer / File(s) Summary
Database Model - Typed Status Enum & Validation
db/pkg/db/model/infinibandpartition.go
InfiniBandPartitionStatus named string type and constants added; FromProto and Message() methods added. InfiniBandPartition, InfiniBandPartitionCreateInput, and InfiniBandPartitionUpdateInput now use typed status fields. DAO Create calls Validate() and Update enforces name/status membership rules.
Database Model Tests - Enum Coverage & Validation
db/pkg/db/model/infinibandpartition_test.go
Adds unit tests for ToProto, FromProto, ToDeletionRequestProto, status mapping/message, and validation. DAO tests updated to use typed status pointers and include invalid-status cases and early error guards.
API Model - Request Converters & Typed Response Fields
api/pkg/api/model/infinibandpartition.go
Adds ToProto for create/update requests, changes Validate methods to pointer receivers, and updates API response Status fields to cdbm.InfiniBandPartitionStatus.
API Model Tests - Converter & Validation Coverage
api/pkg/api/model/infinibandpartition_test.go
Adds tests verifying ToProto mappings and extends validation tables with >1024-character description failure cases.
API Handlers - Workflow Request Construction & Status Validation
api/pkg/api/handler/infinibandpartition.go, api/pkg/api/handler/infinibandpartition_test.go
Handlers now use ToProto/ToDeletionRequestProto helpers for workflow requests. Status-detail writes use string(enum). GetAll casts query status to the typed enum before membership checks. Unused imports removed.
Handler Tests - Typed Status Fixtures
api/pkg/api/handler/*, api/pkg/api/handler/infinibandinterface_test.go
Test helpers and fixtures updated to construct typed InfiniBandPartition status pointers via cdb.Ptr(...) or db.Ptr(...); testBuildIBPartition signature updated accordingly.
Test Data - InfiniBandInterface Layer Tests
db/pkg/db/model/infinibandinterface_test.go
Standardizes InfiniBandPartition fixture status pointers to db.Ptr(InfiniBandPartitionStatusReady) across DAO tests and adjusts an update test's interface status assignment.
Test Data - Instance & Link Handler Tests
api/pkg/api/handler/instance_test.go, api/pkg/api/handler/instancebatch_test.go, api/pkg/api/handler/nvlinkinterface_test.go
Updates multiple instance and NVLink handler test fixtures to use cdb.Ptr(...) for partition status pointers.
Workflow Activity - Status Enum Integration
workflow/pkg/activity/infinibandpartition/infinibandpartition.go, workflow/pkg/util/testing.go
UpdateInfiniBandPartitionsInDB derives typed status via FromProto, uses status.Message() for detail text, and passes *cdbm.InfiniBandPartitionStatus to the DB update helper. Test helper signature updated to accept typed status.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.63% 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 describes the primary change: applying proto-modeling patterns (FromProto/ToProto) to the InfiniBandPartition entity, which is the central objective of this refactoring PR.
Description check ✅ Passed The description comprehensively explains the changeset, including API request modifications, entity-side proto builders, typed status enums, handler simplifications, and test additions—all directly aligned with the implemented changes.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@github-actions

github-actions Bot commented Jun 1, 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-06-01 18:32:26 UTC | Commit: 7b4ef7e

@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: 3

Caution

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

⚠️ Outside diff range comments (1)
workflow/pkg/activity/infinibandpartition/infinibandpartition.go (1)

199-202: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Replace the cross-domain Deleting comparison with InfiniBandPartitionStatusDeleting

ibp.Status is cdbm.InfiniBandPartitionStatus, and cdbm.InfiniBandInterfaceStatusDeleting is an untyped string constant, so the current comparison type-checks—but it relies on both domains using the same "Deleting" value and obscures intent. Use cdbm.InfiniBandPartitionStatusDeleting at both occurrences (lines 200 and 244).

🐛 Proposed correction (apply at both Line 200 and Line 244)
-		if ibp.Status == cdbm.InfiniBandInterfaceStatusDeleting {
+		if ibp.Status == cdbm.InfiniBandPartitionStatusDeleting {
🤖 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 `@workflow/pkg/activity/infinibandpartition/infinibandpartition.go` around
lines 199 - 202, The code compares ibp.Status to the wrong cross-domain constant
cdbm.InfiniBandInterfaceStatusDeleting; replace both comparisons (the one
referencing ibp.Status and the similar one later) with
cdbm.InfiniBandPartitionStatusDeleting to use the correct
InfiniBandPartitionStatus enum; update the two occurrences that currently use
cdbm.InfiniBandInterfaceStatusDeleting so they read comparisons against
cdbm.InfiniBandPartitionStatusDeleting (references: controllerIbp.Status,
ibp.Status, cdbm.InfiniBandPartitionStatusDeleting).
🧹 Nitpick comments (1)
db/pkg/db/model/infinibandpartition_test.go (1)

1057-1057: ⚡ Quick win

Remove the leftover debug print from the update test.

This writes to stdout on every successful run and adds noise without strengthening the assertion set.

Suggested cleanup
-			fmt.Printf("\ngot ID: %v, Created: %v, Updated: %v", got.ID.String(), got.Created, got.Updated)
🤖 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 `@db/pkg/db/model/infinibandpartition_test.go` at line 1057, Remove the
leftover debug print: delete the fmt.Printf("\ngot ID: %v, Created: %v, Updated:
%v", got.ID.String(), got.Created, got.Updated) call in the update test (the
line referencing fmt.Printf and the local variable got) in
infinibandpartition_test.go; if you want non-noisy test output keep a t.Logf
instead but preferably remove the print altogether so tests don't write to
stdout on success.
🤖 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 `@db/pkg/db/model/infinibandinterface_test.go`:
- Line 725: Replace the partition status constant usage with the interface
status constant in the test: instead of setting uInfiniBandInterface.Status =
string(InfiniBandPartitionStatusPending), set it to the corresponding
InfiniBandInterface status constant (e.g., InfiniBandInterfaceStatusPending or
whatever constant is defined for interface.Status) so the test uses the correct
domain-specific constant; update the assignment in the test where
uInfiniBandInterface.Status is set and ensure any helper expectations/assertions
reference the same interface status constant.

In `@db/pkg/db/model/infinibandpartition.go`:
- Around line 148-161: The Create and Update DAO methods must call the model's
Validate() to enforce the new invariants (name length/whitespace and status
membership) before persisting changes: in the Create function (where the
InfiniBandPartition entity is assembled) call ibp.Validate() and return the
validation error instead of only checking Status; in the Update function
validate the patched view (the new Name and Status values combined into an
InfiniBandPartition or a small struct) with Validate() before executing the SQL
update so leading/trailing whitespace or too-short names are rejected; reference
the existing InfiniBandPartition.Validate and validateNameWhitespace helpers and
ensure both Create and Update propagate validation errors to callers.

In `@workflow/pkg/activity/infinibandpartition/infinibandpartition.go`:
- Around line 269-273: The log uses the stale outer variable err instead of the
local error serr returned by mibp.updateIBPStatusInDB; update the logger call in
the block after calling updateIBPStatusInDB (where serr is set) to pass serr to
slogger.Error().Err(...) and keep the same message (i.e., replace Err(err) with
Err(serr)) so the actual DB update error is logged; reference the variables serr
and err and the method updateIBPStatusInDB to locate the change.

---

Outside diff comments:
In `@workflow/pkg/activity/infinibandpartition/infinibandpartition.go`:
- Around line 199-202: The code compares ibp.Status to the wrong cross-domain
constant cdbm.InfiniBandInterfaceStatusDeleting; replace both comparisons (the
one referencing ibp.Status and the similar one later) with
cdbm.InfiniBandPartitionStatusDeleting to use the correct
InfiniBandPartitionStatus enum; update the two occurrences that currently use
cdbm.InfiniBandInterfaceStatusDeleting so they read comparisons against
cdbm.InfiniBandPartitionStatusDeleting (references: controllerIbp.Status,
ibp.Status, cdbm.InfiniBandPartitionStatusDeleting).

---

Nitpick comments:
In `@db/pkg/db/model/infinibandpartition_test.go`:
- Line 1057: Remove the leftover debug print: delete the fmt.Printf("\ngot ID:
%v, Created: %v, Updated: %v", got.ID.String(), got.Created, got.Updated) call
in the update test (the line referencing fmt.Printf and the local variable got)
in infinibandpartition_test.go; if you want non-noisy test output keep a t.Logf
instead but preferably remove the print altogether so tests don't write to
stdout on success.
🪄 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: 01ef1eec-26f9-40e4-bf4f-375ce4ac8b4e

📥 Commits

Reviewing files that changed from the base of the PR and between 72c00aa and 7b4ef7e.

📒 Files selected for processing (14)
  • api/pkg/api/handler/infinibandinterface_test.go
  • api/pkg/api/handler/infinibandpartition.go
  • api/pkg/api/handler/infinibandpartition_test.go
  • api/pkg/api/handler/instance_test.go
  • api/pkg/api/handler/instancebatch_test.go
  • api/pkg/api/handler/nvlinkinterface_test.go
  • api/pkg/api/model/infinibandpartition.go
  • api/pkg/api/model/infinibandpartition_test.go
  • db/pkg/db/model/helper_test.go
  • db/pkg/db/model/infinibandinterface_test.go
  • db/pkg/db/model/infinibandpartition.go
  • db/pkg/db/model/infinibandpartition_test.go
  • workflow/pkg/activity/infinibandpartition/infinibandpartition.go
  • workflow/pkg/util/testing.go

Comment thread db/pkg/db/model/infinibandinterface_test.go Outdated
Comment thread db/pkg/db/model/infinibandpartition.go
Comment thread workflow/pkg/activity/infinibandpartition/infinibandpartition.go
@chet chet force-pushed the proto-infinibandpartition-receivers branch from 7b4ef7e to 6d7e144 Compare June 1, 2026 18:42
Brings `InfiniBandPartition` in line with the proto-modeling changes. The handler keeps its REST surface; Create and Update route through `ToProto` on the API request types and the entity gains the full round-trip plus a delete-request builder. The entity also picks up the typed `Labels` field per the `InstanceType` reference in NVIDIA#540 -- it reaches `Labels.ToProto()` / `Labels.FromProto(...)` directly.

Primary callouts are:
- API request side: `APIInfiniBandPartitionCreateRequest.ToProto(ibp)` and `APIInfiniBandPartitionUpdateRequest.ToProto(ibp)`; both source corresponding fields via `ibp.ToProto()`.
- Entity side: `InfiniBandPartition.ToProto`, `FromProto`, and `ToDeletionRequestProto`. There's also a new `InfiniBandPartition.Validate()` so site-driven `FromProto` callers can do `FromProto` + `Validate` -- mirroring the MachineCapability pattern (which went in at NVIDIA#569).
- `InfiniBandPartitionStatus` is now a typed string with its own `.FromProto(state)` and `.Message()` methods, replacing the `InfiniBandPartitionStatusFromProto(state)` helper that split a single proto state into `(status, message)`. The workflow activity caller is just a two-liner now.
- Handler simplified to one-liners, and the inline `cwssaws` / `model/util` imports drop.

As part of the new typed `InfiniBandPartitionStatus` (and the already-typed `Labels`), the typing propagates through the API and DAO layers, but nothing changes on the wire -- JSON serialization of `type X string` is identical to `string`, the OpenAPI spec still just says "string", and the SDK is unaffected.

Tests added!

Signed-off-by: Chet Nichols III <chetn@nvidia.com>
@chet chet force-pushed the proto-infinibandpartition-receivers branch from 6d7e144 to b4c507e Compare June 1, 2026 18:49

@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)
db/pkg/db/model/infinibandinterface_test.go (1)

782-782: ⚡ Quick win

Drop debug print from update test path.

Line 782 writes directly to stdout during tests. This is noisy and unnecessary once assertions are in place.

Proposed cleanup
-			fmt.Printf("\ngot ID: %v, Created: %v, Updated: %v", got.ID.String(), got.Created, got.Updated)

If this is removed, fmt can likely be dropped from imports in this file.

🤖 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 `@db/pkg/db/model/infinibandinterface_test.go` at line 782, Remove the debug
stdout print in the update test (the fmt.Printf line that prints "got ID...") so
the test no longer writes to stdout; after removing that statement also delete
the now-unused fmt import from infinibandinterface_test.go (or run `go vet`/`go
test` to catch the unused import) to keep imports clean.
db/pkg/db/model/infinibandpartition_test.go (1)

1057-1057: ⚡ Quick win

Remove debug stdout from DAO update test.

Line 1057 prints runtime values during normal test execution. This creates noisy CI logs and obscures failures.

Proposed cleanup
-			fmt.Printf("\ngot ID: %v, Created: %v, Updated: %v", got.ID.String(), got.Created, got.Updated)
🤖 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 `@db/pkg/db/model/infinibandpartition_test.go` at line 1057, Remove the debug
stdout print in the DAO update test by deleting the fmt.Printf("\ngot ID: %v,
Created: %v, Updated: %v", got.ID.String(), got.Created, got.Updated) line in
infinibandpartition_test.go; if you want retained test diagnostics, replace it
with t.Logf(...) inside the test function so output is only shown on failure
rather than always printing to stdout.
🤖 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 `@db/pkg/db/model/infinibandinterface_test.go`:
- Line 782: Remove the debug stdout print in the update test (the fmt.Printf
line that prints "got ID...") so the test no longer writes to stdout; after
removing that statement also delete the now-unused fmt import from
infinibandinterface_test.go (or run `go vet`/`go test` to catch the unused
import) to keep imports clean.

In `@db/pkg/db/model/infinibandpartition_test.go`:
- Line 1057: Remove the debug stdout print in the DAO update test by deleting
the fmt.Printf("\ngot ID: %v, Created: %v, Updated: %v", got.ID.String(),
got.Created, got.Updated) line in infinibandpartition_test.go; if you want
retained test diagnostics, replace it with t.Logf(...) inside the test function
so output is only shown on failure rather than always printing to stdout.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 4ac6e0e5-9c5a-401b-a0fa-cc31b7cc96a7

📥 Commits

Reviewing files that changed from the base of the PR and between 6d7e144 and b4c507e.

📒 Files selected for processing (14)
  • api/pkg/api/handler/infinibandinterface_test.go
  • api/pkg/api/handler/infinibandpartition.go
  • api/pkg/api/handler/infinibandpartition_test.go
  • api/pkg/api/handler/instance_test.go
  • api/pkg/api/handler/instancebatch_test.go
  • api/pkg/api/handler/nvlinkinterface_test.go
  • api/pkg/api/model/infinibandpartition.go
  • api/pkg/api/model/infinibandpartition_test.go
  • db/pkg/db/model/helper_test.go
  • db/pkg/db/model/infinibandinterface_test.go
  • db/pkg/db/model/infinibandpartition.go
  • db/pkg/db/model/infinibandpartition_test.go
  • workflow/pkg/activity/infinibandpartition/infinibandpartition.go
  • workflow/pkg/util/testing.go
🚧 Files skipped from review as they are similar to previous changes (12)
  • workflow/pkg/util/testing.go
  • api/pkg/api/handler/instancebatch_test.go
  • api/pkg/api/handler/nvlinkinterface_test.go
  • api/pkg/api/handler/infinibandinterface_test.go
  • api/pkg/api/handler/instance_test.go
  • api/pkg/api/handler/infinibandpartition_test.go
  • db/pkg/db/model/helper_test.go
  • api/pkg/api/model/infinibandpartition_test.go
  • api/pkg/api/handler/infinibandpartition.go
  • workflow/pkg/activity/infinibandpartition/infinibandpartition.go
  • db/pkg/db/model/infinibandpartition.go
  • api/pkg/api/model/infinibandpartition.go

@github-actions

github-actions Bot commented Jun 1, 2026

Copy link
Copy Markdown

🔍 Container Scan Summary

Service Total Critical High Medium Low Other
nico-flow 66 4 34 18 2 8
nico-nsm 82 2 28 43 9 0
nico-psm 67 4 35 18 2 8
nico-rest-api 100 6 53 30 3 8
nico-rest-cert-manager 65 4 34 18 1 8
nico-rest-db 66 4 34 18 2 8
nico-rest-site-agent 65 4 34 18 1 8
nico-rest-site-manager 65 4 34 18 1 8
nico-rest-workflow 67 4 35 18 2 8
TOTAL 643 36 321 199 23 64

Per-CVE detail lives in the per-service grype-* artifacts (JSON + SARIF). Severity counts only — no CVE IDs published here.

@chet

chet commented Jun 2, 2026

Copy link
Copy Markdown
Contributor Author

Going to re-open this on the infra-controller side!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant