ansible/test/units/modules/network/mlnxos/test_mlnxos_protocols.py
Samer Deeb ad73bda323 Add new module mlnxos_protocol for enabling disabling protocols on MLNX-OS Mellanox network devices (#34286)
* Add new module mlnxos_protocol for enabling disabling protocols on
MLNX-OS Mellanox network devices

Signed-off-by: Samer Deeb <samerd@mellanox.com>

* Fix Test Class name

* Fix IP routing protocol support

Signed-off-by: Samer Deeb <samerd@mellanox.com>

* Add missing support for check_mode, and Fix documentation

Signed-off-by: Samer Deeb <samerd@mellanox.com>
2018-01-08 14:30:30 +00:00

134 lines
4.6 KiB
Python

#
# 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_protocol
from units.modules.utils import set_module_args
from .mlnxos_module import TestMlnxosModule, load_fixture
class TestMlnxosProtocolModule(TestMlnxosModule):
module = mlnxos_protocol
def setUp(self):
super(TestMlnxosProtocolModule, self).setUp()
self.mock_get_config = patch.object(
mlnxos_protocol.MlnxosProtocolModule,
"_get_protocols")
self.get_config = self.mock_get_config.start()
self.mock_get_ip_config = patch.object(
mlnxos_protocol.MlnxosProtocolModule,
"_get_ip_routing")
self.get_ip_config = self.mock_get_ip_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(TestMlnxosProtocolModule, self).tearDown()
self.mock_get_config.stop()
self.mock_load_config.stop()
def load_fixtures(self, commands=None, transport='cli'):
config_file = 'mlnxos_protocols_show.cfg'
self.get_config.return_value = load_fixture(config_file)
self.load_config.return_value = None
self.get_ip_config.return_value = "IP routing: enabled"
def test_mlag_enable(self):
set_module_args(dict(mlag='enabled'))
commands = ['protocol mlag']
self.execute_module(changed=True, commands=commands)
def test_mlag_disable(self):
set_module_args(dict(mlag='disabled'))
self.execute_module(changed=False)
def test_magp_enable(self):
set_module_args(dict(magp='enabled'))
commands = ['protocol magp']
self.execute_module(changed=True, commands=commands)
def test_magp_disable(self):
set_module_args(dict(magp='disabled'))
self.execute_module(changed=False)
def test_spanning_tree_enable(self):
set_module_args(dict(spanning_tree='enabled'))
self.execute_module(changed=False)
def test_spanning_tree_disable(self):
set_module_args(dict(spanning_tree='disabled'))
commands = ['no spanning-tree']
self.execute_module(changed=True, commands=commands)
def test_dcb_pfc_enable(self):
set_module_args(dict(dcb_pfc='enabled'))
commands = ['dcb priority-flow-control enable force']
self.execute_module(changed=True, commands=commands)
def test_dcb_pfc_disable(self):
set_module_args(dict(dcb_pfc='disabled'))
self.execute_module(changed=False)
def test_igmp_snooping_enable(self):
set_module_args(dict(igmp_snooping='enabled'))
commands = ['ip igmp snooping']
self.execute_module(changed=True, commands=commands)
def test_igmp_snooping_disable(self):
set_module_args(dict(igmp_snooping='disabled'))
self.execute_module(changed=False)
def test_lacp_enable(self):
set_module_args(dict(lacp='enabled'))
commands = ['lacp']
self.execute_module(changed=True, commands=commands)
def test_lacp_disable(self):
set_module_args(dict(lacp='disabled'))
self.execute_module(changed=False)
def test_ip_routing_enable(self):
set_module_args(dict(ip_routing='enabled'))
self.execute_module(changed=False)
def test_ip_routing_disable(self):
set_module_args(dict(ip_routing='disabled'))
commands = ['no ip routing']
self.execute_module(changed=True, commands=commands)
def test_lldp_enable(self):
set_module_args(dict(lldp='enabled'))
commands = ['lldp']
self.execute_module(changed=True, commands=commands)
def test_lldp_disable(self):
set_module_args(dict(lldp='disabled'))
self.execute_module(changed=False)
def test_bgp_enable(self):
set_module_args(dict(bgp='enabled'))
commands = ['protocol bgp']
self.execute_module(changed=True, commands=commands)
def test_bgp_disable(self):
set_module_args(dict(bgp='disabled'))
self.execute_module(changed=False)
def test_ospf_enable(self):
set_module_args(dict(ospf='enabled'))
commands = ['protocol ospf']
self.execute_module(changed=True, commands=commands)
def test_ospf_disable(self):
set_module_args(dict(ospf='disabled'))
self.execute_module(changed=False)