Skip to content

fix(rest): use lowercase phone_home 'post' key for cloud-init YAML property - #4670

Open
SnobbishFish40 wants to merge 3 commits into
NVIDIA:mainfrom
SnobbishFish40:relliott/correctAutoinstallUserdataPOST
Open

fix(rest): use lowercase phone_home 'post' key for cloud-init YAML property#4670
SnobbishFish40 wants to merge 3 commits into
NVIDIA:mainfrom
SnobbishFish40:relliott/correctAutoinstallUserdataPOST

Conversation

@SnobbishFish40

@SnobbishFish40 SnobbishFish40 commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

When phone-home is enabled for an Ubuntu autoinstall OS, NICo injects the callback configuration into autoinstall.user-data using the uppercase property POST. Ubuntu Subsequently validates this nested cloud-config and rejects POST because the supported property is lowercase post. Installation stops at a fatal-error prompt and the instance remains Provisioning indefinitely.

This regression is exposed by infra-controller PR #3859, which moved NICo's existing phone-home block from the cloud-config document root into the target OS's nested autoinstall.user-data. Uppercase POST had previously worked accidentally at the document root as cloudinit falls back to "post: all" (post_list = ph_cfg.get("post", "all")). Moving it into the strictly validated nested mapping made it crash.

Related issues

Ref: 6569456

Type of Change

  • Fix - Bug fixes

Breaking Changes

  • This PR contains breaking changes

Testing

No testing was possible without dev environment.

@SnobbishFish40
SnobbishFish40 requested a review from a team as a code owner August 6, 2026 14:39
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Summary by CodeRabbit

  • Bug Fixes
    • Updated the site phone-home request method to use the correct lowercase format: post.
    • Improved validation of phone-home configuration, including URL formats, supported post keys, retry settings, and rejection of unknown options.

Walkthrough

The phone-home method constant now uses "post". A cloud-init phone-home schema was added. A test validates inserted phone-home configuration against the schema.

Changes

Phone-home configuration

Layer / File(s) Summary
Update phone-home method constant
rest-api/api/pkg/api/model/util/util.go
Changes SitePhoneHomePost from "POST" to "post".
Validate phone-home configuration
rest-api/api/pkg/api/model/util/testdata/cloud-init-phone-home.schema.json, rest-api/api/pkg/api/model/util/util_test.go, rest-api/go.mod
Adds the cloud-init phone_home schema and validates inserted configuration with the JSON Schema v6 package.

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

🚥 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 and concisely describes the main change: using lowercase post for the cloud-init phone_home property.
Description check ✅ Passed The description explains the validation failure, the fix, the triggering context, and the added test coverage.
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

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

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

19-19: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick win

Add a literal contract assertion for the lowercase key.

The constant now matches the Ubuntu autoinstall requirement. However, rest-api/api/pkg/api/model/util/util_test.go looks up the generated field through SitePhoneHomePost, so the test does not independently prove that the serialized configuration contains post rather than POST. Assert the literal key and verify that POST is absent.

🤖 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/model/util/util.go` at line 19, Update the test using
SitePhoneHomePost to assert that the serialized configuration contains the
literal lowercase key "post", and also verify that the uppercase key "POST" is
absent. Keep the existing generated-field validation while making the assertion
independent of the constant’s value.
🤖 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/api/pkg/api/model/util/util.go`:
- Line 19: Update the test using SitePhoneHomePost to assert that the serialized
configuration contains the literal lowercase key "post", and also verify that
the uppercase key "POST" is absent. Keep the existing generated-field validation
while making the assertion independent of the constant’s value.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: d7ddef6d-85f2-4556-a47b-8c3983c7255f

📥 Commits

Reviewing files that changed from the base of the PR and between 4f0e11f and 6f55032.

📒 Files selected for processing (1)
  • rest-api/api/pkg/api/model/util/util.go

@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 14:42:22 UTC | Commit: 6f55032

@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
@SnobbishFish40 SnobbishFish40 self-assigned this Aug 6, 2026
@thossain-nv thossain-nv changed the title Change POST to post fix(rest): Revise HTTP method specification for phone home configuration Aug 6, 2026
@pbreton pbreton changed the title fix(rest): Revise HTTP method specification for phone home configuration fix(rest): use lowercase phone_home 'post' key for cloud-init YAML property Aug 6, 2026
Signed-off-by: Patrice Breton <pbreton@nvidia.com>

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

Please add SnobbishFish40#1 (which I should have done in the first place 😀).

…n-test

test(rest-api): validate generated phone-home cloud-init schema
@copy-pr-bot

copy-pr-bot Bot commented Aug 6, 2026

Copy link
Copy Markdown

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.

@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/api/pkg/api/model/util/util_test.go`:
- Around line 15-34: Move the schema-validation logic from
TestInsertedPhoneHomeMatchesCloudInitSchema into a named t.Run case within
TestInsertPhoneHomeIntoUserData. Preserve the existing YAML setup,
InsertPhoneHomeIntoUserData call, cloud-init schema compilation, and validation
assertions, then remove the separate top-level test function.
🪄 Autofix

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: de2e5a66-da28-43ab-997e-3a051ce63b89

📥 Commits

Reviewing files that changed from the base of the PR and between 6f55032 and 2b58019.

📒 Files selected for processing (3)
  • rest-api/api/pkg/api/model/util/testdata/cloud-init-phone-home.schema.json
  • rest-api/api/pkg/api/model/util/util_test.go
  • rest-api/go.mod

Comment on lines +15 to +34
func TestInsertedPhoneHomeMatchesCloudInitSchema(t *testing.T) {
documentRoot := unmarshalDocumentRoot(t, `autoinstall:
version: 1
`)
require.NoError(t, InsertPhoneHomeIntoUserData(documentRoot, "http://169.254.169.254/phone_home"))

autoinstallNode := mappingNodeValue(documentRoot, "autoinstall")
require.NotNil(t, autoinstallNode)
targetUserDataNode := mappingNodeValue(autoinstallNode, "user-data")
require.NotNil(t, targetUserDataNode)

var targetUserData any
require.NoError(t, targetUserDataNode.Decode(&targetUserData))

compiler := jsonschema.NewCompiler()
compiler.AssertFormat()
schema, err := compiler.Compile("testdata/cloud-init-phone-home.schema.json")
require.NoError(t, err)
require.NoError(t, schema.Validate(targetUserData))
}

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.

📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Move this scenario into the existing table-driven test.

TestInsertedPhoneHomeMatchesCloudInitSchema adds a second top-level test function. Add this validation as a named t.Run case in TestInsertPhoneHomeIntoUserData instead.

As per coding guidelines, rest-api/**/*_test.go requires one top-level Test... function and named table-driven t.Run subtests.

🤖 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/model/util/util_test.go` around lines 15 - 34, Move the
schema-validation logic from TestInsertedPhoneHomeMatchesCloudInitSchema into a
named t.Run case within TestInsertPhoneHomeIntoUserData. Preserve the existing
YAML setup, InsertPhoneHomeIntoUserData call, cloud-init schema compilation, and
validation assertions, then remove the separate top-level test function.

Source: Coding guidelines

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

LGTM.

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.

3 participants