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)
|
return get_interfaces_config(self._module, self._interface_type)
|
||||||
|
|
||||||
def load_current_config(self):
|
def load_current_config(self):
|
||||||
|
self._os_version = self._get_os_version()
|
||||||
self._current_config = dict()
|
self._current_config = dict()
|
||||||
config = self._get_interfaces_config()
|
config = self._get_interfaces_config()
|
||||||
if not config:
|
if not config:
|
||||||
return
|
return
|
||||||
|
if self._os_version < self.ONYX_API_VERSION:
|
||||||
for item in config:
|
for if_data in config:
|
||||||
name = self.get_if_name(item)
|
if_name = self.get_if_name(if_data)
|
||||||
self._current_config[name] = self._create_if_data(name, item)
|
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):
|
def _generate_no_if_commands(self, req_if, curr_if):
|
||||||
if self._interface_type == self.IF_TYPE_ETH:
|
if self._interface_type == self.IF_TYPE_ETH:
|
||||||
|
|
|
@ -162,6 +162,9 @@ class OnyxL2InterfaceModule(BaseOnyxModule):
|
||||||
return int(access_vlan)
|
return int(access_vlan)
|
||||||
|
|
||||||
def _create_switchport_data(self, if_name, if_data):
|
def _create_switchport_data(self, if_name, if_data):
|
||||||
|
if self._os_version >= self.ONYX_API_VERSION:
|
||||||
|
if_data = if_data[0]
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'name': if_name,
|
'name': if_name,
|
||||||
'mode': self.get_config_attr(if_data, 'Mode'),
|
'mode': self.get_config_attr(if_data, 'Mode'),
|
||||||
|
@ -174,6 +177,7 @@ class OnyxL2InterfaceModule(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()
|
||||||
switchports_config = self._get_switchport_config()
|
switchports_config = self._get_switchport_config()
|
||||||
if not switchports_config:
|
if not switchports_config:
|
||||||
|
|
|
@ -197,34 +197,44 @@ class OnyxL3InterfaceModule(BaseOnyxModule):
|
||||||
return get_interfaces_config(self._module, interface_type)
|
return get_interfaces_config(self._module, interface_type)
|
||||||
|
|
||||||
def _parse_interfaces_config(self, if_type, if_config):
|
def _parse_interfaces_config(self, if_type, if_config):
|
||||||
|
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]
|
ipaddr_attr = self.IP_ADDR_ATTR_MAP[if_type]
|
||||||
for if_data in if_config:
|
regex = self.IF_TYPE_MAP[if_type]
|
||||||
if_name = self.get_config_attr(if_data, 'header')
|
match = regex.match(if_name)
|
||||||
regex = self.IF_TYPE_MAP[if_type]
|
if not match:
|
||||||
match = regex.match(if_name)
|
return
|
||||||
if not match:
|
ipv4 = self.get_config_attr(if_data, ipaddr_attr)
|
||||||
continue
|
if ipv4:
|
||||||
ipv4 = self.get_config_attr(if_data, ipaddr_attr)
|
ipv4 = ipv4.replace(' ', '')
|
||||||
if ipv4:
|
ipv6 = self.get_config_attr(if_data, 'IPv6 address(es)')
|
||||||
ipv4 = ipv4.replace(' ', '')
|
if ipv6:
|
||||||
ipv6 = self.get_config_attr(if_data, 'IPv6 address(es)')
|
ipv6 = ipv6.replace('[primary]', '')
|
||||||
if ipv6:
|
ipv6 = ipv6.strip()
|
||||||
ipv6 = ipv6.replace('[primary]', '')
|
if_id = match.group(1)
|
||||||
ipv6 = ipv6.strip()
|
switchport = self.get_config_attr(if_data, 'Switchport mode')
|
||||||
if_id = match.group(1)
|
if_obj = {
|
||||||
switchport = self.get_config_attr(if_data, 'Switchport mode')
|
'name': if_name,
|
||||||
if_obj = {
|
'if_id': if_id,
|
||||||
'name': if_name,
|
'if_type': if_type,
|
||||||
'if_id': if_id,
|
'ipv4': ipv4,
|
||||||
'if_type': if_type,
|
'ipv6': ipv6,
|
||||||
'ipv4': ipv4,
|
'switchport': switchport,
|
||||||
'ipv6': ipv6,
|
}
|
||||||
'switchport': switchport,
|
self._current_config[if_name] = if_obj
|
||||||
}
|
|
||||||
self._current_config[if_name] = if_obj
|
|
||||||
|
|
||||||
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()
|
||||||
if_types = set([if_obj['if_type'] for if_obj in self._required_config])
|
if_types = set([if_obj['if_type'] for if_obj in self._required_config])
|
||||||
for if_type in if_types:
|
for if_type in if_types:
|
||||||
|
|
|
@ -34,6 +34,10 @@ class TestOnyxInterfaceModule(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_interface.OnyxInterfaceModule, "_get_os_version")
|
||||||
|
self.get_version = self.mock_get_version.start()
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
super(TestOnyxInterfaceModule, self).tearDown()
|
super(TestOnyxInterfaceModule, self).tearDown()
|
||||||
self.mock_get_config.stop()
|
self.mock_get_config.stop()
|
||||||
|
@ -43,6 +47,7 @@ class TestOnyxInterfaceModule(TestOnyxModule):
|
||||||
config_file = 'onyx_interfaces_show.cfg'
|
config_file = 'onyx_interfaces_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_mtu_no_change(self):
|
def test_mtu_no_change(self):
|
||||||
set_module_args(dict(name='Eth1/1', mtu=1500))
|
set_module_args(dict(name='Eth1/1', mtu=1500))
|
||||||
|
|
|
@ -40,6 +40,10 @@ class TestOnyxInterfaceModule(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_l2_interface.OnyxL2InterfaceModule, "_get_os_version")
|
||||||
|
self.get_version = self.mock_get_version.start()
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
super(TestOnyxInterfaceModule, self).tearDown()
|
super(TestOnyxInterfaceModule, self).tearDown()
|
||||||
self.mock_get_config.stop()
|
self.mock_get_config.stop()
|
||||||
|
@ -49,6 +53,7 @@ class TestOnyxInterfaceModule(TestOnyxModule):
|
||||||
config_file = 'onyx_l2_interface_show.cfg'
|
config_file = 'onyx_l2_interface_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_access_vlan_no_change(self):
|
def test_access_vlan_no_change(self):
|
||||||
set_module_args(dict(name='Eth1/11', access_vlan=1))
|
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')
|
'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_l3_interface.OnyxL3InterfaceModule, "_get_os_version")
|
||||||
|
self.get_version = self.mock_get_version.start()
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
super(TestOnyxL3InterfaceModule, self).tearDown()
|
super(TestOnyxL3InterfaceModule, self).tearDown()
|
||||||
self.mock_get_config.stop()
|
self.mock_get_config.stop()
|
||||||
|
@ -52,6 +56,7 @@ class TestOnyxL3InterfaceModule(TestOnyxModule):
|
||||||
def load_fixture(self, config_file):
|
def load_fixture(self, config_file):
|
||||||
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 load_eth_ifc_fixture(self):
|
def load_eth_ifc_fixture(self):
|
||||||
config_file = 'onyx_l3_interface_show.cfg'
|
config_file = 'onyx_l3_interface_show.cfg'
|
||||||
|
|
Loading…
Reference in a new issue