summaryrefslogtreecommitdiff
path: root/test/units/modules/network/slxos
diff options
context:
space:
mode:
Diffstat (limited to 'test/units/modules/network/slxos')
-rw-r--r--test/units/modules/network/slxos/fixtures/show_interface_ethernet_0_2_switchport6
-rw-r--r--test/units/modules/network/slxos/fixtures/show_interface_ethernet_0_3_switchport0
-rw-r--r--test/units/modules/network/slxos/fixtures/show_interface_ethernet_0_4_switchport6
-rw-r--r--test/units/modules/network/slxos/fixtures/show_version18
-rw-r--r--test/units/modules/network/slxos/fixtures/show_vlan_brief17
-rw-r--r--test/units/modules/network/slxos/fixtures/slxos_config_config.cfg31
-rw-r--r--test/units/modules/network/slxos/fixtures/slxos_config_src.cfg11
-rw-r--r--test/units/modules/network/slxos/fixtures/slxos_facts_show_inventory_chassis5
-rw-r--r--test/units/modules/network/slxos/fixtures/slxos_facts_show_running-config1
-rw-r--r--test/units/modules/network/slxos/fixtures/slxos_facts_show_version18
-rw-r--r--test/units/modules/network/slxos/slxos_module.py87
-rw-r--r--test/units/modules/network/slxos/test_slxos_command.py121
-rw-r--r--test/units/modules/network/slxos/test_slxos_config.py195
-rw-r--r--test/units/modules/network/slxos/test_slxos_facts.py61
-rw-r--r--test/units/modules/network/slxos/test_slxos_interface.py155
-rw-r--r--test/units/modules/network/slxos/test_slxos_l2_interface.py171
-rw-r--r--test/units/modules/network/slxos/test_slxos_l3_interface.py102
-rw-r--r--test/units/modules/network/slxos/test_slxos_linkagg.py159
-rw-r--r--test/units/modules/network/slxos/test_slxos_lldp.py95
-rw-r--r--test/units/modules/network/slxos/test_slxos_vlan.py144
20 files changed, 0 insertions, 1403 deletions
diff --git a/test/units/modules/network/slxos/fixtures/show_interface_ethernet_0_2_switchport b/test/units/modules/network/slxos/fixtures/show_interface_ethernet_0_2_switchport
deleted file mode 100644
index b43c357021..0000000000
--- a/test/units/modules/network/slxos/fixtures/show_interface_ethernet_0_2_switchport
+++ /dev/null
@@ -1,6 +0,0 @@
- Interface name : Ethernet 0/2
- Switchport mode : access
- Ingress filter : enable
- Acceptable frame types : vlan-untagged only
- Default Vlan : 1
- Active Vlans : 1
diff --git a/test/units/modules/network/slxos/fixtures/show_interface_ethernet_0_3_switchport b/test/units/modules/network/slxos/fixtures/show_interface_ethernet_0_3_switchport
deleted file mode 100644
index e69de29bb2..0000000000
--- a/test/units/modules/network/slxos/fixtures/show_interface_ethernet_0_3_switchport
+++ /dev/null
diff --git a/test/units/modules/network/slxos/fixtures/show_interface_ethernet_0_4_switchport b/test/units/modules/network/slxos/fixtures/show_interface_ethernet_0_4_switchport
deleted file mode 100644
index 63a761bdce..0000000000
--- a/test/units/modules/network/slxos/fixtures/show_interface_ethernet_0_4_switchport
+++ /dev/null
@@ -1,6 +0,0 @@
- Interface name : Ethernet 0/4
- Switchport mode : trunk
- Ingress filter : enable
- Acceptable frame types : vlan-tagged only
- Native Vlan : 1
- Active Vlans : 1,22,200
diff --git a/test/units/modules/network/slxos/fixtures/show_version b/test/units/modules/network/slxos/fixtures/show_version
deleted file mode 100644
index 0d648378ac..0000000000
--- a/test/units/modules/network/slxos/fixtures/show_version
+++ /dev/null
@@ -1,18 +0,0 @@
-SLX-OS Operating System Software
-SLX-OS Operating System Version: 17s.1.02
-Copyright (c) 1995-2018 Brocade Communications Systems, Inc.
-Firmware name: 17s.1.02
-Build Time: 00:06:59 Sep 28, 2017
-Install Time: 15:58:29 Feb 9, 2018
-Kernel: 2.6.34.6
-Host Version: Ubuntu 14.04 LTS
-Host Kernel: Linux 3.14.17
-
-Control Processor: QEMU Virtual CPU version 2.0.0
-
-System Uptime: 34days 4hrs 41mins 53secs
-
-Slot Name Primary/Secondary Versions Status
----------------------------------------------------------------------------
-SW/0 SLX-OS 17s.1.02 ACTIVE*
- 17s.1.02
diff --git a/test/units/modules/network/slxos/fixtures/show_vlan_brief b/test/units/modules/network/slxos/fixtures/show_vlan_brief
deleted file mode 100644
index 3a49c5a7a4..0000000000
--- a/test/units/modules/network/slxos/fixtures/show_vlan_brief
+++ /dev/null
@@ -1,17 +0,0 @@
-Total Number of VLANs configured : 2
-VLAN Name State Config status Ports Classification
-(R)-RSPAN (u)-Untagged
- (t)-Tagged
-================ =============== ========================== =============== ====================
-1 default ACTIVE Static Eth 1/5(t)
-
-22 VLAN0022 INACTIVE(no member port) Static
-
-5 VLAN0005 ACTIVE Static Tu 61442(t) vni 5
- Tu 61443(t) vni 5
-
-200 VLAN0200 ACTIVE Dynamic (MVRP) Po 60(t)
-
-1000 VLAN1000 ACTIVE Dynamic (EP tracking) Po 60(t)
-
-4090 VLAN4090 INACTIVE(no member port) Static
diff --git a/test/units/modules/network/slxos/fixtures/slxos_config_config.cfg b/test/units/modules/network/slxos/fixtures/slxos_config_config.cfg
deleted file mode 100644
index 48286bf1e5..0000000000
--- a/test/units/modules/network/slxos/fixtures/slxos_config_config.cfg
+++ /dev/null
@@ -1,31 +0,0 @@
-!
-hostname router
-!
-interface Ethernet 0/0
- ip address 1.2.3.4 255.255.255.0
- description test string
-!
-interface Ethernet 0/1
- ip address 6.7.8.9 255.255.255.0
- description test string
- shutdown
-!
-interface Ethernet 0/10
- channel-group 20 mode active
- description Channel Group Member
-!
-interface Ethernet 0/11
- channel-group 20 mode active
- description Channel Group Member
-!
-interface Port-channel 20
-!
-interface Ethernet 0/9
- ip address 172.16.128.99 255.255.255.0
- ipv6 address dead::beaf/64
- description Bleh
-!
-protocol lldp
- system-description An Extreme SLX Device
- disable
-!
diff --git a/test/units/modules/network/slxos/fixtures/slxos_config_src.cfg b/test/units/modules/network/slxos/fixtures/slxos_config_src.cfg
deleted file mode 100644
index 1b642f8b4e..0000000000
--- a/test/units/modules/network/slxos/fixtures/slxos_config_src.cfg
+++ /dev/null
@@ -1,11 +0,0 @@
-!
-hostname foo
-!
-interface Ethernet 0/0
- no ip address
-!
-interface Ethernet 0/1
- ip address 6.7.8.9 255.255.255.0
- description test string
- shutdown
-!
diff --git a/test/units/modules/network/slxos/fixtures/slxos_facts_show_inventory_chassis b/test/units/modules/network/slxos/fixtures/slxos_facts_show_inventory_chassis
deleted file mode 100644
index 7908951251..0000000000
--- a/test/units/modules/network/slxos/fixtures/slxos_facts_show_inventory_chassis
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
-NAME: Chassis DESCR:System Chassis
-SID:BR-SLX9140 SwitchType:3001
-PN:84-1002952-01 SN:EXH3349M005
diff --git a/test/units/modules/network/slxos/fixtures/slxos_facts_show_running-config b/test/units/modules/network/slxos/fixtures/slxos_facts_show_running-config
deleted file mode 100644
index 3d7d017b06..0000000000
--- a/test/units/modules/network/slxos/fixtures/slxos_facts_show_running-config
+++ /dev/null
@@ -1 +0,0 @@
-switch-attributes host-name DC2LEAF2
diff --git a/test/units/modules/network/slxos/fixtures/slxos_facts_show_version b/test/units/modules/network/slxos/fixtures/slxos_facts_show_version
deleted file mode 100644
index 0d648378ac..0000000000
--- a/test/units/modules/network/slxos/fixtures/slxos_facts_show_version
+++ /dev/null
@@ -1,18 +0,0 @@
-SLX-OS Operating System Software
-SLX-OS Operating System Version: 17s.1.02
-Copyright (c) 1995-2018 Brocade Communications Systems, Inc.
-Firmware name: 17s.1.02
-Build Time: 00:06:59 Sep 28, 2017
-Install Time: 15:58:29 Feb 9, 2018
-Kernel: 2.6.34.6
-Host Version: Ubuntu 14.04 LTS
-Host Kernel: Linux 3.14.17
-
-Control Processor: QEMU Virtual CPU version 2.0.0
-
-System Uptime: 34days 4hrs 41mins 53secs
-
-Slot Name Primary/Secondary Versions Status
----------------------------------------------------------------------------
-SW/0 SLX-OS 17s.1.02 ACTIVE*
- 17s.1.02
diff --git a/test/units/modules/network/slxos/slxos_module.py b/test/units/modules/network/slxos/slxos_module.py
deleted file mode 100644
index 8cd482ed11..0000000000
--- a/test/units/modules/network/slxos/slxos_module.py
+++ /dev/null
@@ -1,87 +0,0 @@
-# (c) 2018 Extreme Networks Inc.
-#
-# This file is part of Ansible
-#
-# Ansible is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# Ansible is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
-#
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
-
-import os
-import json
-
-from units.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase
-
-
-fixture_path = os.path.join(os.path.dirname(__file__), 'fixtures')
-fixture_data = {}
-
-
-def load_fixture(name):
- path = os.path.join(fixture_path, name)
-
- if path in fixture_data:
- return fixture_data[path]
-
- with open(path) as file_desc:
- data = file_desc.read()
-
- try:
- data = json.loads(data)
- except Exception:
- pass
-
- fixture_data[path] = data
- return data
-
-
-class TestSlxosModule(ModuleTestCase):
-
- def execute_module(self, failed=False, changed=False, commands=None, sort=True, defaults=False):
-
- self.load_fixtures(commands)
-
- 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:
- if sort:
- self.assertEqual(sorted(commands), sorted(result['commands']), result['commands'])
- else:
- self.assertEqual(commands, result['commands'], result['commands'])
-
- return result
-
- def failed(self):
- with self.assertRaises(AnsibleFailJson) as exc:
- self.module.main()
-
- result = exc.exception.args[0]
- self.assertTrue(result['failed'], result)
- return result
-
- def changed(self, changed=False):
- with self.assertRaises(AnsibleExitJson) as exc:
- self.module.main()
-
- result = exc.exception.args[0]
- self.assertEqual(result['changed'], changed, result)
- return result
-
- def load_fixtures(self, commands=None):
- pass
diff --git a/test/units/modules/network/slxos/test_slxos_command.py b/test/units/modules/network/slxos/test_slxos_command.py
deleted file mode 100644
index 3e7de3c6f1..0000000000
--- a/test/units/modules/network/slxos/test_slxos_command.py
+++ /dev/null
@@ -1,121 +0,0 @@
-#
-# (c) 2018 Extreme Networks Inc.
-#
-# This file is part of Ansible
-#
-# Ansible is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# Ansible is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
-#
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
-
-import json
-
-from units.compat.mock import patch
-from units.modules.utils import set_module_args
-from ansible.modules.network.slxos import slxos_command
-from .slxos_module import TestSlxosModule, load_fixture
-
-
-class TestSlxosCommandModule(TestSlxosModule):
-
- module = slxos_command
-
- def setUp(self):
- super(TestSlxosCommandModule, self).setUp()
-
- self.mock_run_commands = patch('ansible.modules.network.slxos.slxos_command.run_commands')
- self.run_commands = self.mock_run_commands.start()
-
- def tearDown(self):
- super(TestSlxosCommandModule, self).tearDown()
- self.mock_run_commands.stop()
-
- def load_fixtures(self, commands=None):
-
- def load_from_file(*args, **kwargs):
- module, commands = args
- output = list()
-
- for item in commands:
- try:
- obj = json.loads(item['command'])
- command = obj['command']
- except ValueError:
- command = item['command']
- filename = str(command).replace(' ', '_')
- output.append(load_fixture(filename))
- return output
-
- self.run_commands.side_effect = load_from_file
-
- def test_slxos_command_simple(self):
- set_module_args(dict(commands=['show version']))
- result = self.execute_module()
- self.assertEqual(len(result['stdout']), 1)
- self.assertTrue(result['stdout'][0].startswith('SLX-OS Operating System Software'))
-
- def test_slxos_command_multiple(self):
- set_module_args(dict(commands=['show version', 'show version']))
- result = self.execute_module()
- self.assertEqual(len(result['stdout']), 2)
- self.assertTrue(result['stdout'][0].startswith('SLX-OS Operating System Software'))
-
- def test_slxos_command_wait_for(self):
- wait_for = 'result[0] contains "SLX-OS Operating System Software"'
- set_module_args(dict(commands=['show version'], wait_for=wait_for))
- self.execute_module()
-
- def test_slxos_command_wait_for_fails(self):
- wait_for = 'result[0] contains "test string"'
- set_module_args(dict(commands=['show version'], wait_for=wait_for))
- self.execute_module(failed=True)
- self.assertEqual(self.run_commands.call_count, 10)
-
- def test_slxos_command_retries(self):
- wait_for = 'result[0] contains "test string"'
- set_module_args(dict(commands=['show version'], wait_for=wait_for, retries=2))
- self.execute_module(failed=True)
- self.assertEqual(self.run_commands.call_count, 2)
-
- def test_slxos_command_match_any(self):
- wait_for = ['result[0] contains "SLX-OS"',
- 'result[0] contains "test string"']
- set_module_args(dict(commands=['show version'], wait_for=wait_for, match='any'))
- self.execute_module()
-
- def test_slxos_command_match_all(self):
- wait_for = ['result[0] contains "SLX-OS"',
- 'result[0] contains "SLX-OS Operating System Software"']
- set_module_args(dict(commands=['show version'], wait_for=wait_for, match='all'))
- self.execute_module()
-
- def test_slxos_command_match_all_failure(self):
- wait_for = ['result[0] contains "SLX-OS Operating System Software"',
- 'result[0] contains "test string"']
- commands = ['show version', 'show version']
- set_module_args(dict(commands=commands, wait_for=wait_for, match='all'))
- self.execute_module(failed=True)
-
- def test_slxos_command_configure_error(self):
- commands = ['configure terminal']
- set_module_args({
- 'commands': commands,
- '_ansible_check_mode': True,
- })
- result = self.execute_module(failed=True)
- self.assertEqual(
- result['msg'],
- 'slxos_command does not support running config mode commands. '
- 'Please use slxos_config instead'
- )
diff --git a/test/units/modules/network/slxos/test_slxos_config.py b/test/units/modules/network/slxos/test_slxos_config.py
deleted file mode 100644
index e37f547dff..0000000000
--- a/test/units/modules/network/slxos/test_slxos_config.py
+++ /dev/null
@@ -1,195 +0,0 @@
-#
-# (c) 2018 Extreme Networks Inc.
-#
-# This file is part of Ansible
-#
-# Ansible is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# Ansible is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
-#
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
-
-from units.compat.mock import patch
-from units.modules.utils import set_module_args
-from ansible.modules.network.slxos import slxos_config
-from .slxos_module import TestSlxosModule, load_fixture
-
-
-class TestSlxosConfigModule(TestSlxosModule):
-
- module = slxos_config
-
- def setUp(self):
- super(TestSlxosConfigModule, self).setUp()
-
- self.mock_get_config = patch('ansible.modules.network.slxos.slxos_config.get_config')
- self.get_config = self.mock_get_config.start()
-
- self.mock_load_config = patch('ansible.modules.network.slxos.slxos_config.load_config')
- self.load_config = self.mock_load_config.start()
-
- self.mock_run_commands = patch('ansible.modules.network.slxos.slxos_config.run_commands')
- self.run_commands = self.mock_run_commands.start()
-
- def tearDown(self):
- super(TestSlxosConfigModule, self).tearDown()
- self.mock_get_config.stop()
- self.mock_load_config.stop()
- self.mock_run_commands.stop()
-
- def load_fixtures(self, commands=None):
- config_file = 'slxos_config_config.cfg'
- self.get_config.return_value = load_fixture(config_file)
- self.load_config.return_value = None
-
- def test_slxos_config_unchanged(self):
- src = load_fixture('slxos_config_config.cfg')
- set_module_args(dict(src=src))
- self.execute_module()
-
- def test_slxos_config_src(self):
- src = load_fixture('slxos_config_src.cfg')
- set_module_args(dict(src=src))
- commands = ['hostname foo', 'interface Ethernet 0/0',
- 'no ip address']
- self.execute_module(changed=True, commands=commands)
-
- def test_slxos_config_backup(self):
- set_module_args(dict(backup=True))
- result = self.execute_module()
- self.assertIn('__backup__', result)
-
- def test_slxos_config_save_always(self):
- self.run_commands.return_value = "Hostname foo"
- set_module_args(dict(save_when='always'))
- self.execute_module(changed=True)
- self.assertEqual(self.run_commands.call_count, 1)
- self.assertEqual(self.get_config.call_count, 0)
- self.assertEqual(self.load_config.call_count, 0)
- args = self.run_commands.call_args[0][1]
- self.assertIn('copy running-config startup-config', args['command'])
-
- def test_slxos_config_save_changed_true(self):
- src = load_fixture('slxos_config_src.cfg')
- set_module_args(dict(src=src, save_when='changed'))
- commands = ['hostname foo', 'interface Ethernet 0/0', 'no ip address']
- self.execute_module(changed=True, commands=commands)
- self.assertEqual(self.run_commands.call_count, 1)
- self.assertEqual(self.get_config.call_count, 1)
- self.assertEqual(self.load_config.call_count, 1)
- args = self.run_commands.call_args[0][1]
- self.assertIn('copy running-config startup-config', args['command'])
-
- def test_slxos_config_save_changed_false(self):
- set_module_args(dict(save_when='changed'))
- self.execute_module(changed=False)
- self.assertEqual(self.run_commands.call_count, 0)
- self.assertEqual(self.get_config.call_count, 0)
- self.assertEqual(self.load_config.call_count, 0)
-
- def test_slxos_config_lines_wo_parents(self):
- set_module_args(dict(lines=['hostname foo']))
- commands = ['hostname foo']
- self.execute_module(changed=True, commands=commands)
-
- def test_slxos_config_lines_w_parents(self):
- set_module_args(dict(lines=['shutdown'], parents=['interface Ethernet 0/0']))
- commands = ['interface Ethernet 0/0', 'shutdown']
- self.execute_module(changed=True, commands=commands)
-
- def test_slxos_config_before(self):
- set_module_args(dict(lines=['hostname foo'], before=['test1', 'test2']))
- commands = ['test1', 'test2', 'hostname foo']
- self.execute_module(changed=True, commands=commands, sort=False)
-
- def test_slxos_config_after(self):
- set_module_args(dict(lines=['hostname foo'], after=['test1', 'test2']))
- commands = ['hostname foo', 'test1', 'test2']
- self.execute_module(changed=True, commands=commands, sort=False)
-
- def test_slxos_config_before_after_no_change(self):
- set_module_args(dict(lines=['hostname router'],
- before=['test1', 'test2'],
- after=['test3', 'test4']))
- self.execute_module()
-
- def test_slxos_config_config(self):
- config = 'hostname localhost'
- set_module_args(dict(lines=['hostname router'], config=config))
- commands = ['hostname router']
- self.execute_module(changed=True, commands=commands)
-
- def test_slxos_config_replace_block(self):
- lines = ['description test string', 'test string']
- parents = ['interface Ethernet 0/0']
- set_module_args(dict(lines=lines, replace='block', parents=parents))
- commands = parents + lines
- self.execute_module(changed=True, commands=commands)
-
- def test_slxos_config_match_none(self):
- lines = ['hostname router']
- set_module_args(dict(lines=lines, match='none'))
- self.execute_module(changed=True, commands=lines)
-
- def test_slxos_config_match_none_parents(self):
- lines = ['ip address 1.2.3.4 255.255.255.0', 'description test string']
- parents = ['interface Ethernet 0/0']
- set_module_args(dict(lines=lines, parents=parents, match='none'))
- commands = parents + lines
- self.execute_module(changed=True, commands=commands, sort=False)
-
- def test_slxos_config_match_strict(self):
- lines = ['ip address 1.2.3.4 255.255.255.0', 'description test string',
- 'shutdown']
- parents = ['interface Ethernet 0/0']
- set_module_args(dict(lines=lines, parents=parents, match='strict'))
- commands = parents + ['shutdown']
- self.execute_module(changed=True, commands=commands, sort=False)
-
- def test_slxos_config_match_exact(self):
- lines = ['ip address 1.2.3.4 255.255.255.0', 'description test string',
- 'shutdown']
- parents = ['interface Ethernet 0/0']
- set_module_args(dict(lines=lines, parents=parents, match='exact'))
- commands = parents + lines
- self.execute_module(changed=True, commands=commands, sort=False)
-
- def test_slxos_config_src_and_lines_fails(self):
- args = dict(src='foo', lines='foo')
- set_module_args(args)
- self.execute_module(failed=True)
-
- def test_slxos_config_src_and_parents_fails(self):
- args = dict(src='foo', parents='foo')
- set_module_args(args)
- self.execute_module(failed=True)
-
- def test_slxos_config_match_exact_requires_lines(self):
- args = dict(match='exact')
- set_module_args(args)
- self.execute_module(failed=True)
-
- def test_slxos_config_match_strict_requires_lines(self):
- args = dict(match='strict')
- set_module_args(args)
- self.execute_module(failed=True)
-
- def test_slxos_config_replace_block_requires_lines(self):
- args = dict(replace='block')
- set_module_args(args)
- self.execute_module(failed=True)
-
- def test_slxos_config_replace_config_requires_src(self):
- args = dict(replace='config')
- set_module_args(args)
- self.execute_module(failed=True)
diff --git a/test/units/modules/network/slxos/test_slxos_facts.py b/test/units/modules/network/slxos/test_slxos_facts.py
deleted file mode 100644
index 4859903e81..0000000000
--- a/test/units/modules/network/slxos/test_slxos_facts.py
+++ /dev/null
@@ -1,61 +0,0 @@
-#
-# (c) 2018 Extreme Networks Inc.
-#
-# This file is part of Ansible
-#
-# Ansible is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# Ansible is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
-#
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
-
-from units.compat.mock import patch
-from units.modules.utils import set_module_args
-from ansible.modules.network.slxos import slxos_facts
-from .slxos_module import TestSlxosModule, load_fixture
-
-
-class TestSlxosFactsModule(TestSlxosModule):
-
- module = slxos_facts
-
- def setUp(self):
- super(TestSlxosFactsModule, self).setUp()
- self.mock_run_commands = patch('ansible.modules.network.slxos.slxos_facts.run_commands')
- self.run_commands = self.mock_run_commands.start()
-
- def tearDown(self):
- super(TestSlxosFactsModule, self).tearDown()
- self.mock_run_commands.stop()
-
- def load_fixtures(self, commands=None):
- def load_from_file(*args, **kwargs):
- commands = args[1]
- output = list()
-
- for command in commands:
- filename = str(command).split(' | ')[0].replace(' ', '_')
- output.append(load_fixture('slxos_facts_%s' % filename))
- return output
-
- self.run_commands.side_effect = load_from_file
-
- def test_slxos_facts(self):
- set_module_args(dict(gather_subset='default'))
- result = self.execute_module()
- self.assertEqual(
- result['ansible_facts']['ansible_net_model'], 'BR-SLX9140'
- )
- self.assertEqual(
- result['ansible_facts']['ansible_net_serialnum'], 'EXH3349M005'
- )
diff --git a/test/units/modules/network/slxos/test_slxos_interface.py b/test/units/modules/network/slxos/test_slxos_interface.py
deleted file mode 100644
index 4814ec0f54..0000000000
--- a/test/units/modules/network/slxos/test_slxos_interface.py
+++ /dev/null
@@ -1,155 +0,0 @@
-#
-# (c) 2018 Extreme Networks Inc.
-#
-# This file is part of Ansible
-#
-# Ansible is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# Ansible is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
-#
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
-
-import re
-
-from units.compat.mock import patch
-from units.modules.utils import set_module_args
-from ansible.modules.network.slxos import slxos_interface
-from .slxos_module import TestSlxosModule, load_fixture
-
-
-class TestSlxosInterfaceModule(TestSlxosModule):
- module = slxos_interface
-
- def setUp(self):
- super(TestSlxosInterfaceModule, self).setUp()
- self._patch_get_config = patch(
- 'ansible.modules.network.slxos.slxos_interface.get_config'
- )
- self._patch_load_config = patch(
- 'ansible.modules.network.slxos.slxos_interface.load_config'
- )
- self._patch_exec_command = patch(
- 'ansible.modules.network.slxos.slxos_interface.exec_command'
- )
-
- self._get_config = self._patch_get_config.start()
- self._load_config = self._patch_load_config.start()
- self._exec_command = self._patch_exec_command.start()
-
- def tearDown(self):
- super(TestSlxosInterfaceModule, self).tearDown()
- self._patch_get_config.stop()
- self._patch_load_config.stop()
- self._patch_exec_command.stop()
-
- def load_fixtures(self, commands=None):
- config_file = 'slxos_config_config.cfg'
- self._get_config.return_value = load_fixture(config_file)
- self._load_config.return_value = None
-
- def test_slxos_interface_description(self, *args, **kwargs):
- set_module_args(dict(
- name='Ethernet 0/2',
- description='show version'
- ))
- result = self.execute_module(changed=True)
- self.assertEqual(
- result,
- {
- 'commands': [
- 'interface Ethernet 0/2',
- 'description show version'
- ],
- 'changed': True
- }
- )
-
- def test_slxos_interface_speed(self, *args, **kwargs):
- set_module_args(dict(
- name='Ethernet 0/2',
- speed=1000
- ))
- result = self.execute_module(changed=True)
- self.assertEqual(
- result,
- {
- 'commands': [
- 'interface Ethernet 0/2',
- 'speed 1000'
- ],
- 'changed': True
- }
- )
-
- def test_slxos_interface_mtu(self, *args, **kwargs):
- set_module_args(dict(
- name='Ethernet 0/2',
- mtu=1548
- ))
- result = self.execute_module(changed=True)
- self.assertEqual(
- result,
- {
- 'commands': [
- 'interface Ethernet 0/2',
- 'mtu 1548'
- ],
- 'changed': True
- }
- )
-
- def test_slxos_interface_mtu_out_of_range(self, *args, **kwargs):
- set_module_args(dict(
- name='Ethernet 0/2',
- mtu=15000
- ))
- result = self.execute_module(failed=True)
- self.assertEqual(
- result,
- {
- 'msg': 'mtu must be between 1548 and 9216',
- 'failed': True
- }
- )
-
- def test_slxos_interface_enabled(self, *args, **kwargs):
- set_module_args(dict(
- name='Ethernet 0/1',
- enabled=True
- ))
- result = self.execute_module(changed=True)
- self.assertEqual(
- result,
- {
- 'commands': [
- 'interface Ethernet 0/1',
- 'no shutdown'
- ],
- 'changed': True
- }
- )
-
- def test_slxos_interface_invalid_argument(self, *args, **kwargs):
- set_module_args(dict(
- name='Ethernet 0/1',
- shawshank='Redemption'
- ))
- result = self.execute_module(failed=True)
- self.assertEqual(result['failed'], True)
- self.assertTrue(re.match(
- r'Unsupported parameters for \((basic.py|basic.pyc)\) module: '
- 'shawshank Supported parameters include: aggregate, '
- 'delay, description, enabled, mtu, name, neighbors, '
- 'rx_rate, speed, state, tx_rate',
- result['msg']
- ))
diff --git a/test/units/modules/network/slxos/test_slxos_l2_interface.py b/test/units/modules/network/slxos/test_slxos_l2_interface.py
deleted file mode 100644
index 929552a47a..0000000000
--- a/test/units/modules/network/slxos/test_slxos_l2_interface.py
+++ /dev/null
@@ -1,171 +0,0 @@
-#
-# (c) 2018 Extreme Networks Inc.
-#
-# This file is part of Ansible
-#
-# Ansible is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# Ansible is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
-#
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
-
-import re
-
-from units.compat.mock import patch
-from units.modules.utils import set_module_args
-from ansible.modules.network.slxos import slxos_l2_interface
-from .slxos_module import TestSlxosModule, load_fixture
-
-
-class TestSlxosL2InterfaceModule(TestSlxosModule):
- module = slxos_l2_interface
-
- def setUp(self):
- super(TestSlxosL2InterfaceModule, self).setUp()
- self._patch_get_config = patch(
- 'ansible.modules.network.slxos.slxos_l2_interface.get_config'
- )
- self._patch_load_config = patch(
- 'ansible.modules.network.slxos.slxos_l2_interface.load_config'
- )
- self._patch_run_commands = patch(
- 'ansible.modules.network.slxos.slxos_l2_interface.run_commands'
- )
-
- self._get_config = self._patch_get_config.start()
- self._load_config = self._patch_load_config.start()
- self._run_commands = self._patch_run_commands.start()
- self._run_commands.side_effect = self.run_commands_load_fixtures
-
- def run_commands_load_fixtures(self, module, commands, *args, **kwargs):
- return self.load_fixtures(
- commands,
- destination=self._run_commands,
- return_values=True
- )
-
- def tearDown(self):
- super(TestSlxosL2InterfaceModule, self).tearDown()
- self._patch_get_config.stop()
- self._patch_load_config.stop()
- self._patch_run_commands.stop()
-
- def load_fixtures(self, commands=None, destination=None, return_values=False):
- side_effects = []
-
- if not destination:
- destination = self._get_config
-
- if not commands:
- commands = ['slxos_config_config.cfg']
-
- for command in commands:
- filename = str(command).replace(' ', '_')
- filename = str(filename).replace('/', '_')
- side_effects.append(load_fixture(filename))
-
- if return_values is True:
- return side_effects
-
- destination.side_effect = side_effects
- return None
-
- def test_slxos_l2_interface_access_vlan(self, *args, **kwargs):
- set_module_args(dict(
- name='Ethernet 0/2',
- mode='access',
- access_vlan=200,
- ))
- result = self.execute_module(changed=True)
- self.assertEqual(
- result,
- {
- 'commands': [
- 'interface ethernet 0/2',
- 'switchport access vlan 200'
- ],
- 'changed': True,
- 'warnings': []
- }
- )
-
- def test_slxos_l2_interface_vlan_does_not_exist(self, *args, **kwargs):
- set_module_args(dict(
- name='Ethernet 0/2',
- mode='access',
- access_vlan=10,
- ))
- result = self.execute_module(failed=True)
- self.assertEqual(
- result,
- {
- 'msg': 'You are trying to configure a VLAN on an interface '
- 'that\ndoes not exist on the switch yet!',
- 'failed': True,
- 'vlan': '10'
- }
- )
-
- def test_slxos_l2_interface_incorrect_state(self, *args, **kwargs):
- set_module_args(dict(
- name='Ethernet 0/3',
- mode='access',
- access_vlan=10,
- ))
- result = self.execute_module(failed=True)
- self.assertEqual(
- result,
- {
- 'msg': 'Ensure interface is configured to be a L2\nport first '
- 'before using this module. You can use\nthe slxos_'
- 'interface module for this.',
- 'failed': True
- }
- )
-
- def test_slxos_l2_interface_trunk(self, *args, **kwargs):
- set_module_args(dict(
- name='Ethernet 0/4',
- mode='trunk',
- native_vlan='22',
- trunk_allowed_vlans='200,22'
- ))
- result = self.execute_module(changed=True)
- self.assertEqual(
- result,
- {
- 'commands': [
- 'interface ethernet 0/4',
- 'switchport trunk allowed vlan add 200,22',
- 'switchport trunk native vlan 22'
- ],
- 'changed': True,
- 'warnings': []
- }
- )
-
- def test_slxos_l2_interface_invalid_argument(self, *args, **kwargs):
- set_module_args(dict(
- name='Ethernet 0/2',
- mode='access',
- access_vlan=10,
- shawshank='Redemption'
- ))
- result = self.execute_module(failed=True)
- self.assertEqual(result['failed'], True)
- self.assertTrue(re.match(
- r'Unsupported parameters for \((basic.py|basic.pyc)\) module: '
- 'shawshank Supported parameters include: access_vlan, aggregate, '
- 'mode, name, native_vlan, state, trunk_allowed_vlans, trunk_vlans',
- result['msg']
- ))
diff --git a/test/units/modules/network/slxos/test_slxos_l3_interface.py b/test/units/modules/network/slxos/test_slxos_l3_interface.py
deleted file mode 100644
index dd4826c6df..0000000000
--- a/test/units/modules/network/slxos/test_slxos_l3_interface.py
+++ /dev/null
@@ -1,102 +0,0 @@
-#
-# (c) 2018 Extreme Networks Inc.
-#
-# This file is part of Ansible
-#
-# Ansible is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# Ansible is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
-#
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
-
-import re
-
-from units.compat.mock import patch
-from units.modules.utils import set_module_args
-from ansible.modules.network.slxos import slxos_l3_interface
-from .slxos_module import TestSlxosModule, load_fixture
-
-
-class TestSlxosL3InterfaceModule(TestSlxosModule):
- module = slxos_l3_interface
-
- def setUp(self):
- super(TestSlxosL3InterfaceModule, self).setUp()
- self._patch_get_config = patch(
- 'ansible.modules.network.slxos.slxos_l3_interface.get_config'
- )
- self._patch_load_config = patch(
- 'ansible.modules.network.slxos.slxos_l3_interface.load_config'
- )
-
- self._get_config = self._patch_get_config.start()
- self._load_config = self._patch_load_config.start()
-
- def tearDown(self):
- super(TestSlxosL3InterfaceModule, self).tearDown()
- self._patch_get_config.stop()
- self._patch_load_config.stop()
-
- def load_fixtures(self, commands=None):
- config_file = 'slxos_config_config.cfg'
- self._get_config.return_value = load_fixture(config_file)
- self._load_config.return_value = None
-
- def test_slxos_l3_interface_ipv4_address(self, *args, **kwargs):
- set_module_args(dict(
- name='Ethernet 0/2',
- ipv4='192.168.4.1/24'
- ))
- result = self.execute_module(changed=True)
- self.assertEqual(
- result,
- {
- 'commands': [
- 'interface Ethernet 0/2',
- 'ip address 192.168.4.1/24'
- ],
- 'changed': True
- }
- )
-
- def test_slxos_l3_interface_absent(self, *args, **kwargs):
- set_module_args(dict(
- name='Ethernet 0/9',
- state='absent'
- ))
- result = self.execute_module(changed=True)
- self.assertEqual(
- result,
- {
- 'commands': [
- 'interface Ethernet 0/9',
- 'no ip address',
- 'no ipv6 address'
- ],
- 'changed': True
- }
- )
-
- def test_slxos_l3_interface_invalid_argument(self, *args, **kwargs):
- set_module_args(dict(
- name='Ethernet 0/1',
- shawshank='Redemption'
- ))
- result = self.execute_module(failed=True)
- self.assertEqual(result['failed'], True)
- self.assertTrue(re.match(
- r'Unsupported parameters for \((basic.py|basic.pyc)\) module: '
- 'shawshank Supported parameters include: aggregate, ipv4, ipv6, '
- 'name, state',
- result['msg']
- ))
diff --git a/test/units/modules/network/slxos/test_slxos_linkagg.py b/test/units/modules/network/slxos/test_slxos_linkagg.py
deleted file mode 100644
index 5969b0c652..0000000000
--- a/test/units/modules/network/slxos/test_slxos_linkagg.py
+++ /dev/null
@@ -1,159 +0,0 @@
-#
-# (c) 2018 Extreme Networks Inc.
-#
-# This file is part of Ansible
-#
-# Ansible is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# Ansible is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
-#
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
-
-import re
-
-from units.compat.mock import patch
-from units.modules.utils import set_module_args
-from ansible.modules.network.slxos import slxos_linkagg
-from .slxos_module import TestSlxosModule, load_fixture
-
-
-class TestSlxosLinkaggModule(TestSlxosModule):
- module = slxos_linkagg
-
- def setUp(self):
- super(TestSlxosLinkaggModule, self).setUp()
- self._patch_get_config = patch(
- 'ansible.modules.network.slxos.slxos_linkagg.get_config'
- )
- self._patch_load_config = patch(
- 'ansible.modules.network.slxos.slxos_linkagg.load_config'
- )
-
- self._get_config = self._patch_get_config.start()
- self._load_config = self._patch_load_config.start()
-
- def tearDown(self):
- super(TestSlxosLinkaggModule, self).tearDown()
- self._patch_get_config.stop()
- self._patch_load_config.stop()
-
- def load_fixtures(self, commands=None):
- config_file = 'slxos_config_config.cfg'
- self._get_config.return_value = load_fixture(config_file)
- self._load_config.return_value = None
-
- def test_slxos_linkagg_group_present(self, *args, **kwargs):
- set_module_args(dict(
- group='10',
- state='present'
- ))
- result = self.execute_module(changed=True)
- self.assertEqual(
- result,
- {
- 'commands': [
- 'interface port-channel 10',
- 'exit'
- ],
- 'changed': True
- }
- )
-
- def test_slxos_linkagg_group_members_active(self, *args, **kwargs):
- set_module_args(dict(
- group='10',
- mode='active',
- members=[
- 'Ethernet 0/1',
- 'Ethernet 0/2'
- ]
- ))
- result = self.execute_module(changed=True)
- self.assertEqual(
- result,
- {
- 'commands': [
- 'interface port-channel 10',
- 'exit',
- 'interface Ethernet 0/1',
- 'channel-group 10 mode active',
- 'interface Ethernet 0/2',
- 'channel-group 10 mode active'
- ],
- 'changed': True
- }
- )
-
- def test_slxos_linkagg_group_member_removal(self, *args, **kwargs):
- set_module_args(dict(
- group='20',
- mode='active',
- members=[
- 'Ethernet 0/10',
- ]
- ))
- result = self.execute_module(changed=True)
- self.assertEqual(
- result,
- {
- 'commands': [
- 'interface port-channel 20',
- 'exit',
- 'interface Ethernet 0/11',
- 'no channel-group'
- ],
- 'changed': True
- }
- )
-
- def test_slxos_linkagg_group_members_absent(self, *args, **kwargs):
- set_module_args(dict(
- group='20',
- state='absent'
- ))
- result = self.execute_module(changed=True)
- self.assertEqual(
- result,
- {
- 'commands': [
- 'no interface port-channel 20'
- ],
- 'changed': True
- }
- )
- set_module_args(dict(
- group='10',
- state='absent'
- ))
- result = self.execute_module(changed=False)
- self.assertEqual(
- result,
- {
- 'commands': [],
- 'changed': False
- }
- )
-
- def test_slxos_linkagg_invalid_argument(self, *args, **kwargs):
- set_module_args(dict(
- group='10',
- shawshank='Redemption'
- ))
- result = self.execute_module(failed=True)
- self.assertEqual(result['failed'], True)
- self.assertTrue(re.match(
- r'Unsupported parameters for \((basic.pyc|basic.py)\) module: '
- 'shawshank Supported parameters include: aggregate, group, '
- 'members, mode, purge, state',
- result['msg']
- ))
diff --git a/test/units/modules/network/slxos/test_slxos_lldp.py b/test/units/modules/network/slxos/test_slxos_lldp.py
deleted file mode 100644
index 4d6c2d1555..0000000000
--- a/test/units/modules/network/slxos/test_slxos_lldp.py
+++ /dev/null
@@ -1,95 +0,0 @@
-#
-# (c) 2018 Extreme Networks Inc.
-#
-# This file is part of Ansible
-#
-# Ansible is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# Ansible is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
-#
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
-
-import re
-
-from units.compat.mock import patch
-from units.modules.utils import set_module_args
-from ansible.modules.network.slxos import slxos_lldp
-from .slxos_module import TestSlxosModule, load_fixture
-
-
-class TestSlxosLldpModule(TestSlxosModule):
- module = slxos_lldp
-
- def setUp(self):
- super(TestSlxosLldpModule, self).setUp()
- self._patch_get_config = patch(
- 'ansible.modules.network.slxos.slxos_lldp.get_config'
- )
- self._patch_load_config = patch(
- 'ansible.modules.network.slxos.slxos_lldp.load_config'
- )
-
- self._get_config = self._patch_get_config.start()
- self._load_config = self._patch_load_config.start()
-
- def tearDown(self):
- super(TestSlxosLldpModule, self).tearDown()
- self._patch_get_config.stop()
- self._patch_load_config.stop()
-
- def load_fixtures(self, commands=None):
- config_file = 'slxos_config_config.cfg'
- self._get_config.return_value = load_fixture(config_file)
- self._load_config.return_value = None
-
- def test_slxos_lldp_present(self, *args, **kwargs):
- set_module_args(dict(
- state='present'
- ))
- result = self.execute_module(changed=True)
- self.assertEqual(
- result,
- {
- 'commands': [
- 'protocol lldp',
- 'no disable'
- ],
- 'changed': True
- }
- )
-
- def test_slxos_lldp_absent(self, *args, **kwargs):
- set_module_args(dict(
- state='absent'
- ))
- result = self.execute_module()
- self.assertEqual(
- result,
- {
- 'commands': [],
- 'changed': False
- }
- )
-
- def test_slxos_lldp_invalid_argument(self, *args, **kwargs):
- set_module_args(dict(
- state='absent',
- shawshank='Redemption'
- ))
- result = self.execute_module(failed=True)
- self.assertEqual(result['failed'], True)
- self.assertTrue(re.match(
- r'Unsupported parameters for \((basic.py|basic.pyc)\) module: '
- 'shawshank Supported parameters include: state',
- result['msg']
- ), 'Output did not match. Got: %s' % result['msg'])
diff --git a/test/units/modules/network/slxos/test_slxos_vlan.py b/test/units/modules/network/slxos/test_slxos_vlan.py
deleted file mode 100644
index 5c103a70d1..0000000000
--- a/test/units/modules/network/slxos/test_slxos_vlan.py
+++ /dev/null
@@ -1,144 +0,0 @@
-#
-# (c) 2018 Extreme Networks Inc.
-#
-# This file is part of Ansible
-#
-# Ansible is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# Ansible is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
-#
-from __future__ import (absolute_import, division, print_function)
-__metaclass__ = type
-
-import re
-
-from units.compat.mock import patch
-from units.modules.utils import set_module_args
-from ansible.modules.network.slxos import slxos_vlan
-from .slxos_module import TestSlxosModule, load_fixture
-
-
-class TestSlxosVlanModule(TestSlxosModule):
- module = slxos_vlan
-
- def setUp(self):
- super(TestSlxosVlanModule, self).setUp()
- self._patch_run_commands = patch(
- 'ansible.modules.network.slxos.slxos_vlan.run_commands'
- )
- self._patch_load_config = patch(
- 'ansible.modules.network.slxos.slxos_vlan.load_config'
- )
-
- self._run_commands = self._patch_run_commands.start()
- self._load_config = self._patch_load_config.start()
-
- def tearDown(self):
- super(TestSlxosVlanModule, self).tearDown()
- self._patch_run_commands.stop()
- self._patch_load_config.stop()
-
- def load_fixtures(self, commands=None):
- config_file = 'show_vlan_brief'
- self._run_commands.return_value = [load_fixture(config_file)]
- self._load_config.return_value = None
-
- def test_slxos_vlan_id_with_name(self, *args, **kwargs):
- load_fixture('show_vlan_brief')
- set_module_args(dict(
- vlan_id=100,
- name='ONEHUNDRED'
- ))
- result = self.execute_module(changed=True)
- self.assertEqual(
- result,
- {
- 'commands': [
- 'vlan 100',
- 'name ONEHUNDRED'
- ],
- 'changed': True
- }
- )
-
- def test_slxos_vlan_with_members(self, *args, **kwargs):
- set_module_args(dict(
- vlan_id=100,
- name='ONEHUNDRED',
- interfaces=[
- 'Ethernet 0/1',
- 'Ethernet 0/2'
- ]
- ))
- result = self.execute_module(changed=True)
- self.assertEqual(
- result,
- {
- 'commands': [
- 'vlan 100',
- 'name ONEHUNDRED',
- 'interface Ethernet 0/1',
- 'switchport',
- 'switchport mode access',
- 'switchport access vlan 100',
- 'interface Ethernet 0/2',
- 'switchport',
- 'switchport mode access',
- 'switchport access vlan 100'
- ],
- 'changed': True
- }
- )
-
- def test_slxos_vlan_state_absent(self, *args, **kwargs):
- set_module_args(dict(
- vlan_id=200,
- state='absent'
- ))
- result = self.execute_module(changed=True)
- self.assertEqual(
- result,
- {
- 'commands': [
- 'no vlan 200'
- ],
- 'changed': True
- }
- )
-
- def test_slxos_vlan_state_absent_nonexistent_vlan(self, *args, **kwargs):
- set_module_args(dict(
- vlan_id=100,
- state='absent'
- ))
- result = self.execute_module()
- self.assertEqual(
- result,
- {
- 'commands': [],
- 'changed': False
- }
- )
-
- def test_slxos_interface_invalid_argument(self, *args, **kwargs):
- set_module_args(dict(
- name='Ethernet 0/1',
- shawshank='Redemption'
- ))
- result = self.execute_module(failed=True)
- self.assertEqual(result['failed'], True)
- self.assertTrue(re.match(
- r'Unsupported parameters for \((basic.py|basic.pyc)\) module: '
- 'shawshank Supported parameters include: aggregate, delay, '
- 'interfaces, name, purge, state, vlan_id',
- result['msg']
- ), 'Result did not match expected output. Got: %s' % result['msg'])