From 6178a55afda751aaf185cfc6992f13e4e97ed0e8 Mon Sep 17 00:00:00 2001 From: anasbadaha <43231942+anasbadaha@users.noreply.github.com> Date: Fri, 21 Dec 2018 08:23:36 +0200 Subject: [PATCH] Fix Issue #49612 (#50073) * Fix Issue #49612 Signed-off-by: Anas Badaha * Fix Pep8 failures Signed-off-by: Anas Badaha * Add validation for send empty group name Signed-off-by: Anas Badaha * Fix Error message Signed-off-by: Anas Badaha --- lib/ansible/modules/network/onyx/onyx_mlag_vip.py | 14 ++++++++++---- .../modules/network/onyx/test_onyx_mlag_vip.py | 8 ++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/ansible/modules/network/onyx/onyx_mlag_vip.py b/lib/ansible/modules/network/onyx/onyx_mlag_vip.py index ca639a6fb6..047bd29594 100644 --- a/lib/ansible/modules/network/onyx/onyx_mlag_vip.py +++ b/lib/ansible/modules/network/onyx/onyx_mlag_vip.py @@ -145,11 +145,17 @@ class OnyxMLagVipModule(BaseOnyxModule): if req_mac: req_mac = req_mac.lower() - if req_group != current_group or req_ip != current_ip: + if req_ip is not None: + if req_group is None: + self._module.fail_json(msg='In order to configure Mlag-Vip you must send ' + 'group name param beside IPaddress') ipaddr, mask = req_ip.split('/') - self._commands.append( - 'mlag-vip %s ip %s /%s force' % (req_group, ipaddr, mask)) - if req_mac != current_mac: + if req_group != current_group or req_ip != current_ip: + self._commands.append('mlag-vip %s ip %s /%s force' % (req_group, ipaddr, mask)) + elif req_group and req_group != current_group: + self._commands.append('mlag-vip %s' % req_group) + + if req_mac and req_mac != current_mac: self._commands.append( 'mlag system-mac %s' % (req_mac)) if self._commands: diff --git a/test/units/modules/network/onyx/test_onyx_mlag_vip.py b/test/units/modules/network/onyx/test_onyx_mlag_vip.py index f093c9a5ca..1ff20afab3 100644 --- a/test/units/modules/network/onyx/test_onyx_mlag_vip.py +++ b/test/units/modules/network/onyx/test_onyx_mlag_vip.py @@ -65,6 +65,14 @@ class TestOnyxMlagVipModule(TestOnyxModule): 'mlag system-mac 00:00:5e:00:01:4e', 'no mlag shutdown'] self.execute_module(changed=True, commands=commands) + def test_mlag_send_group_name_only_change(self): + self._mlag_enabled = False + set_module_args(dict(group_name='neo-mlag-vip-500', + delay=0)) + commands = ['mlag-vip neo-mlag-vip-500', + 'no mlag shutdown'] + self.execute_module(changed=True, commands=commands) + def test_mlag_absent_no_change(self): self._mlag_enabled = False set_module_args(dict(state='absent'))