Skip to content

cloud-init: T9172: add userdata command regression tests - #116

Open
jeleel-muibi wants to merge 2 commits into
vyos:rollingfrom
jeleel-muibi:t9172-cloud-init-userdata-tests
Open

cloud-init: T9172: add userdata command regression tests#116
jeleel-muibi wants to merge 2 commits into
vyos:rollingfrom
jeleel-muibi:t9172-cloud-init-userdata-tests

Conversation

@jeleel-muibi

Copy link
Copy Markdown

Proposed Commit Message

cloud-init: T9172: add userdata command regression tests

Add focused regression coverage for the VyOS-specific
vyos_config_commands handler. Exercise template discovery, supported
set/delete parsing, ordinary, multi, and nested tag-node updates, both
delete paths, and malformed-command skipping.

Use temporary template trees and a mocked ConfigTree interface so the
tests run without a VyOS image or installed template hierarchy.

Additional Context

Related task: T9172

This is a test-only change. It does not alter cloud-init runtime behavior,
dependencies, or configuration. The cases include the trailing multi-node
metadata behavior fixed in T3735 and the nested
tag-node preservation behavior fixed in T4895.

Test Steps

Validated with Python 3.10.20 and the repository-pinned tool versions:

python -m pytest -q tests/unittests/config/test_cc_vyos_userdata.py
9 passed

python -m black --check tests/unittests/config/test_cc_vyos_userdata.py
1 file would be left unchanged

python -m isort --check-only --diff tests/unittests/config/test_cc_vyos_userdata.py
python -m flake8 tests/unittests/config/test_cc_vyos_userdata.py
python -m mypy tests/unittests/config/test_cc_vyos_userdata.py
python -m pylint tests/unittests/config/test_cc_vyos_userdata.py
All passed; pylint rated the file 10.00/10.

python -m pytest -q tests/unittests \
  -k 'not test_get_script_folder_per_boot and not test_get_script_folder_per_instance and not test_get_script_folder_per_once'
3228 passed, 10 skipped, 3 deselected

The three host-dependent tests were deselected because they read
/etc/cloud/cloud.cfg.d/99-installer.cfg, which is not readable in the local
environment. An unfiltered run has only those three PermissionError
failures; none involves this test module.

Checklist:

  • My code follows the process laid out in the documentation
  • I have updated or added any unit tests accordingly
  • I have updated or added any documentation accordingly (not applicable: test-only change)

Add focused regression coverage for the VyOS-specific
vyos_config_commands handler. Exercise template discovery, supported
set/delete parsing, ordinary, multi, and nested tag-node updates, both
delete paths, and malformed-command skipping.

Use temporary template trees and a mocked ConfigTree interface so the
tests run without a VyOS image or installed template hierarchy.
@coderabbitai

coderabbitai Bot commented Aug 8, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited), Organization UI (inherited)

Review profile: CHILL

Plan: Pro Plus

Run ID: 1fffd95b-8101-4452-a0e7-f7847f63ec4d

📥 Commits

Reviewing files that changed from the base of the PR and between dab383a and fb81132.

📒 Files selected for processing (1)
  • tests/unittests/config/test_cc_vyos_userdata.py
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • ansible/ansible (manual)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/unittests/config/test_cc_vyos_userdata.py
📜 Recent review details
⏰ Context from checks skipped due to timeout. (2)
  • GitHub Check: Mergify Merge Protections
  • GitHub Check: Summary
⚠️ CI failures not shown inline (1)

GitHub Check: Mergify Merge Protections: 1 applicable rule, 0 validating requirements

Conclusion: failure

View job details

# Merge Protections
🔴 **1 of 1 protections blocking** · waiting on 🙋 you
| | Protection | Waiting on |
|:--:|:--|:--:|
| 🔴 | **invalid-task-id label must be absent to merge** | 🙋 you |
## 🔴 invalid-task-id label must be absent to merge
**Waiting for**
- [ ] `label != invalid-task-id`
<details><summary>This rule is failing.</summary>
Block merge while the invalid-task-id label is present. Set by the per-repo product T-ID rule (product repos only); dormant where the label is never applied.
- [ ] `label != invalid-task-id`
</details>
🧰 Additional context used
🔍 Remote MCP vyos.dev

Relevant review context

  • T9172 — “cloud-init: add regression coverage for vyos_config_commands” is In progress with Low priority. Its acceptance criteria directly match this PR: unit tests only; mocked ConfigTree and template discovery; set/delete behavior; multi/tag-node handling; and malformed-command skipping. It also requires both the focused tests and pytest tests/unittests to pass.
  • T4895 — “Tag nodes are overwritten when configured by Cloud-Init from User-Data” documents that repeated nested tag-node values were overwritten because replace=False was applied only to multi-nodes. The nested tag-node preservation test is therefore directly relevant regression coverage.
  • T3735 — “Configuration with multiple network addresses of firewall network-group via colud-init fails” records that multi-node detection failed when template metadata followed multi:; the original matcher required exactly ^multi:$. The trailing-metadata test covers this historical failure mode.
  • T8185 — “config.boot.default path inconsistency between cloud-init and build system causes flavor-defined configs to be ignored” identifies distinct default-config paths: /usr/share/vyos/config.boot.default and /opt/vyatta/etc/config.boot.default. Template/path fixtures should remain self-contained and avoid assuming these paths are interchangeable.

📝 Walkthrough

Summary by CodeRabbit

  • Tests
    • Added comprehensive coverage for VyOS userdata handling.
    • Verified template discovery and multi-node detection.
    • Added tests for parsing valid and malformed commands.
    • Covered setting, appending, preserving nested values, and deleting configuration nodes.
    • Confirmed valid commands are processed while malformed input is skipped.

Walkthrough

Changes

VyOS userdata tests

Layer / File(s) Summary
Discovery and command parsing
tests/unittests/config/test_cc_vyos_userdata.py
Tests template path discovery, multi-node detection, parsing of set and delete commands, and rejection of malformed input.
Command application and deletion
tests/unittests/config/test_cc_vyos_userdata.py
Tests ordinary-node replacement, multi-node value appending, nested tag-node preservation, and deletion by value or path.
Command routing
tests/unittests/config/test_cc_vyos_userdata.py
Tests application of valid commands and skipping of malformed commands.
🚥 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 identifies the cloud-init component, task, and primary change: adding VyOS userdata command regression tests.
Description check ✅ Passed The description directly explains the VyOS regression tests, covered cases, test-only scope, and validation results.
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 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
✨ Simplify code
  • Create PR with simplified code

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.

@mergify mergify Bot added the rolling label Aug 8, 2026
@jeleel-muibi
jeleel-muibi marked this pull request as ready for review August 8, 2026 11:06
@sever-sever
sever-sever requested review from c-po, dmbaturin and zdc and a lite review from Copilot August 10, 2026 15:21

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds a new unit test module to provide regression coverage for the VyOS-specific cloudinit.config.cc_vyos_userdata handler logic (template-node discovery, command parsing, and command application) without requiring a VyOS runtime environment.

Changes:

  • Introduces tests/unittests/config/test_cc_vyos_userdata.py with focused unit tests for tag-node and multi-node template discovery.
  • Adds coverage for string_to_command, apply_command_set, apply_command_delete, and apply_commands, including malformed-command skipping.
Suppressed comments (1)

tests/unittests/config/test_cc_vyos_userdata.py:186

  • test_apply_commands_routes_valid_commands_and_skips_malformed currently only asserts the delete-with-value path (delete_value). Since apply_commands also needs to support delete-by-path (no value), it would be good to include a delete … command without a value here and assert that config.delete(...) is invoked.
        cc_vyos_userdata.apply_commands(
            config,
            [
                "set system host-name 'edge-a'",
                "show version",
                "delete system name-server '192.0.2.53'",
            ],
        )

        config.set.assert_called_once_with(
            ["system", "host-name"], "edge-a", replace=True
        )
        config.delete_value.assert_called_once_with(
            ["system", "name-server"], "192.0.2.53"
        )
        config.delete.assert_not_called()

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread tests/unittests/config/test_cc_vyos_userdata.py Outdated
Comment thread tests/unittests/config/test_cc_vyos_userdata.py
@jeleel-muibi
jeleel-muibi force-pushed the t9172-cloud-init-userdata-tests branch from fb81132 to b5e7b60 Compare August 11, 2026 14:58
@mergify mergify Bot removed the invalid-task-id label Aug 11, 2026
@sever-sever
sever-sever self-requested a review August 13, 2026 16:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

2 participants