From ae033f1ec392f363e5ddaf9e3d28ccb4d71ceef1 Mon Sep 17 00:00:00 2001 From: Rohit Date: Fri, 31 May 2019 16:13:40 +0530 Subject: [PATCH] vyos interfacefix and test cases (#57169) Signed-off-by: rohitthakur2590 --- lib/ansible/modules/network/vyos/vyos_interface.py | 6 +++++- .../targets/vyos_interface/tests/cli/basic.yaml | 10 +++++----- .../vyos_interface/tests/cli/net_interface.yaml | 4 ++-- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/ansible/modules/network/vyos/vyos_interface.py b/lib/ansible/modules/network/vyos/vyos_interface.py index def589c26dc..dce70ff48db 100644 --- a/lib/ansible/modules/network/vyos/vyos_interface.py +++ b/lib/ansible/modules/network/vyos/vyos_interface.py @@ -204,6 +204,8 @@ def map_obj_to_commands(updates): value = w.get(item) if value and value != obj_in_have.get(item): + if item == 'description': + value = "\'" + str(value) + "\'" commands.append(set_interface + ' ' + item + ' ' + str(value)) if disable and not obj_in_have.get('disable', False): @@ -215,6 +217,8 @@ def map_obj_to_commands(updates): for item in params: value = w.get(item) if value: + if item == 'description': + value = "\'" + str(value) + "\'" commands.append(set_interface + ' ' + item + ' ' + str(value)) if disable: @@ -244,7 +248,7 @@ def map_config_to_obj(module): if match: param = match.group(1) if param == 'description': - match = re.search(r'description (\S+)', line, re.M) + match = re.search(r'description (.+)', line, re.M) description = match.group(1).strip("'") interface['description'] = description elif param == 'speed': diff --git a/test/integration/targets/vyos_interface/tests/cli/basic.yaml b/test/integration/targets/vyos_interface/tests/cli/basic.yaml index 0f1549a7381..2b9ce129b1b 100644 --- a/test/integration/targets/vyos_interface/tests/cli/basic.yaml +++ b/test/integration/targets/vyos_interface/tests/cli/basic.yaml @@ -23,7 +23,7 @@ that: - 'result.changed == true' - '"set interfaces ethernet eth1" in result.commands' - - '"set interfaces ethernet eth1 description test-interface" in result.commands' + - '"set interfaces ethernet eth1 description ''test-interface''" in result.commands' - name: Configure interface params vyos_interface: @@ -39,7 +39,7 @@ - assert: that: - 'result.changed == true' - - '"set interfaces ethernet eth1 description test-interface-1" in result.commands' + - '"set interfaces ethernet eth1 description ''test-interface-1''" in result.commands' - '"set interfaces ethernet eth1 speed 100" in result.commands' - '"set interfaces ethernet eth1 duplex half" in result.commands' - '"set interfaces ethernet eth1 mtu 256" in result.commands' @@ -75,7 +75,7 @@ - assert: that: - 'result.changed == true' - - '"set interfaces ethernet eth1 description test-interface-2" in result.commands' + - '"set interfaces ethernet eth1 description ''test-interface-2''" in result.commands' - '"set interfaces ethernet eth1 speed 1000" in result.commands' - '"set interfaces ethernet eth1 duplex full" in result.commands' - '"set interfaces ethernet eth1 mtu 512" in result.commands' @@ -141,11 +141,11 @@ - assert: that: - 'result.changed == true' - - '"set interfaces ethernet eth1 description test-interface-1" in result.commands' + - '"set interfaces ethernet eth1 description ''test-interface-1''" in result.commands' - '"set interfaces ethernet eth1 speed 100" in result.commands' - '"set interfaces ethernet eth1 duplex half" in result.commands' - '"set interfaces ethernet eth1 mtu 512" in result.commands' - - '"set interfaces ethernet eth2 description test-interface-2" in result.commands' + - '"set interfaces ethernet eth2 description ''test-interface-2''" in result.commands' - '"set interfaces ethernet eth2 speed 1000" in result.commands' - '"set interfaces ethernet eth2 duplex full" in result.commands' - '"set interfaces ethernet eth2 mtu 256" in result.commands' diff --git a/test/integration/targets/vyos_interface/tests/cli/net_interface.yaml b/test/integration/targets/vyos_interface/tests/cli/net_interface.yaml index c3ea453397b..ced273d5f5b 100644 --- a/test/integration/targets/vyos_interface/tests/cli/net_interface.yaml +++ b/test/integration/targets/vyos_interface/tests/cli/net_interface.yaml @@ -26,7 +26,7 @@ that: - 'result.changed == true' - '"set interfaces ethernet eth1" in result.commands' - - '"set interfaces ethernet eth1 description test-interface" in result.commands' + - '"set interfaces ethernet eth1 description ''test-interface''" in result.commands' - name: Configure interface params using platform agnostic module net_interface: @@ -42,7 +42,7 @@ - assert: that: - 'result.changed == true' - - '"set interfaces ethernet eth1 description test-interface-1" in result.commands' + - '"set interfaces ethernet eth1 description ''test-interface-1''" in result.commands' - '"set interfaces ethernet eth1 speed 100" in result.commands' - '"set interfaces ethernet eth1 duplex half" in result.commands' - '"set interfaces ethernet eth1 mtu 256" in result.commands'