|
| 1 | +# Copyright (c) 2022 VEXXHOST, Inc. |
| 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 aruba |
| 18 | +from networking_generic_switch.tests.unit.netmiko import test_netmiko_base |
| 19 | + |
| 20 | + |
| 21 | +class TestNetmikoAruba(test_netmiko_base.NetmikoSwitchTestBase): |
| 22 | + |
| 23 | + def _make_switch_device(self, extra_cfg={}): |
| 24 | + device_cfg = {'device_type': 'netmiko_aruba_os'} |
| 25 | + device_cfg.update(extra_cfg) |
| 26 | + return aruba.ArubaOSCX(device_cfg) |
| 27 | + |
| 28 | + def test_constants(self): |
| 29 | + self.assertIsNone(self.switch.SAVE_CONFIGURATION) |
| 30 | + |
| 31 | + @mock.patch('networking_generic_switch.devices.netmiko_devices.' |
| 32 | + 'NetmikoSwitch.send_commands_to_device') |
| 33 | + def test_add_network(self, m_exec): |
| 34 | + self.switch.add_network(33, '0ae071f5-5be9-43e4-80ea-e41fefe85b21') |
| 35 | + m_exec.assert_called_with( |
| 36 | + ['vlan 33', 'name 0ae071f55be943e480eae41fefe85b21']) |
| 37 | + |
| 38 | + @mock.patch('networking_generic_switch.devices.netmiko_devices.' |
| 39 | + 'NetmikoSwitch.send_commands_to_device') |
| 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(['no vlan 33']) |
| 43 | + |
| 44 | + @mock.patch('networking_generic_switch.devices.netmiko_devices.' |
| 45 | + 'NetmikoSwitch.send_commands_to_device') |
| 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 | + ['interface 3333', 'no routing', 'vlan access 33']) |
| 50 | + |
| 51 | + @mock.patch('networking_generic_switch.devices.netmiko_devices.' |
| 52 | + 'NetmikoSwitch.send_commands_to_device') |
| 53 | + def test_plug_port_to_network_disable_inactive(self, m_sctd): |
| 54 | + switch = self._make_switch_device( |
| 55 | + {'ngs_disable_inactive_ports': 'true'}) |
| 56 | + switch.plug_port_to_network(3333, 33) |
| 57 | + m_sctd.assert_called_with( |
| 58 | + ['interface 3333', 'no shutdown', |
| 59 | + 'interface 3333', 'no routing', 'vlan access 33']) |
| 60 | + |
| 61 | + @mock.patch('networking_generic_switch.devices.netmiko_devices.' |
| 62 | + 'NetmikoSwitch.send_commands_to_device') |
| 63 | + def test_delete_port(self, mock_exec): |
| 64 | + self.switch.delete_port(3333, 33) |
| 65 | + mock_exec.assert_called_with(['interface 3333', 'no vlan access 33']) |
| 66 | + |
| 67 | + @mock.patch('networking_generic_switch.devices.netmiko_devices.' |
| 68 | + 'NetmikoSwitch.send_commands_to_device') |
| 69 | + def test_delete_port_disable_inactive(self, m_sctd): |
| 70 | + switch = self._make_switch_device( |
| 71 | + {'ngs_disable_inactive_ports': 'true'}) |
| 72 | + switch.delete_port(3333, 33) |
| 73 | + m_sctd.assert_called_with( |
| 74 | + ['interface 3333', 'no vlan access 33', |
| 75 | + 'interface 3333', 'shutdown']) |
| 76 | + |
| 77 | + @mock.patch('networking_generic_switch.devices.netmiko_devices.' |
| 78 | + 'NetmikoSwitch.send_commands_to_device') |
| 79 | + def test_add_network_with_trunk_ports(self, mock_exec): |
| 80 | + switch = self._make_switch_device({'ngs_trunk_ports': 'port1, port2'}) |
| 81 | + switch.add_network(33, '0ae071f5-5be9-43e4-80ea-e41fefe85b21') |
| 82 | + mock_exec.assert_called_with( |
| 83 | + ['vlan 33', |
| 84 | + 'name 0ae071f55be943e480eae41fefe85b21', |
| 85 | + 'interface port1', 'no routing', 'vlan trunk allowed 33', |
| 86 | + 'interface port2', 'no routing', 'vlan trunk allowed 33']) |
| 87 | + |
| 88 | + @mock.patch('networking_generic_switch.devices.netmiko_devices.' |
| 89 | + 'NetmikoSwitch.send_commands_to_device') |
| 90 | + def test_del_network_with_trunk_ports(self, mock_exec): |
| 91 | + switch = self._make_switch_device({'ngs_trunk_ports': 'port1, port2'}) |
| 92 | + switch.del_network(33, '0ae071f55be943e480eae41fefe85b21') |
| 93 | + mock_exec.assert_called_with( |
| 94 | + ['interface port1', 'no vlan trunk allowed 33', |
| 95 | + 'interface port2', 'no vlan trunk allowed 33', |
| 96 | + 'no vlan 33']) |
| 97 | + |
| 98 | + def test__format_commands(self): |
| 99 | + cmd_set = self.switch._format_commands( |
| 100 | + aruba.ArubaOSCX.ADD_NETWORK, |
| 101 | + segmentation_id=22, |
| 102 | + network_id=22, |
| 103 | + network_name='vlan-22') |
| 104 | + self.assertEqual(cmd_set, ['vlan 22', 'name vlan-22']) |
| 105 | + |
| 106 | + cmd_set = self.switch._format_commands( |
| 107 | + aruba.ArubaOSCX.DELETE_NETWORK, |
| 108 | + segmentation_id=22) |
| 109 | + self.assertEqual(cmd_set, ['no vlan 22']) |
| 110 | + |
| 111 | + cmd_set = self.switch._format_commands( |
| 112 | + aruba.ArubaOSCX.PLUG_PORT_TO_NETWORK, |
| 113 | + port=3333, |
| 114 | + segmentation_id=33) |
| 115 | + plug_exp = ['interface 3333', 'no routing', 'vlan access 33'] |
| 116 | + self.assertEqual(plug_exp, cmd_set) |
| 117 | + |
| 118 | + cmd_set = self.switch._format_commands( |
| 119 | + aruba.ArubaOSCX.DELETE_PORT, |
| 120 | + port=3333, |
| 121 | + segmentation_id=33) |
| 122 | + del_exp = ['interface 3333', 'no vlan access 33'] |
| 123 | + self.assertEqual(del_exp, cmd_set) |
| 124 | + |
| 125 | + cmd_set = self.switch._format_commands( |
| 126 | + aruba.ArubaOSCX.ADD_NETWORK_TO_TRUNK, |
| 127 | + port=3333, |
| 128 | + segmentation_id=33) |
| 129 | + trunk_exp = ['interface 3333', 'no routing', 'vlan trunk allowed 33'] |
| 130 | + self.assertEqual(trunk_exp, cmd_set) |
| 131 | + cmd_set = self.switch._format_commands( |
| 132 | + aruba.ArubaOSCX.REMOVE_NETWORK_FROM_TRUNK, |
| 133 | + port=3333, |
| 134 | + segmentation_id=33) |
| 135 | + self.assertEqual(cmd_set, |
| 136 | + ['interface 3333', 'no vlan trunk allowed 33']) |
0 commit comments