From 2f996fc6e222eeaf6c3391ad437dadf8ad642b36 Mon Sep 17 00:00:00 2001 From: Rohit Date: Fri, 3 Jan 2020 17:35:37 +0530 Subject: [PATCH] vyos_config bug fix #66110 (#66122) Signed-off-by: rohitthakur2590 --- .../modules/network/vyos/vyos_config.py | 8 ++++++- .../targets/vyos_config/tests/cli/config.cfg | 3 +++ .../targets/vyos_config/tests/cli/simple.yaml | 24 +++++++++++++++++++ .../network/vyos/fixtures/vyos_config_src.cfg | 2 +- 4 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 test/integration/targets/vyos_config/tests/cli/config.cfg diff --git a/lib/ansible/modules/network/vyos/vyos_config.py b/lib/ansible/modules/network/vyos/vyos_config.py index 25711a0cc4..5af2147172 100644 --- a/lib/ansible/modules/network/vyos/vyos_config.py +++ b/lib/ansible/modules/network/vyos/vyos_config.py @@ -208,7 +208,13 @@ def get_candidate(module): def format_commands(commands): - return [line for line in commands if len(line.strip()) > 0] + """ + This function format the input commands and removes the prepend white spaces + for command lines having 'set' or 'delete' and it skips empty lines. + :param commands: + :return: list of commands + """ + return [line.strip() if line.split()[0] in ('set', 'delete') else line for line in commands if len(line.strip()) > 0] def diff_config(commands, config): diff --git a/test/integration/targets/vyos_config/tests/cli/config.cfg b/test/integration/targets/vyos_config/tests/cli/config.cfg new file mode 100644 index 0000000000..36c98f19aa --- /dev/null +++ b/test/integration/targets/vyos_config/tests/cli/config.cfg @@ -0,0 +1,3 @@ + set service lldp + set protocols static + diff --git a/test/integration/targets/vyos_config/tests/cli/simple.yaml b/test/integration/targets/vyos_config/tests/cli/simple.yaml index a4a879957c..376d0b94bb 100644 --- a/test/integration/targets/vyos_config/tests/cli/simple.yaml +++ b/test/integration/targets/vyos_config/tests/cli/simple.yaml @@ -25,6 +25,30 @@ that: - "result.changed == false" +- name: Configuring when commands starts with whitespaces + vyos_config: + src: "{{ role_path }}/tests/cli/config.cfg" + register: result + +- assert: + that: + - "result.changed == true" + - '"set service lldp" in result.commands' + - '"set protocols static" in result.commands' + +- name: Delete description + vyos_config: + lines: + - delete service lldp + - delete protocols static + register: result + +- assert: + that: + - "result.changed == true" + - '"delete service lldp" in result.commands' + - '"delete protocols static" in result.commands' + - name: teardown vyos_config: lines: set system host-name {{ inventory_hostname_short }} diff --git a/test/units/modules/network/vyos/fixtures/vyos_config_src.cfg b/test/units/modules/network/vyos/fixtures/vyos_config_src.cfg index 18cd793718..410f6115fc 100644 --- a/test/units/modules/network/vyos/fixtures/vyos_config_src.cfg +++ b/test/units/modules/network/vyos/fixtures/vyos_config_src.cfg @@ -2,5 +2,5 @@ set system host-name foo delete interfaces ethernet eth0 address set interfaces ethernet eth1 address '6.7.8.9/24' -set interfaces ethernet eth1 description 'test string' + set interfaces ethernet eth1 description 'test string' set interfaces ethernet eth1 disable