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:
parent
de3d188cdd
commit
369354547e
2 changed files with 19 additions and 4 deletions
|
@ -65,6 +65,7 @@ commands:
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
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 BaseOnyxModule
|
||||||
from ansible.module_utils.network.onyx.onyx import show_cmd
|
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"))
|
router_mac=self.get_config_attr(item, "Virtual MAC"))
|
||||||
|
|
||||||
def _update_magp_data(self, magp_data):
|
def _update_magp_data(self, magp_data):
|
||||||
for magp_item in magp_data:
|
if self._os_version >= self.ONYX_API_VERSION:
|
||||||
magp_id = self.get_magp_id(magp_item)
|
for magp_config in magp_data:
|
||||||
inst_data = self._create_magp_instance_data(magp_id, magp_item)
|
for magp_name, data in iteritems(magp_config):
|
||||||
self._current_config[magp_id] = inst_data
|
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):
|
def _get_magp_config(self):
|
||||||
cmd = "show magp"
|
cmd = "show magp"
|
||||||
|
@ -144,6 +152,7 @@ class OnyxMagpModule(BaseOnyxModule):
|
||||||
|
|
||||||
def load_current_config(self):
|
def load_current_config(self):
|
||||||
# called in base class in run function
|
# called in base class in run function
|
||||||
|
self._os_version = self._get_os_version()
|
||||||
self._current_config = dict()
|
self._current_config = dict()
|
||||||
magp_data = self._get_magp_config()
|
magp_data = self._get_magp_config()
|
||||||
if magp_data:
|
if magp_data:
|
||||||
|
|
|
@ -27,15 +27,21 @@ class TestOnyxMagpModule(TestOnyxModule):
|
||||||
'ansible.module_utils.network.onyx.onyx.load_config')
|
'ansible.module_utils.network.onyx.onyx.load_config')
|
||||||
self.load_config = self.mock_load_config.start()
|
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):
|
def tearDown(self):
|
||||||
super(TestOnyxMagpModule, self).tearDown()
|
super(TestOnyxMagpModule, self).tearDown()
|
||||||
self.mock_get_config.stop()
|
self.mock_get_config.stop()
|
||||||
self.mock_load_config.stop()
|
self.mock_load_config.stop()
|
||||||
|
self.mock_get_version.stop()
|
||||||
|
|
||||||
def load_fixtures(self, commands=None, transport='cli'):
|
def load_fixtures(self, commands=None, transport='cli'):
|
||||||
config_file = 'onyx_magp_show.cfg'
|
config_file = 'onyx_magp_show.cfg'
|
||||||
self.get_config.return_value = load_fixture(config_file)
|
self.get_config.return_value = load_fixture(config_file)
|
||||||
self.load_config.return_value = None
|
self.load_config.return_value = None
|
||||||
|
self.get_version.return_value = "3.6.5000"
|
||||||
|
|
||||||
def test_magp_absent_no_change(self):
|
def test_magp_absent_no_change(self):
|
||||||
set_module_args(dict(interface='Vlan 1002', magp_id=110,
|
set_module_args(dict(interface='Vlan 1002', magp_id=110,
|
||||||
|
|
Loading…
Add table
Reference in a new issue