diff --git a/lib/ansible/modules/network/onyx/onyx_magp.py b/lib/ansible/modules/network/onyx/onyx_magp.py index 2b429411933..603c2497493 100644 --- a/lib/ansible/modules/network/onyx/onyx_magp.py +++ b/lib/ansible/modules/network/onyx/onyx_magp.py @@ -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: diff --git a/test/units/modules/network/onyx/test_onyx_magp.py b/test/units/modules/network/onyx/test_onyx_magp.py index 8a5146b6b86..2fbbd82e4cd 100644 --- a/test/units/modules/network/onyx/test_onyx_magp.py +++ b/test/units/modules/network/onyx/test_onyx_magp.py @@ -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,