PR190 revive, vyos_conf match "enforced"#415
Open
omnom62 wants to merge 45 commits into
Open
Conversation
|
All contributors have signed the CLA ✍️ ✅ |
Contributor
Author
|
I have read the CLA Document and I hereby sign the CLA |
There was a problem hiding this comment.
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
📒 Files selected for processing (2)
plugins/cliconf/vyos.pytests/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 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 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 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
+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 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")) |
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
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): |
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Related Task(s)
Related PR(s)
Component(s) name
Proposed changes
How to test
Test results
Tested against VyOS versions:
Checklist:
changelogs/fragmentsto describe the changesSummary by CodeRabbit
New Features
Documentation
Tests
Chores