|
| 1 | +# Copyright 2024 Nscale. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 | +# not use this file except in compliance with the License. You may obtain |
| 5 | +# a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 | +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | +# License for the specific language governing permissions and limitations |
| 13 | +# under the License. |
| 14 | + |
| 15 | +from unittest import mock |
| 16 | + |
| 17 | +from networking_generic_switch.devices.netmiko_devices import smc |
| 18 | +from networking_generic_switch.tests.unit.netmiko import test_netmiko_base |
| 19 | + |
| 20 | + |
| 21 | +class TestNetmikoSupermicroSmis(test_netmiko_base.NetmikoSwitchTestBase): |
| 22 | + |
| 23 | + def _make_switch_device(self): |
| 24 | + device_cfg = {'device_type': 'netmiko_supermicro_smis'} |
| 25 | + return smc.SupermicroSmis(device_cfg) |
| 26 | + |
| 27 | + def test_constants(self): |
| 28 | + self.assertIsNone(self.switch.SAVE_CONFIGURATION) |
| 29 | + |
| 30 | + @mock.patch('networking_generic_switch.devices.netmiko_devices.' |
| 31 | + 'NetmikoSwitch.send_commands_to_device', autospec=True) |
| 32 | + def test_add_network(self, m_exec): |
| 33 | + self.switch.add_network(33, '0ae071f5-5be9-43e4-80ea-e41fefe85b21') |
| 34 | + m_exec.assert_any_call( |
| 35 | + self.switch, |
| 36 | + ['vlan 33', 'name 0ae071f55be943e480eae41fefe85b21']) |
| 37 | + |
| 38 | + @mock.patch('networking_generic_switch.devices.netmiko_devices.' |
| 39 | + 'NetmikoSwitch.send_commands_to_device', autospec=True) |
| 40 | + def test_del_network(self, mock_exec): |
| 41 | + self.switch.del_network(33, '0ae071f5-5be9-43e4-80ea-e41fefe85b21') |
| 42 | + mock_exec.assert_called_with(self.switch, ['no vlan 33']) |
| 43 | + |
| 44 | + @mock.patch('networking_generic_switch.devices.netmiko_devices.' |
| 45 | + 'NetmikoSwitch.send_commands_to_device', autospec=True) |
| 46 | + def test_plug_port_to_network(self, mock_exec): |
| 47 | + self.switch.plug_port_to_network(3333, 33) |
| 48 | + mock_exec.assert_called_with( |
| 49 | + self.switch, |
| 50 | + ['interface 3333', 'switchport mode access', |
| 51 | + 'switchport access vlan 33']) |
| 52 | + |
| 53 | + @mock.patch('networking_generic_switch.devices.netmiko_devices.' |
| 54 | + 'NetmikoSwitch.send_commands_to_device', autospec=True) |
| 55 | + def test_delete_port(self, mock_exec): |
| 56 | + self.switch.delete_port(3333, 33) |
| 57 | + mock_exec.assert_called_with( |
| 58 | + self.switch, |
| 59 | + ['interface 3333', 'no switchport access vlan 33', |
| 60 | + 'no switchport mode trunk', 'switchport trunk allowed vlan none']) |
| 61 | + |
| 62 | + def test__format_commands(self): |
| 63 | + cmd_set = self.switch._format_commands( |
| 64 | + smc.SupermicroSmis.ADD_NETWORK, |
| 65 | + segmentation_id=22, |
| 66 | + network_id=22, |
| 67 | + network_name='vlan-22') |
| 68 | + self.assertEqual(cmd_set, ['vlan 22', 'name vlan-22']) |
| 69 | + |
| 70 | + cmd_set = self.switch._format_commands( |
| 71 | + smc.SupermicroSmis.DELETE_NETWORK, |
| 72 | + segmentation_id=22) |
| 73 | + self.assertEqual(cmd_set, ['no vlan 22']) |
| 74 | + |
| 75 | + cmd_set = self.switch._format_commands( |
| 76 | + smc.SupermicroSmis.PLUG_PORT_TO_NETWORK, |
| 77 | + port=3333, |
| 78 | + segmentation_id=33) |
| 79 | + plug_exp = ['interface 3333', 'switchport mode access', |
| 80 | + 'switchport access vlan 33'] |
| 81 | + self.assertEqual(plug_exp, cmd_set) |
| 82 | + |
| 83 | + cmd_set = self.switch._format_commands( |
| 84 | + smc.SupermicroSmis.DELETE_PORT, |
| 85 | + port=3333, |
| 86 | + segmentation_id=33) |
| 87 | + del_exp = ['interface 3333', |
| 88 | + 'no switchport access vlan 33', |
| 89 | + 'no switchport mode trunk', |
| 90 | + 'switchport trunk allowed vlan none'] |
| 91 | + self.assertEqual(del_exp, cmd_set) |
0 commit comments