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

Issue: 46475 Fix onyx magp module for supporting new json format (#49417)

Signed-off-by: Anas Badaha <anasb@mellanox.com>
This commit is contained in:
anasbadaha 2018-12-17 07:22:51 +02:00 committed by Ganesh Nalawade
parent de3d188cdd
commit 369354547e
2 changed files with 19 additions and 4 deletions

View file

@ -65,6 +65,7 @@ commands:
import re
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.six import iteritems
from ansible.module_utils.network.onyx.onyx import BaseOnyxModule
from ansible.module_utils.network.onyx.onyx import show_cmd
@ -133,10 +134,17 @@ class OnyxMagpModule(BaseOnyxModule):
router_mac=self.get_config_attr(item, "Virtual MAC"))
def _update_magp_data(self, magp_data):
for magp_item in magp_data:
magp_id = self.get_magp_id(magp_item)
inst_data = self._create_magp_instance_data(magp_id, magp_item)
self._current_config[magp_id] = inst_data
if self._os_version >= self.ONYX_API_VERSION:
for magp_config in magp_data:
for magp_name, data in iteritems(magp_config):
magp_id = int(magp_name.replace('MAGP ', ''))
self._current_config[magp_id] = \
self._create_magp_instance_data(magp_id, data[0])
else:
for magp_item in magp_data:
magp_id = self.get_magp_id(magp_item)
inst_data = self._create_magp_instance_data(magp_id, magp_item)
self._current_config[magp_id] = inst_data
def _get_magp_config(self):
cmd = "show magp"
@ -144,6 +152,7 @@ class OnyxMagpModule(BaseOnyxModule):
def load_current_config(self):
# called in base class in run function
self._os_version = self._get_os_version()
self._current_config = dict()
magp_data = self._get_magp_config()
if magp_data:

View file

@ -27,15 +27,21 @@ class TestOnyxMagpModule(TestOnyxModule):
'ansible.module_utils.network.onyx.onyx.load_config')
self.load_config = self.mock_load_config.start()
self.mock_get_version = patch.object(onyx_magp.OnyxMagpModule,
"_get_os_version")
self.get_version = self.mock_get_version.start()
def tearDown(self):
super(TestOnyxMagpModule, self).tearDown()
self.mock_get_config.stop()
self.mock_load_config.stop()
self.mock_get_version.stop()
def load_fixtures(self, commands=None, transport='cli'):
config_file = 'onyx_magp_show.cfg'
self.get_config.return_value = load_fixture(config_file)
self.load_config.return_value = None
self.get_version.return_value = "3.6.5000"
def test_magp_absent_no_change(self):
set_module_args(dict(interface='Vlan 1002', magp_id=110,