fix nxos_vrf_af nxapi & cli (#27307)

* fix nxapi failure #27142

Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>

* fix nxos_vrf_af nxapi and cli

Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>
This commit is contained in:
Trishna Guha 2017-07-28 09:02:02 +05:30 committed by GitHub
parent 87d434ed68
commit a49c419651
2 changed files with 10 additions and 24 deletions

View file

@ -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'] = []

View file

@ -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']))