Skip to content

feat: Add net.HardwareAddr wrapper for BMC MAC JSON marshaling#369

Open
jw-nvidia wants to merge 1 commit intoNVIDIA:mainfrom
jw-nvidia:feat/mac_addr_json
Open

feat: Add net.HardwareAddr wrapper for BMC MAC JSON marshaling#369
jw-nvidia wants to merge 1 commit intoNVIDIA:mainfrom
jw-nvidia:feat/mac_addr_json

Conversation

@jw-nvidia
Copy link
Copy Markdown
Contributor

Description

Introduce MACAddress in the bmc package, wrapping net.HardwareAddr and implementing encoding.TextMarshaler/TextUnmarshaler so that BMC.MAC serializes to a human-readable colon-separated string in JSON instead of a base64-encoded byte array.

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
  • RLA - RLA 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

@jw-nvidia jw-nvidia requested a review from a team as a code owner April 9, 2026 20:20
@copy-pr-bot
Copy link
Copy Markdown

copy-pr-bot bot commented Apr 9, 2026

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@jw-nvidia jw-nvidia changed the title feat: add wrapper for net.HardwareAddr with JSON text marshaling feat: Add wrapper for net.HardwareAddr with JSON text marshaling Apr 9, 2026
@jw-nvidia jw-nvidia force-pushed the feat/mac_addr_json branch from abca6ec to ef8419d Compare April 9, 2026 20:42
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 9, 2026

Summary by CodeRabbit

  • Refactor
    • Enhanced MAC address handling across the system with improved serialization and deserialization capabilities for consistent and reliable data transformation in network device processing and component management.
  • Tests
    • Updated test fixtures and assertions to reflect the new MAC address structure.

Walkthrough

Adds an exported bmc.MACAddress wrapper around net.HardwareAddr with text marshal/unmarshal, changes BMC.MAC fields to use this type, and updates converters (DAO, protobuf, client), domain types, and all affected tests to construct and handle MACs via the new wrapper.

Changes

Cohort / File(s) Summary
MAC Address Type & BMC struct
rla/pkg/inventoryobjects/bmc/macaddr.go, rla/pkg/inventoryobjects/bmc/bmc.go
Adds bmc.MACAddress (wraps net.HardwareAddr) with MarshalText/UnmarshalText; changes BMC.MAC field type to MACAddress and updates constructor to wrap parsed MACs.
Types surface
rla/pkg/types/types.go
Updates public BMC type to use bmc.MACAddress for the MAC field.
Client conversion helpers
rla/pkg/client/convert.go
Adjusts proto↔domain conversion: parse MACs into net.HardwareAddr, wrap as bmc.MACAddress{HardwareAddr: addr} when present; update serialization checks to inspect MAC.HardwareAddr.
DAO converters & tests
rla/internal/converter/dao/converter.go, rla/internal/converter/dao/converter_test.go
Wraps parsed MACs in bmc.MACAddress when populating BMCs; test fixtures and expectations updated accordingly (including invalid/empty MAC cases).
Protobuf converters & tests
rla/internal/converter/protobuf/converter.go, rla/internal/converter/protobuf/converter_test.go
Rename local BMC var, assign parsed IP/MAC into new local, wrap MAC as MACAddress{HardwareAddr: ...}; tests updated to expect wrapped MAC values (empty MACs become empty MACAddress{}).
Domain & service tests
rla/pkg/inventoryobjects/bmc/bmc_test.go, rla/pkg/inventoryobjects/component/component_test.go, rla/internal/service/component_api_test.go
Test fixtures updated to construct BMC.MAC using bmc.MACAddress{HardwareAddr: ...}; assertions and test logic unchanged.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the primary change: introducing a net.HardwareAddr wrapper (MACAddress) to enable JSON marshaling of BMC MAC addresses as human-readable strings.
Description check ✅ Passed The description is well-aligned with the changeset, clearly explaining the MACAddress wrapper implementation, TextMarshaler/TextUnmarshaler interface adoption, and JSON serialization behavior change.

✏️ 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.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

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 the current code and only fix it if needed.

Inline comments:
In `@rla/pkg/inventoryobjects/bmc/bmc.go`:
- Line 31: Fix two issues caused by the MACAddress wrapper: replace assignments
like `bmc.MAC, _ = net.ParseMAC(mac)` with the same pattern used in `bmc.New` —
call `net.ParseMAC(mac)`, handle the error, and assign the parsed value as
`MACAddress{HardwareAddr: parsed}` to the `bmc.MAC` field; and replace struct
nil checks like `if b.MAC != nil` with a check of the embedded hardware address
(e.g., `if b.MAC.HardwareAddr != nil` or `len(b.MAC.HardwareAddr) > 0`) so you
test the actual pointer/length rather than the struct itself.
🪄 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: Pro

Run ID: 8d743cab-cf76-4527-9aa2-f599f1fb32d7

📥 Commits

Reviewing files that changed from the base of the PR and between 14262c0 and ef8419d.

📒 Files selected for processing (9)
  • rla/internal/converter/dao/converter.go
  • rla/internal/converter/dao/converter_test.go
  • rla/internal/converter/protobuf/converter.go
  • rla/internal/converter/protobuf/converter_test.go
  • rla/internal/service/component_api_test.go
  • rla/pkg/inventoryobjects/bmc/bmc.go
  • rla/pkg/inventoryobjects/bmc/bmc_test.go
  • rla/pkg/inventoryobjects/bmc/macaddr.go
  • rla/pkg/inventoryobjects/component/component_test.go

@thossain-nv thossain-nv changed the title feat: Add wrapper for net.HardwareAddr with JSON text marshaling feat: Add net.HardwareAddr wrapper for BMC MAC JSON marshaling Apr 9, 2026
…haling

Introduce MACAddress in the bmc package, wrapping net.HardwareAddr and
implementing encoding.TextMarshaler/TextUnmarshaler so that BMC.MAC
serializes to a human-readable colon-separated string in JSON instead
of a base64-encoded byte array.

Signed-off-by: Jin Wang <jinwan@nvidia.com>
@jw-nvidia jw-nvidia force-pushed the feat/mac_addr_json branch from ef8419d to 664e12b Compare April 9, 2026 22:28
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
rla/pkg/types/types.go (1)

57-57: Avoid leaking inventoryobjects/bmc into the shared types API surface.

Line 57 couples rla/pkg/types to rla/pkg/inventoryobjects/bmc, which increases cross-package dependency for consumers of types.BMC. Consider introducing a types.MACAddress type (or alias) in rla/pkg/types and keep package-specific mapping in converters.

As per coding guidelines, **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@rla/pkg/types/types.go` at line 57, types.BMC currently exposes the concrete
type bmc.MACAddress (field MAC) which leaks the inventoryobjects/bmc package
into the shared API; change this by declaring a local types.MACAddress (type
alias or new named type) in rla/pkg/types and update the BMC struct to use
types.MACAddress for the MAC field, then adjust any converter functions/methods
(the mapping code that converts between inventoryobjects/bmc and types.BMC) to
translate between bmc.MACAddress and the new types.MACAddress so the inventory
package is no longer imported by rla/pkg/types.
rla/pkg/client/convert.go (1)

127-130: This behavior is intentional and consistent with established converter patterns; documentation is optional.

Invalid MAC addresses are silently ignored across the converter layer (rla/internal/converter/dao/converter.go, rla/internal/converter/protobuf/converter.go) by design, as validated by explicit test cases ("invalid MAC address" in both test files). The internal converters do not document this behavior—it defaults to an unset MAC (zero value), which is a sensible fallback when parsing fails.

If consistency or clarity is desired, a brief comment explaining the intentional behavior would be beneficial, particularly since this function lacks a dedicated test file unlike its counterparts in the internal converter layer.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@rla/pkg/client/convert.go` around lines 127 - 130, Add a brief inline comment
in rla/pkg/client/convert.go immediately above the net.ParseMAC call (the block
that sets bmc.MAC = bmcobj.MACAddress{HardwareAddr: addr}) stating that invalid
MAC addresses are intentionally ignored and left as the zero-value, mirroring
behavior in rla/internal/converter/dao/converter.go and
rla/internal/converter/protobuf/converter.go; optionally add a small unit test
for this converter to assert that an invalid MAC leaves bmc.MAC unset if you
want parity with the internal converters.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@rla/pkg/client/convert.go`:
- Around line 127-130: Add a brief inline comment in rla/pkg/client/convert.go
immediately above the net.ParseMAC call (the block that sets bmc.MAC =
bmcobj.MACAddress{HardwareAddr: addr}) stating that invalid MAC addresses are
intentionally ignored and left as the zero-value, mirroring behavior in
rla/internal/converter/dao/converter.go and
rla/internal/converter/protobuf/converter.go; optionally add a small unit test
for this converter to assert that an invalid MAC leaves bmc.MAC unset if you
want parity with the internal converters.

In `@rla/pkg/types/types.go`:
- Line 57: types.BMC currently exposes the concrete type bmc.MACAddress (field
MAC) which leaks the inventoryobjects/bmc package into the shared API; change
this by declaring a local types.MACAddress (type alias or new named type) in
rla/pkg/types and update the BMC struct to use types.MACAddress for the MAC
field, then adjust any converter functions/methods (the mapping code that
converts between inventoryobjects/bmc and types.BMC) to translate between
bmc.MACAddress and the new types.MACAddress so the inventory package is no
longer imported by rla/pkg/types.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 6dae7d3a-ddc5-422d-811b-a53b489f5d1f

📥 Commits

Reviewing files that changed from the base of the PR and between ef8419d and 664e12b.

📒 Files selected for processing (11)
  • rla/internal/converter/dao/converter.go
  • rla/internal/converter/dao/converter_test.go
  • rla/internal/converter/protobuf/converter.go
  • rla/internal/converter/protobuf/converter_test.go
  • rla/internal/service/component_api_test.go
  • rla/pkg/client/convert.go
  • rla/pkg/inventoryobjects/bmc/bmc.go
  • rla/pkg/inventoryobjects/bmc/bmc_test.go
  • rla/pkg/inventoryobjects/bmc/macaddr.go
  • rla/pkg/inventoryobjects/component/component_test.go
  • rla/pkg/types/types.go
✅ Files skipped from review due to trivial changes (5)
  • rla/internal/converter/dao/converter.go
  • rla/internal/service/component_api_test.go
  • rla/pkg/inventoryobjects/component/component_test.go
  • rla/pkg/inventoryobjects/bmc/bmc_test.go
  • rla/pkg/inventoryobjects/bmc/macaddr.go
🚧 Files skipped from review as they are similar to previous changes (4)
  • rla/internal/converter/dao/converter_test.go
  • rla/internal/converter/protobuf/converter.go
  • rla/pkg/inventoryobjects/bmc/bmc.go
  • rla/internal/converter/protobuf/converter_test.go

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.

1 participant