diff options
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 00000000..b34f5a09 --- /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 5e4836d8..8efad382 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 468b32c2..81c06b25 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 a471edd4..3c49d3aa 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): |