Skip to content

Move BMCSettings mock redfish_local method into go mock server#790

Open
nagadeesh-nagaraja wants to merge 6 commits intomainfrom
moveToMock
Open

Move BMCSettings mock redfish_local method into go mock server#790
nagadeesh-nagaraja wants to merge 6 commits intomainfrom
moveToMock

Conversation

@nagadeesh-nagaraja
Copy link
Copy Markdown
Contributor

@nagadeesh-nagaraja nagadeesh-nagaraja commented Apr 8, 2026

Proposed Changes

Move mocked unit test methods into go mock server

Fixes #789

Summary by CodeRabbit

  • New Features

    • BMC attribute settings can now be applied immediately or deferred as pending changes.
    • Added comprehensive BMC attribute registry for configuration management and validation.
  • Bug Fixes

    • Improved BMC reset operations to correctly apply pending attribute settings.
  • Chores

    • Enhanced test infrastructure with improved mock server integration.

@nagadeesh-nagaraja nagadeesh-nagaraja self-assigned this Apr 8, 2026
@nagadeesh-nagaraja nagadeesh-nagaraja requested a review from a team as a code owner April 8, 2026 14:18
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 8, 2026

Warning

Rate limit exceeded

@nagadeesh-nagaraja has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 28 minutes and 28 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 28 minutes and 28 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3d7dda13-dc4b-4c90-bbfc-cbbf941d7430

📥 Commits

Reviewing files that changed from the base of the PR and between ae7a36b and 15c67eb.

📒 Files selected for processing (6)
  • bmc/mock/server/data/Registries/index.json
  • bmc/mock/server/server.go
  • bmc/redfish_local.go
  • internal/controller/biossettings_controller_test.go
  • internal/controller/bmcsettings_controller_test.go
  • internal/controller/bmcsettingsset_controller_test.go
📝 Walkthrough

Walkthrough

This PR adds BMC Settings support to the Redfish mock server. It introduces a new BMC Settings endpoint with a corresponding attribute registry, implements runtime attribute loading and application logic, and refactors existing BMC reset/settings workflows to use HTTP PATCH requests instead of direct in-memory mutations.

Changes

Cohort / File(s) Summary
BMC Settings JSON Resources
bmc/mock/server/data/Managers/BMC/Settings/index.json, bmc/mock/server/data/Managers/BMC/index.json
Added new BMC Settings endpoint definition and extended Manager resource with Attributes object and @Redfish.Settings reference pointing to the new Settings resource.
BMC Attribute Registry
bmc/mock/server/data/Registries/BMCAttributeRegistry/index.json, bmc/mock/server/data/Registries/index.json
Created new BMC Attribute Registry with three attribute entries (abc, fooreboot, composite) and registered it in the Registries collection.
Mock Server Core Logic
bmc/mock/server/server.go, bmc/redfish_local.go
Implemented runtime attribute loading from registries, added BMC settings application helpers (applyBMCSettings, applyPendingBMCSettings), refactored BMC reset to clear lock and apply pending settings, and updated client methods to use HTTP PATCH against Settings endpoint instead of in-memory mutations.
Test Updates
internal/controller/biossettings_controller_test.go, internal/controller/bmcsettings_controller_test.go, internal/controller/bmcsettingsset_controller_test.go, internal/controller/helper.go, internal/controller/suite_test.go
Migrated test teardown to use defaultMockServer.ResetBMCSettings(), updated mock server IP configuration, fixed UUID parameter in BMC reset call, and added package-level mock server instance for test harness.

Sequence Diagram

sequenceDiagram
    participant Client as Test Client
    participant MockSrv as Mock Server
    participant BMCMgr as BMC Manager Resource
    participant BMCSet as BMC Settings Resource

    Client->>MockSrv: PATCH /Managers/BMC/Settings (Attributes + SettingsApplyTime=Immediate)
    MockSrv->>MockSrv: applyBMCSettings(pending update)
    activate MockSrv
    MockSrv->>MockSrv: Load registry, filter noRebootBMCSettings
    MockSrv->>MockSrv: Check if immediate attrs in noRebootBMCSettings
    MockSrv->>BMCMgr: Apply immediate attrs to current Manager.Attributes
    MockSrv->>MockSrv: Remove immediate attrs from pending update
    MockSrv->>BMCSet: Store remaining attrs in Settings.Attributes
    deactivate MockSrv
    MockSrv-->>Client: 204 No Content

    Note over Client,BMCSet: Later: BMC Reset Triggered

    Client->>MockSrv: Reset BMC (GracefulRestart)
    MockSrv->>MockSrv: doBMCReset()
    activate MockSrv
    MockSrv->>MockSrv: setLocked(false)
    MockSrv->>MockSrv: applyPendingBMCSettings()
    MockSrv->>BMCSet: Load pending Settings.Attributes
    MockSrv->>BMCMgr: Copy pending to current Manager.Attributes
    MockSrv->>BMCSet: Clear Settings.Attributes
    deactivate MockSrv
    MockSrv-->>Client: Reset complete
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Possibly related issues

Possibly related PRs

Suggested reviewers

  • afritzler
  • xkonni
  • Nuckal777
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

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.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main objective of moving BMC Settings mock methods from redfish_local into the Go mock server, which aligns with the actual changes.
Description check ✅ Passed The description covers the main changes (moving mocked unit test methods into Go mock server) and references the linked issue, though it could be more detailed about the specific scope.
Linked Issues check ✅ Passed The PR successfully implements the objective from issue #789 by relocating BMCSettings mock functionality from redfish_local into the Go mock server with comprehensive supporting changes across test files.
Out of Scope Changes check ✅ Passed All changes are directly related to the objective of moving BMC Settings mocks to the server; test file updates and refactoring support this core migration without introducing unrelated modifications.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch moveToMock

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Copy link
Copy Markdown
Contributor

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

Caution

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

⚠️ Outside diff range comments (1)
bmc/mock/server/data/Registries/index.json (1)

5-15: ⚠️ Potential issue | 🟡 Minor

Update Members@odata.count to reflect the actual member count.

The Members@odata.count field is 1 but there are now 3 members in the array. This inconsistency could cause issues if Redfish clients rely on the count for iteration or validation.

Proposed fix
-    "Members@odata.count": 1,
+    "Members@odata.count": 3,
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@bmc/mock/server/data/Registries/index.json` around lines 5 - 15, The
Members@odata.count value is incorrect (currently 1) and must match the actual
number of entries in the Members array; update the "Members@odata.count" field
in Registries/index.json to 3 so it reflects the three "@odata.id" entries in
"Members" (e.g., "/redfish/v1/Registries/Base.1.5.0",
"/redfish/v1/Registries/BiosAttributeRegistry.v1_0_0",
"/redfish/v1/Registries/BMCAttributeRegistry").
🧹 Nitpick comments (1)
bmc/redfish_kube.go (1)

238-246: Resolve the settings URI from the selected manager instead of hardcoding it.

Both methods ignore the requested BMC UUID and assume the settings resource is always /redfish/v1/Managers/BMC/Settings. The local implementation in bmc/redfish_local.go already follows the manager-advertised @Redfish.Settings.SettingsObject; reusing that pattern here would also let you send the same @Redfish.SettingsApplyTime payload.

Also applies to: 295-300

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

In `@bmc/redfish_kube.go` around lines 238 - 246, The patch hardcodes
"/redfish/v1/Managers/BMC/Settings" in SetBMCAttributesImmediately (in
RedfishKubeBMC) instead of resolving the manager's advertised settings URI;
update this method (and the corresponding apply/settings method around the
295-300 region) to locate the selected manager by the requested BMC UUID, read
its `@Redfish.Settings.SettingsObject` (the pattern used in the local
implementation in bmc/redfish_local.go), use that SettingsObject URI as the
PATCH target, and support sending the same `@Redfish.SettingsApplyTime` payload as
the local implementation does.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@bmc/mock/server/server.go`:
- Around line 56-57: The immediate-apply whitelist variable noRebootBMCSettings
is missing the "composite" attribute listed as ResetRequired:false in the BMC
attribute registry; update the slice to include "composite" (e.g., var
noRebootBMCSettings = []string{"abc", "composite"}) so PATCHes for composite are
applied immediately; optionally note for future work to derive this list
programmatically from the BMCAttributeRegistry index to avoid drift.
- Around line 459-473: The reset path (doBMCReset) flips the resource lock via
setLocked but applyPendingBMCSettings/applyBMCSettings never checks that lock,
allowing PATCHes during the reset sleep to be accepted and applied; modify
applyPendingBMCSettings and the PATCH handling code to check the same lock state
(e.g., call an isLocked(bmcPath) helper or inspect the overrides[bmcPath] locked
flag) and return/reject with an error when the resource is locked, so any
incoming PATCHes while doBMCReset has setLocked(..., true) are refused rather
than queued/applied.

In `@bmc/redfish_kube.go`:
- Around line 244-250: The PATCH response from c.Patch in bmc/redfish_kube.go
(the resp returned by c.Patch("/redfish/v1/Managers/BMC/Settings", payload)) is
not being closed; after checking err != nil add a defer resp.Body.Close() to
ensure the response body is closed and connection-pool resources are freed
(place the defer immediately after the nil-error check in the same block where
resp is available).

---

Outside diff comments:
In `@bmc/mock/server/data/Registries/index.json`:
- Around line 5-15: The Members@odata.count value is incorrect (currently 1) and
must match the actual number of entries in the Members array; update the
"Members@odata.count" field in Registries/index.json to 3 so it reflects the
three "@odata.id" entries in "Members" (e.g.,
"/redfish/v1/Registries/Base.1.5.0",
"/redfish/v1/Registries/BiosAttributeRegistry.v1_0_0",
"/redfish/v1/Registries/BMCAttributeRegistry").

---

Nitpick comments:
In `@bmc/redfish_kube.go`:
- Around line 238-246: The patch hardcodes "/redfish/v1/Managers/BMC/Settings"
in SetBMCAttributesImmediately (in RedfishKubeBMC) instead of resolving the
manager's advertised settings URI; update this method (and the corresponding
apply/settings method around the 295-300 region) to locate the selected manager
by the requested BMC UUID, read its `@Redfish.Settings.SettingsObject` (the
pattern used in the local implementation in bmc/redfish_local.go), use that
SettingsObject URI as the PATCH target, and support sending the same
`@Redfish.SettingsApplyTime` payload as the local implementation does.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: fcf2b889-3a5e-4ded-a4a0-9f63d2f35f36

📥 Commits

Reviewing files that changed from the base of the PR and between 1fb6e38 and 7c319f4.

📒 Files selected for processing (13)
  • bmc/mock/server/data/Managers/BMC/Settings/index.json
  • bmc/mock/server/data/Managers/BMC/index.json
  • bmc/mock/server/data/Registries/BMCAttributeRegistry/index.json
  • bmc/mock/server/data/Registries/index.json
  • bmc/mock/server/server.go
  • bmc/mockup.go
  • bmc/redfish_kube.go
  • bmc/redfish_local.go
  • internal/controller/biossettings_controller_test.go
  • internal/controller/bmcsettings_controller_test.go
  • internal/controller/bmcsettingsset_controller_test.go
  • internal/controller/helper.go
  • internal/controller/suite_test.go
💤 Files with no reviewable changes (1)
  • bmc/mockup.go

Comment thread bmc/mock/server/server.go Outdated
Comment thread bmc/mock/server/server.go
Comment thread bmc/redfish_kube.go Outdated
Comment thread bmc/mock/server/server.go Outdated
@afritzler afritzler added the enhancement New feature or request label Apr 8, 2026
Copy link
Copy Markdown
Contributor

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

♻️ Duplicate comments (1)
bmc/mock/server/server.go (1)

536-540: ⚠️ Potential issue | 🟠 Major

Reject settings PATCHes while the BMC is reset-locked.

Returning nil here still lets handlePatch persist the body to /Managers/BMC/Settings and answer 204, so writes made during the simulated offline window are queued and then applied by applyPendingBMCSettings(). The lock is therefore not actually blocking mutations.

🔒 Minimal fix
 	// If the BMC is mid-reset (locked), leave the immediate settings in attrs
-	// so they are written to the pending Settings resource and picked up by
-	// applyPendingBMCSettings once the reset completes.
+	// reject the PATCH so writes are not accepted while the BMC is offline.
 	if s.isLocked(bmcBase) {
-		return nil
+		return errLocked
 	}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@bmc/mock/server/server.go` around lines 536 - 540, The branch that checks
s.isLocked(bmcBase) currently returns nil which allows handlePatch to continue
and persist the PATCH body; change it to reject the request immediately when the
BMC is reset-locked by returning an error/HTTP 423-style response from the same
check so handlePatch does not write to /Managers/BMC/Settings or return 204;
update the code around s.isLocked(bmcBase) to short-circuit with an appropriate
error value (so pending writes are not queued) and ensure
applyPendingBMCSettings remains the mechanism that applies queued changes after
unlock.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@bmc/mock/server/server.go`:
- Around line 56-85: The current loadNoRebootAttrs silently returns nil on
dataFS.ReadFile or json.Unmarshal errors causing silent behavior changes; update
loadNoRebootAttrs (used by init() to set noRebootSettings and
noRebootBMCSettings) to fail fast by panicking (or returning an error and making
init handle it) when ReadFile or Unmarshal fail, including the registryPath and
the underlying error in the panic/log message so the process exits with a clear
diagnostic instead of silently emptying the allowlist.
- Around line 623-642: The helper resetAttributesFromEmbeddedLocked currently
only replaces Attributes and can leave stale fields (like resourceLock) behind;
instead, read the embedded JSON via dataFS.ReadFile, unmarshal into a
map[string]any (as already done into defaults), and replace the entire in-memory
resource with that defaults map (i.e. assign overrides[filePath] = defaults)
rather than setting only current[attributesKey]; update usages of
loadResourceLocked/overrides accordingly so the full embedded resource (not just
Attributes) is restored in resetAttributesFromEmbeddedLocked.

---

Duplicate comments:
In `@bmc/mock/server/server.go`:
- Around line 536-540: The branch that checks s.isLocked(bmcBase) currently
returns nil which allows handlePatch to continue and persist the PATCH body;
change it to reject the request immediately when the BMC is reset-locked by
returning an error/HTTP 423-style response from the same check so handlePatch
does not write to /Managers/BMC/Settings or return 204; update the code around
s.isLocked(bmcBase) to short-circuit with an appropriate error value (so pending
writes are not queued) and ensure applyPendingBMCSettings remains the mechanism
that applies queued changes after unlock.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8adadbed-ab98-4f6f-a429-3b808fa2faa0

📥 Commits

Reviewing files that changed from the base of the PR and between 7c319f4 and ae7a36b.

📒 Files selected for processing (3)
  • bmc/mock/server/server.go
  • internal/controller/biossettings_controller_test.go
  • internal/controller/bmcsettings_controller_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/controller/biossettings_controller_test.go

Comment thread bmc/mock/server/server.go
Comment thread bmc/mock/server/server.go Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

Move BMCSettings test to mock server

3 participants