mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
issue:43021 add support for onyx version 3.6.6000 and above (#44527)
* issue:43021 add support for onyx version 3.6.6000 Signed-off-by: Samer Deeb <samerd@mellanox.com> * issue:43021 add support for onyx version 3.6.6000 Signed-off-by: Samer Deeb <samerd@mellanox.com>
This commit is contained in:
parent
56b9823bb8
commit
a07af2a1f7
6 changed files with 65 additions and 28 deletions
|
@ -335,14 +335,22 @@ class OnyxInterfaceModule(BaseOnyxModule):
|
|||
return get_interfaces_config(self._module, self._interface_type)
|
||||
|
||||
def load_current_config(self):
|
||||
self._os_version = self._get_os_version()
|
||||
self._current_config = dict()
|
||||
config = self._get_interfaces_config()
|
||||
if not config:
|
||||
return
|
||||
|
||||
for item in config:
|
||||
name = self.get_if_name(item)
|
||||
self._current_config[name] = self._create_if_data(name, item)
|
||||
if self._os_version < self.ONYX_API_VERSION:
|
||||
for if_data in config:
|
||||
if_name = self.get_if_name(if_data)
|
||||
self._current_config[if_name] = self._create_if_data(
|
||||
if_name, if_data)
|
||||
else:
|
||||
for if_config in config:
|
||||
for if_name, if_data in iteritems(if_config):
|
||||
if_data = if_data[0]
|
||||
self._current_config[if_name] = self._create_if_data(
|
||||
if_name, if_data)
|
||||
|
||||
def _generate_no_if_commands(self, req_if, curr_if):
|
||||
if self._interface_type == self.IF_TYPE_ETH:
|
||||
|
|
|
@ -162,6 +162,9 @@ class OnyxL2InterfaceModule(BaseOnyxModule):
|
|||
return int(access_vlan)
|
||||
|
||||
def _create_switchport_data(self, if_name, if_data):
|
||||
if self._os_version >= self.ONYX_API_VERSION:
|
||||
if_data = if_data[0]
|
||||
|
||||
return {
|
||||
'name': if_name,
|
||||
'mode': self.get_config_attr(if_data, 'Mode'),
|
||||
|
@ -174,6 +177,7 @@ class OnyxL2InterfaceModule(BaseOnyxModule):
|
|||
|
||||
def load_current_config(self):
|
||||
# called in base class in run function
|
||||
self._os_version = self._get_os_version()
|
||||
self._current_config = dict()
|
||||
switchports_config = self._get_switchport_config()
|
||||
if not switchports_config:
|
||||
|
|
|
@ -197,13 +197,22 @@ class OnyxL3InterfaceModule(BaseOnyxModule):
|
|||
return get_interfaces_config(self._module, interface_type)
|
||||
|
||||
def _parse_interfaces_config(self, if_type, if_config):
|
||||
ipaddr_attr = self.IP_ADDR_ATTR_MAP[if_type]
|
||||
if self._os_version < self.ONYX_API_VERSION:
|
||||
for if_data in if_config:
|
||||
if_name = self.get_config_attr(if_data, 'header')
|
||||
self._get_if_attributes(if_type, if_name, if_data)
|
||||
else:
|
||||
for if_config_item in if_config:
|
||||
for if_name, if_data in iteritems(if_config_item):
|
||||
if_data = if_data[0]
|
||||
self._get_if_attributes(if_type, if_name, if_data)
|
||||
|
||||
def _get_if_attributes(self, if_type, if_name, if_data):
|
||||
ipaddr_attr = self.IP_ADDR_ATTR_MAP[if_type]
|
||||
regex = self.IF_TYPE_MAP[if_type]
|
||||
match = regex.match(if_name)
|
||||
if not match:
|
||||
continue
|
||||
return
|
||||
ipv4 = self.get_config_attr(if_data, ipaddr_attr)
|
||||
if ipv4:
|
||||
ipv4 = ipv4.replace(' ', '')
|
||||
|
@ -225,6 +234,7 @@ class OnyxL3InterfaceModule(BaseOnyxModule):
|
|||
|
||||
def load_current_config(self):
|
||||
# called in base class in run function
|
||||
self._os_version = self._get_os_version()
|
||||
self._current_config = dict()
|
||||
if_types = set([if_obj['if_type'] for if_obj in self._required_config])
|
||||
for if_type in if_types:
|
||||
|
|
|
@ -34,6 +34,10 @@ class TestOnyxInterfaceModule(TestOnyxModule):
|
|||
'ansible.module_utils.network.onyx.onyx.load_config')
|
||||
self.load_config = self.mock_load_config.start()
|
||||
|
||||
self.mock_get_version = patch.object(
|
||||
onyx_interface.OnyxInterfaceModule, "_get_os_version")
|
||||
self.get_version = self.mock_get_version.start()
|
||||
|
||||
def tearDown(self):
|
||||
super(TestOnyxInterfaceModule, self).tearDown()
|
||||
self.mock_get_config.stop()
|
||||
|
@ -43,6 +47,7 @@ class TestOnyxInterfaceModule(TestOnyxModule):
|
|||
config_file = 'onyx_interfaces_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_mtu_no_change(self):
|
||||
set_module_args(dict(name='Eth1/1', mtu=1500))
|
||||
|
|
|
@ -40,6 +40,10 @@ class TestOnyxInterfaceModule(TestOnyxModule):
|
|||
'ansible.module_utils.network.onyx.onyx.load_config')
|
||||
self.load_config = self.mock_load_config.start()
|
||||
|
||||
self.mock_get_version = patch.object(
|
||||
onyx_l2_interface.OnyxL2InterfaceModule, "_get_os_version")
|
||||
self.get_version = self.mock_get_version.start()
|
||||
|
||||
def tearDown(self):
|
||||
super(TestOnyxInterfaceModule, self).tearDown()
|
||||
self.mock_get_config.stop()
|
||||
|
@ -49,6 +53,7 @@ class TestOnyxInterfaceModule(TestOnyxModule):
|
|||
config_file = 'onyx_l2_interface_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_access_vlan_no_change(self):
|
||||
set_module_args(dict(name='Eth1/11', access_vlan=1))
|
||||
|
|
|
@ -27,6 +27,10 @@ class TestOnyxL3InterfaceModule(TestOnyxModule):
|
|||
'ansible.module_utils.network.onyx.onyx.load_config')
|
||||
self.load_config = self.mock_load_config.start()
|
||||
|
||||
self.mock_get_version = patch.object(
|
||||
onyx_l3_interface.OnyxL3InterfaceModule, "_get_os_version")
|
||||
self.get_version = self.mock_get_version.start()
|
||||
|
||||
def tearDown(self):
|
||||
super(TestOnyxL3InterfaceModule, self).tearDown()
|
||||
self.mock_get_config.stop()
|
||||
|
@ -52,6 +56,7 @@ class TestOnyxL3InterfaceModule(TestOnyxModule):
|
|||
def load_fixture(self, config_file):
|
||||
self.get_config.return_value = load_fixture(config_file)
|
||||
self.load_config.return_value = None
|
||||
self.get_version.return_value = "3.6.5000"
|
||||
|
||||
def load_eth_ifc_fixture(self):
|
||||
config_file = 'onyx_l3_interface_show.cfg'
|
||||
|
|
Loading…
Reference in a new issue