mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-24 05:40:23 -07:00
Module mlnxos_l3_interface (#34199)
* Add module mlnxos_l3_interface for configuring L3 on Mellanox switches Signed-off-by: Samer Deeb <samerd@mellanox.com> * Rename test class Signed-off-by: Samer Deeb <samerd@mellanox.com>
This commit is contained in:
parent
ad04c1854d
commit
89670133c1
4 changed files with 510 additions and 0 deletions
|
@ -0,0 +1,89 @@
|
|||
[
|
||||
{
|
||||
"Broadcast address": "172.3.1.255",
|
||||
"Fec": "auto",
|
||||
"Tx": {
|
||||
"error packets": "0",
|
||||
"packets": "0",
|
||||
"bytes": "0",
|
||||
"multicast packets": "0",
|
||||
"unicast packets": "0",
|
||||
"discard packets": "0",
|
||||
"hoq discard packets": "0",
|
||||
"broadcast packets": "0"
|
||||
},
|
||||
"Rx": {
|
||||
"error packets": "0",
|
||||
"packets": "0",
|
||||
"bytes": "0",
|
||||
"multicast packets": "0",
|
||||
"unicast packets": "0",
|
||||
"discard packets": "0",
|
||||
"broadcast packets": "0"
|
||||
},
|
||||
"header": "Eth1/5",
|
||||
"Arp timeout": "1500 seconds",
|
||||
"Actual speed": "40 Gbps",
|
||||
"60 seconds egress rate": "0 bits/sec, 0 bytes/sec, 0 packets/sec",
|
||||
"Last change in operational status": "Never",
|
||||
"Boot delay time": "0 sec",
|
||||
"Description": "N\\A",
|
||||
"DHCP client": "Disabled",
|
||||
"VRF": "default",
|
||||
"Mac address": "24:8A:07:F5:54:01",
|
||||
"60 seconds ingress rate": "0 bits/sec, 0 bytes/sec, 0 packets/sec",
|
||||
"Last clearing of \"show interface\" counters": "Never",
|
||||
"MTU": "1500 bytes(Maximum packet size 1522 bytes)",
|
||||
"Telemetry threshold": "Disabled\t TCs: N\\A",
|
||||
"Telemetry threshold level": "N\\A",
|
||||
"Flow-control": "receive off send off",
|
||||
"Forwarding mode": "inherited cut-through",
|
||||
"Admin state": "Enabled",
|
||||
"Telemetry sampling": "Disabled\t TCs: N\\A",
|
||||
"IP Address": "172.3.12.4 /24",
|
||||
"Operational state": "Down",
|
||||
"Width reduction mode": "Not supported"
|
||||
},
|
||||
{
|
||||
"Fec": "auto",
|
||||
"Mac address": "24:8a:07:f5:54:0c",
|
||||
"60 seconds ingress rate": "0 bits/sec, 0 bytes/sec, 0 packets/sec",
|
||||
"Last clearing of \"show interface\" counters": "Never",
|
||||
"Actual speed": "40 Gbps",
|
||||
"MTU": "1500 bytes(Maximum packet size 1522 bytes)",
|
||||
"header": "Eth1/6",
|
||||
"Telemetry threshold": "Disabled\t TCs: N\\A",
|
||||
"Telemetry threshold level": "N\\A",
|
||||
"Flow-control": "receive off send off",
|
||||
"Forwarding mode": "inherited cut-through",
|
||||
"60 seconds egress rate": "0 bits/sec, 0 bytes/sec, 0 packets/sec",
|
||||
"Last change in operational status": "Never",
|
||||
"Boot delay time": "0 sec",
|
||||
"Description": "N\\A",
|
||||
"Admin state": "Enabled",
|
||||
"Telemetry sampling": "Disabled\t TCs: N\\A",
|
||||
"Operational state": "Down",
|
||||
"Width reduction mode": "Not supported",
|
||||
"Tx": {
|
||||
"error packets": "0",
|
||||
"packets": "0",
|
||||
"bytes": "0",
|
||||
"multicast packets": "0",
|
||||
"unicast packets": "0",
|
||||
"discard packets": "0",
|
||||
"hoq discard packets": "0",
|
||||
"broadcast packets": "0"
|
||||
},
|
||||
"MAC learning mode": "Enabled",
|
||||
"Switchport mode": "access",
|
||||
"Rx": {
|
||||
"error packets": "0",
|
||||
"packets": "0",
|
||||
"bytes": "0",
|
||||
"multicast packets": "0",
|
||||
"unicast packets": "0",
|
||||
"discard packets": "0",
|
||||
"broadcast packets": "0"
|
||||
}
|
||||
}
|
||||
]
|
|
@ -0,0 +1,18 @@
|
|||
[
|
||||
{
|
||||
"Autostate": "Enabled",
|
||||
"Icmp redirect": "Enabled",
|
||||
"Broadcast address": "172.3.12.255",
|
||||
"Description": "N/A",
|
||||
"Mac Address": "7C:FE:90:E5:CA:01",
|
||||
"Internet Address": "172.3.12.4/24",
|
||||
"Admin state": "Enabled",
|
||||
"header": "Vlan 1002",
|
||||
"MTU": "1500 bytes",
|
||||
"DHCP client": "Disabled",
|
||||
"Operational state": "Down",
|
||||
"VRF": "default",
|
||||
"Arp timeout": "1500 seconds",
|
||||
"Counters": "Disabled"
|
||||
}
|
||||
]
|
108
test/units/modules/network/mlnxos/test_mlnxos_l3_interface.py
Normal file
108
test/units/modules/network/mlnxos/test_mlnxos_l3_interface.py
Normal file
|
@ -0,0 +1,108 @@
|
|||
#
|
||||
# Copyright: Ansible Project
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
# Make coding more python3-ish
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
from ansible.compat.tests.mock import patch
|
||||
from ansible.modules.network.mlnxos import mlnxos_l3_interface
|
||||
from units.modules.utils import set_module_args
|
||||
from .mlnxos_module import TestMlnxosModule, load_fixture
|
||||
|
||||
|
||||
class TestMlnxosL3InterfaceModule(TestMlnxosModule):
|
||||
|
||||
module = mlnxos_l3_interface
|
||||
|
||||
def setUp(self):
|
||||
super(TestMlnxosL3InterfaceModule, self).setUp()
|
||||
self.mock_get_config = patch.object(
|
||||
mlnxos_l3_interface.MlnxosL3InterfaceModule,
|
||||
"_get_interfaces_config")
|
||||
self.get_config = self.mock_get_config.start()
|
||||
|
||||
self.mock_load_config = patch(
|
||||
'ansible.module_utils.network.mlnxos.mlnxos.load_config')
|
||||
self.load_config = self.mock_load_config.start()
|
||||
|
||||
def tearDown(self):
|
||||
super(TestMlnxosL3InterfaceModule, self).tearDown()
|
||||
self.mock_get_config.stop()
|
||||
self.mock_load_config.stop()
|
||||
|
||||
def _execute_module(self, failed=False, changed=False, commands=None, sort=True):
|
||||
if failed:
|
||||
result = self.failed()
|
||||
self.assertTrue(result['failed'], result)
|
||||
else:
|
||||
result = self.changed(changed)
|
||||
self.assertEqual(result['changed'], changed, result)
|
||||
|
||||
if commands is not None:
|
||||
commands_res = result.get('commands')
|
||||
if sort:
|
||||
self.assertEqual(sorted(commands), sorted(commands_res), commands_res)
|
||||
else:
|
||||
self.assertEqual(commands, commands_res, commands_res)
|
||||
|
||||
return result
|
||||
|
||||
def load_fixture(self, config_file):
|
||||
self.get_config.return_value = load_fixture(config_file)
|
||||
self.load_config.return_value = None
|
||||
|
||||
def load_eth_ifc_fixture(self):
|
||||
config_file = 'mlnxos_l3_interface_show.cfg'
|
||||
self.load_fixture(config_file)
|
||||
|
||||
def load_vlan_ifc_fixture(self):
|
||||
config_file = 'mlnxos_l3_vlan_interface_show.cfg'
|
||||
self.load_fixture(config_file)
|
||||
|
||||
def test_vlan_ifc_no_change(self):
|
||||
set_module_args(dict(name='Vlan 1002', state='present',
|
||||
ipv4='172.3.12.4/24'))
|
||||
self.load_vlan_ifc_fixture()
|
||||
self._execute_module(changed=False)
|
||||
|
||||
def test_vlan_ifc_remove(self):
|
||||
set_module_args(dict(name='Vlan 1002', state='absent'))
|
||||
commands = ['interface vlan 1002 no ip address']
|
||||
self.load_vlan_ifc_fixture()
|
||||
self._execute_module(changed=True, commands=commands)
|
||||
|
||||
def test_vlan_ifc_update(self):
|
||||
set_module_args(dict(name='Vlan 1002', state='present',
|
||||
ipv4='172.3.13.4/24'))
|
||||
commands = ['interface vlan 1002 ip address 172.3.13.4/24']
|
||||
self.load_vlan_ifc_fixture()
|
||||
self._execute_module(changed=True, commands=commands)
|
||||
|
||||
def test_eth_ifc_no_change(self):
|
||||
set_module_args(dict(name='Eth1/5', state='present',
|
||||
ipv4='172.3.12.4/24'))
|
||||
self.load_eth_ifc_fixture()
|
||||
self._execute_module(changed=False)
|
||||
|
||||
def test_eth_ifc_remove(self):
|
||||
set_module_args(dict(name='Eth1/5', state='absent'))
|
||||
commands = ['interface ethernet 1/5 no ip address']
|
||||
self.load_eth_ifc_fixture()
|
||||
self._execute_module(changed=True, commands=commands)
|
||||
|
||||
def test_eth_ifc_update(self):
|
||||
set_module_args(dict(name='Eth1/5', state='present',
|
||||
ipv4='172.3.13.4/24'))
|
||||
commands = ['interface ethernet 1/5 ip address 172.3.13.4/24']
|
||||
self.load_eth_ifc_fixture()
|
||||
self._execute_module(changed=True, commands=commands)
|
||||
|
||||
def test_eth_ifc_add_ip(self):
|
||||
set_module_args(dict(name='Eth1/6', state='present',
|
||||
ipv4='172.3.14.4/24'))
|
||||
commands = ['interface ethernet 1/6 no switchport force',
|
||||
'interface ethernet 1/6 ip address 172.3.14.4/24']
|
||||
self.load_eth_ifc_fixture()
|
||||
self._execute_module(changed=True, commands=commands)
|
Loading…
Add table
Add a link
Reference in a new issue