Skip to content

PR190 revive, vyos_conf match "enforced"#415

Open
omnom62 wants to merge 45 commits into
vyos:mainfrom
omnom62:pr190-revive
Open

PR190 revive, vyos_conf match "enforced"#415
omnom62 wants to merge 45 commits into
vyos:mainfrom
omnom62:pr190-revive

Conversation

@omnom62
Copy link
Copy Markdown
Contributor

@omnom62 omnom62 commented Apr 23, 2025

Change Summary

The change modifies vyso_config module to add additional match feature, 'smart', that allows to overwrite the existing configuration by the supplied in the Ansible playboo, i..e this is to enforce the configuration.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes)
  • Migration from an old Vyatta component to vyos-1x, please link to related PR inside obsoleted component
  • Other (please describe):

Related Task(s)

Related PR(s)

Component(s) name

Proposed changes

How to test

Test results

  • Sanity tests passed
  • Unit tests passed

Tested against VyOS versions:

  • 1.3.8
  • 1.4.3
  • 1.5q2

Checklist:

  • I have read the CONTRIBUTING document
  • I have linked this PR to one or more Phabricator Task(s)
  • I have run the ansible sanity and unit tests
  • My commit headlines contain a valid Task id
  • My change requires a change to the documentation
  • I have updated the documentation accordingly
  • I have added unit tests to cover my changes
  • I have added a file to changelogs/fragments to describe the changes

Summary by CodeRabbit

  • New Features

    • Added a "smart" match mode for vyos_config to provide smarter configuration diffing.
  • Documentation

    • Updated vyos_config documentation and examples to demonstrate match: smart.
  • Tests

    • Added unit tests validating smart diff behavior and the configuration diff utility.
  • Chores

    • Added changelog fragment, normalized repo config formatting, and refreshed contributor docs.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jul 22, 2025

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@omnom62
Copy link
Copy Markdown
Contributor Author

omnom62 commented Aug 4, 2025

I have read the CLA Document and I hereby sign the CLA

@omnom62 omnom62 marked this pull request as ready for review November 27, 2025 03:52
@omnom62 omnom62 requested a review from a team as a code owner November 27, 2025 03:52
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 12 changed files in this pull request and generated 2 comments.

Comment thread plugins/cliconf_utils/vyosconf.py Outdated
Comment thread docs/vyos.vyos.vyos_config_module.rst
Copilot AI review requested due to automatic review settings May 12, 2026 10:53
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 current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/unit/modules/network/vyos/test_vyos_config.py`:
- Around line 158-159: Move the mocked get_diff setup out of the test body and
into load_fixtures(): remove self.conn.get_diff =
MagicMock(return_value=response) from the test, and instead configure
self.conn.get_diff inside load_fixtures() to return the appropriate response
based on the fixture filename or inputs (use return_value or side_effect keyed
by filename), so execute_module(changed=True, sort=False) in the test uses the
fixture-provided mock; reference self.conn.get_diff, load_fixtures(),
execute_module, and the response object when making the change.
🪄 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 Plus

Run ID: 53e8ca50-d79f-45a1-9577-7a41bf34a6a5

📥 Commits

Reviewing files that changed from the base of the PR and between f3724d1 and 210a338.

📒 Files selected for processing (2)
  • plugins/cliconf/vyos.py
  • tests/unit/modules/network/vyos/test_vyos_config.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • plugins/cliconf/vyos.py

Comment thread tests/unit/modules/network/vyos/test_vyos_config.py
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 11 changed files in this pull request and generated 4 comments.

Comment thread plugins/cliconf/vyos.py Outdated
Comment on lines +276 to +280
if diff_match == "smart":
running_conf = VyosConf([line for line in running.splitlines() if line.strip()])
candidate_conf = VyosConf([line for line in candidate_commands if line.strip()])
diff["config_diff"] = running_conf.diff_commands_to(candidate_conf)
return diff
first_no_sibling_key = [target, leaf]

target = first_no_sibling_key[0]
target_key = first_no_sibling_key[1]
Comment thread docs/vyos.vyos.vyos_config_module.rst
Comment thread changelogs/fragments/vyos_config_smart.yml
Copilot AI review requested due to automatic review settings May 14, 2026 19:46
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 11 changed files in this pull request and generated 9 comments.

Comment thread plugins/modules/vyos_config.py
Comment on lines +57 to +75
target = self.config
first_no_sibling_key = None
for key in path:
if key not in target:
return self.config
if len(target[key]) <= 1:
if first_no_sibling_key is None:
first_no_sibling_key = [target, key]
else:
first_no_sibling_key = None
target = target[key]

if first_no_sibling_key is None:
first_no_sibling_key = [target, leaf]

target = first_no_sibling_key[0]
target_key = first_no_sibling_key[1]
del target[target_key]
return self.config
Comment thread plugins/cliconf_utils/vyosconf.py
Comment thread plugins/cliconf/vyos.py
Comment thread plugins/cliconf_utils/vyosconf.py
Comment thread plugins/cliconf/vyos.py
Comment on lines +275 to +279
if diff_match == "smart" and running is not None:
running_conf = VyosConf([line for line in running.splitlines() if line.strip()])
candidate_conf = VyosConf([line for line in candidate_commands if line.strip()])
diff["config_diff"] = running_conf.diff_commands_to(candidate_conf)
return diff
Comment thread changelogs/fragments/vyos_config_smart.yml
Comment thread tests/unit/modules/network/vyos/test_vyos_config.py
Comment thread plugins/cliconf_utils/vyosconf.py
Copilot AI review requested due to automatic review settings May 25, 2026 12:02
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 11 changed files in this pull request and generated 4 comments.

Comment thread plugins/cliconf/vyos.py
Comment on lines +275 to +279
if diff_match == "smart" and running is not None:
running_conf = VyosConf([line for line in running.splitlines() if line.strip()])
candidate_conf = VyosConf([line for line in candidate_commands if line.strip()])
diff["config_diff"] = running_conf.diff_commands_to(candidate_conf)
return diff
Comment on lines +234 to +235
(toset, todel) = self.diff_to(other.config, self.config)
return ["delete " + c.strip() for c in todel] + ["set " + c.strip() for c in toset]
Comment thread plugins/modules/vyos_config.py
Comment on lines +144 to +149
def test_vyos_config_match_smart(self):
lines = [
"set interfaces ethernet eth0 address '1.2.3.4/24'",
"set interfaces ethernet eth0 description 'test string'",
]
set_module_args(dict(lines=lines, match="smart"))
Copilot AI review requested due to automatic review settings May 26, 2026 19:46
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 11 changed files in this pull request and generated 4 comments.

Comment thread plugins/cliconf/vyos.py
Comment on lines +275 to +279
if diff_match == "smart" and running is not None:
running_conf = VyosConf([line for line in running.splitlines() if line.strip()])
candidate_conf = VyosConf([line for line in candidate_commands if line.strip()])
diff["config_diff"] = running_conf.diff_commands_to(candidate_conf)
return diff
Comment thread plugins/cliconf/vyos.py
Comment on lines 272 to +277
if diff_match == "none":
diff["config_diff"] = list(candidate_commands)
return diff
if diff_match == "smart" and running is not None:
running_conf = VyosConf([line for line in running.splitlines() if line.strip()])
candidate_conf = VyosConf([line for line in candidate_commands if line.strip()])
Comment on lines +57 to +75
target = self.config
first_no_sibling_key = None
for key in path:
if key not in target:
return self.config
if len(target[key]) <= 1:
if first_no_sibling_key is None:
first_no_sibling_key = [target, key]
else:
first_no_sibling_key = None
target = target[key]

if first_no_sibling_key is None:
first_no_sibling_key = [target, leaf]

target = first_no_sibling_key[0]
target_key = first_no_sibling_key[1]
del target[target_key]
return self.config
from ansible_collections.vyos.vyos.plugins.cliconf_utils.vyosconf import VyosConf


class TestListElements(unittest.TestCase):
Copilot AI review requested due to automatic review settings May 30, 2026 20:40
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 11 changed files in this pull request and generated 2 comments.

Comment on lines +69 to +74
if first_no_sibling_key is None:
first_no_sibling_key = [target, leaf]

target = first_no_sibling_key[0]
target_key = first_no_sibling_key[1]
del target[target_key]
Comment on lines +115 to +120
[cmd, path, leaf] = self.parse_line(command)
if cmd.startswith("set"):
self.set_entry(path, leaf)
if cmd.startswith("del"):
self.del_entry(path, leaf)
return self.config
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

2 participants