From a49c419651ef78c571dfd69d576c8f0c227abdd6 Mon Sep 17 00:00:00 2001 From: Trishna Guha Date: Fri, 28 Jul 2017 09:02:02 +0530 Subject: fix nxos_vrf_af nxapi & cli (#27307) * fix nxapi failure #27142 Signed-off-by: Trishna Guha * fix nxos_vrf_af nxapi and cli Signed-off-by: Trishna Guha --- lib/ansible/modules/network/nxos/nxos_vrf_af.py | 24 ++++++++-------------- .../units/modules/network/nxos/test_nxos_vrf_af.py | 10 ++------- 2 files changed, 10 insertions(+), 24 deletions(-) diff --git a/lib/ansible/modules/network/nxos/nxos_vrf_af.py b/lib/ansible/modules/network/nxos/nxos_vrf_af.py index 0c411f3b5c..0809b36196 100644 --- a/lib/ansible/modules/network/nxos/nxos_vrf_af.py +++ b/lib/ansible/modules/network/nxos/nxos_vrf_af.py @@ -80,9 +80,7 @@ commands: description: commands sent to the device returned: always type: list - sample: ["vrf context ntc", "address-family ipv4 unicast", - "afi ipv4", "route-target both auto evpn", "vrf ntc", - "safi unicast"] + sample: ["vrf context ntc", "address-family ipv4 unicast"] ''' import re @@ -95,9 +93,6 @@ from ansible.module_utils.netcfg import CustomNetworkConfig BOOL_PARAMS = ['route_target_both_auto_evpn'] PARAM_TO_COMMAND_KEYMAP = { - 'vrf': 'vrf', - 'safi': 'safi', - 'afi': 'afi', 'route_target_both_auto_evpn': 'route-target both auto evpn' } PARAM_TO_DEFAULT_KEYMAP = {} @@ -179,11 +174,10 @@ def state_present(module, existing, proposed, candidate): command = '{0} {1}'.format(key, value.lower()) commands.append(command) - if commands: - parents = ['vrf context {0}'.format(module.params['vrf'])] - parents.append('address-family {0} {1}'.format(module.params['afi'], - module.params['safi'])) - candidate.add(commands, parents=parents) + parents = ['vrf context {0}'.format(module.params['vrf'])] + parents.append('address-family {0} {1}'.format(module.params['afi'], + module.params['safi'])) + candidate.add(commands, parents=parents) def state_absent(module, existing, proposed, candidate): @@ -201,10 +195,7 @@ def main(): afi=dict(required=True, type='str', choices=['ipv4', 'ipv6']), route_target_both_auto_evpn=dict(required=False, type='bool'), m_facts=dict(required=False, default=False, type='bool'), - state=dict(choices=['present', 'absent'], default='present', required=False), - include_defaults=dict(default=False), - config=dict(), - save=dict(type='bool', default=False) + state=dict(choices=['present', 'absent'], default='present', required=False) ) argument_spec.update(nxos_argument_spec) @@ -238,9 +229,10 @@ def main(): state_absent(module, existing, proposed, candidate) if candidate: + candidate = candidate.items_text() load_config(module, candidate) result['changed'] = True - result['commands'] = candidate.items_text() + result['commands'] = candidate else: result['commands'] = [] diff --git a/test/units/modules/network/nxos/test_nxos_vrf_af.py b/test/units/modules/network/nxos/test_nxos_vrf_af.py index d2a890e4e1..7a3e7a329b 100644 --- a/test/units/modules/network/nxos/test_nxos_vrf_af.py +++ b/test/units/modules/network/nxos/test_nxos_vrf_af.py @@ -51,10 +51,7 @@ class TestNxosVrfafModule(TestNxosModule): set_module_args(dict(vrf='ntc', afi='ipv4', safi='unicast', state='present')) result = self.execute_module(changed=True) self.assertEqual(sorted(result['commands']), sorted(['vrf context ntc', - 'address-family ipv4 unicast', - 'afi ipv4', - 'vrf ntc', - 'safi unicast'])) + 'address-family ipv4 unicast'])) def test_nxos_vrf_af_absent(self): set_module_args(dict(vrf='ntc', afi='ipv4', safi='unicast', state='absent')) @@ -66,7 +63,4 @@ class TestNxosVrfafModule(TestNxosModule): result = self.execute_module(changed=True) self.assertEqual(sorted(result['commands']), sorted(['vrf context ntc', 'address-family ipv4 unicast', - 'afi ipv4', - 'route-target both auto evpn', - 'vrf ntc', - 'safi unicast'])) + 'route-target both auto evpn'])) -- cgit v1.2.1