1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

fix nxos_overlay_global idempotence (#28150)

* fix nxos_overlay_global idempotence

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

* modify nxos_overlay_global unittest

Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>
This commit is contained in:
Trishna Guha 2017-08-14 16:09:53 +05:30 committed by GitHub
parent a8b7f2a7e2
commit 60ce6438e3
3 changed files with 11 additions and 6 deletions

View file

@ -72,11 +72,12 @@ def get_existing(module, args):
for arg in args:
command = PARAM_TO_COMMAND_KEYMAP[arg]
has_command = re.match(r'(?:{0}\s)(?P<value>.*)$'.format(command), config, re.M)
has_command = re.findall(r'(?:{0}\s)(?P<value>.*)$'.format(command), config, re.M)
value = ''
if has_command:
value = has_command.group('value')
value = has_command[0]
existing[arg] = value
return existing
@ -102,8 +103,10 @@ def get_commands(module, existing, proposed, candidate):
else:
if 'anycast-gateway-mac' in key:
value = normalize_mac(value, module)
command = '{0} {1}'.format(key, value)
commands.append(command)
existing_value = existing_commands.get(key)
if existing_value and value != existing_value:
command = '{0} {1}'.format(key, value)
commands.append(command)
if commands:
candidate.add(commands, parents=[])

View file

@ -0,0 +1 @@
fabric forwarding anycast-gateway-mac 000B.000B.000B

View file

@ -42,9 +42,10 @@ class TestNxosOverlayGlobalModule(TestNxosModule):
self.mock_get_config.stop()
def load_fixtures(self, commands=None, device=''):
self.get_config.return_value = load_fixture('', 'nxos_overlay_global_config.cfg')
self.load_config.return_value = None
def test_nxos_overlay_global_up(self):
set_module_args(dict(anycast_gateway_mac="b.b.b"))
set_module_args(dict(anycast_gateway_mac="a.a.a"))
result = self.execute_module(changed=True)
self.assertEqual(result['commands'], ['fabric forwarding anycast-gateway-mac 000B.000B.000B'])
self.assertEqual(result['commands'], ['fabric forwarding anycast-gateway-mac 000A.000A.000A'])