diff options
author | Wim de With <wf@dewith.io> | 2020-12-09 01:25:04 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-09 00:25:04 +0000 |
commit | 59dad0ffed43b0f7fc3026fc8014e2092cb5b68b (patch) | |
tree | b0e5124337b960a40eba47dd947e770c5ee8b9b8 | |
parent | 6c51003d205242acd18bdfb6bd3400c5cfdba419 (diff) | |
download | vyos.vyos-59dad0ffed43b0f7fc3026fc8014e2092cb5b68b.tar.gz vyos.vyos-59dad0ffed43b0f7fc3026fc8014e2092cb5b68b.zip |
vyos_config: Fix config being processed as command (#94)
vyos_config: Fix config being processed as command
Reviewed-by: https://github.com/apps/ansible-zuul
4 files changed, 19 insertions, 7 deletions
diff --git a/changelogs/fragments/config-processed-as-command.yaml b/changelogs/fragments/config-processed-as-command.yaml new file mode 100644 index 0000000..b34f5a0 --- /dev/null +++ b/changelogs/fragments/config-processed-as-command.yaml @@ -0,0 +1,3 @@ +--- +bugfixes: + - vyos_config - Only process src files as commands when they actually contain commands. This fixes an issue were the whitespace preceding a configuration key named 'set' was stripped, tripping up the parser. diff --git a/plugins/modules/vyos_config.py b/plugins/modules/vyos_config.py index 5e4836d..8efad38 100644 --- a/plugins/modules/vyos_config.py +++ b/plugins/modules/vyos_config.py @@ -209,7 +209,11 @@ def get_candidate(module): contents = module.params["src"] or module.params["lines"] if module.params["src"]: - contents = format_commands(contents.splitlines()) + contents = contents.splitlines() + if len(contents) > 0: + line = contents[0].split() + if len(line) > 0 and line[0] in ("set", "delete"): + contents = format_commands(contents) contents = "\n".join(contents) return contents diff --git a/tests/unit/modules/network/vyos/fixtures/vyos_config_src_brackets.cfg b/tests/unit/modules/network/vyos/fixtures/vyos_config_src_brackets.cfg index 468b32c..81c06b2 100644 --- a/tests/unit/modules/network/vyos/fixtures/vyos_config_src_brackets.cfg +++ b/tests/unit/modules/network/vyos/fixtures/vyos_config_src_brackets.cfg @@ -8,6 +8,15 @@ interfaces { disable } } +policy { + route testroute { + rule 1 { + set { + table 10 + } + } + } +} system { host-name foo } diff --git a/tests/unit/modules/network/vyos/test_vyos_config.py b/tests/unit/modules/network/vyos/test_vyos_config.py index a471edd..3c49d3a 100644 --- a/tests/unit/modules/network/vyos/test_vyos_config.py +++ b/tests/unit/modules/network/vyos/test_vyos_config.py @@ -106,16 +106,12 @@ class TestVyosConfigModule(TestVyosModule): def test_vyos_config_src_brackets(self): src = load_fixture("vyos_config_src_brackets.cfg") set_module_args(dict(src=src)) - candidate = "\n".join(self.module.format_commands(src.splitlines())) commands = [ "set interfaces ethernet eth0 address 10.10.10.10/24", + "set policy route testroute rule 1 set table 10", "set system host-name foo", ] - self.conn.get_diff = MagicMock( - return_value=self.cliconf_obj.get_diff( - candidate, self.running_config - ) - ) + self.conn.get_diff = MagicMock(side_effect=self.cliconf_obj.get_diff) self.execute_module(changed=True, commands=commands) def test_vyos_config_backup(self): |