Browse Source

Adds ngs_switchport_mode config option to Dell PowerConnect driver

This allows the PowerConnect switches to configured with switchport
mode set to general.

Change-Id: Id9b506a043a8756393b302f304ca7432819bebd5
Story: 2002940
Task: 22932
Will Szumski 9 months ago
parent
commit
e3878ac7e1

+ 6
- 0
doc/source/configuration.rst View File

@@ -98,6 +98,12 @@ for the Dell PowerConnect device::
98 98
     password = password
99 99
     secret = secret
100 100
 
101
+    # You can set ngs_switchport_mode according to switchmode you have set on
102
+    # the switch. The following options are supported: general, access. It
103
+    # will default to access mode if left unset. In general mode, the port
104
+    # be set to transmit untagged packets.
105
+    ngs_switchport_mode = access
106
+
101 107
 Dell PowerConnect devices have been seen to have issues with multiple
102 108
 concurrent configuration sessions. See :ref:`synchronization` for details on
103 109
 how to limit the number of concurrent active connections to each device.

+ 1
- 0
networking_generic_switch/devices/__init__.py View File

@@ -34,6 +34,7 @@ NGS_INTERNAL_OPTS = [
34 34
     {'name': 'ngs_ssh_connect_timeout', 'default': 60},
35 35
     {'name': 'ngs_ssh_connect_interval', 'default': 10},
36 36
     {'name': 'ngs_max_connections', 'default': 1},
37
+    {'name': 'ngs_switchport_mode', 'default': 'access'}
37 38
 ]
38 39
 
39 40
 

+ 35
- 0
networking_generic_switch/devices/netmiko_devices/dell.py View File

@@ -13,6 +13,7 @@
13 13
 #    under the License.
14 14
 
15 15
 from networking_generic_switch.devices import netmiko_devices
16
+from networking_generic_switch import exceptions as exc
16 17
 
17 18
 
18 19
 class DellNos(netmiko_devices.NetmikoSwitch):
@@ -57,6 +58,26 @@ class DellNos(netmiko_devices.NetmikoSwitch):
57 58
 class DellPowerConnect(netmiko_devices.NetmikoSwitch):
58 59
     """Netmiko device driver for Dell PowerConnect switches."""
59 60
 
61
+    def _switch_to_general_mode(self):
62
+        self.PLUG_PORT_TO_NETWORK = self.PLUG_PORT_TO_NETWORK_GENERAL
63
+        self.DELETE_PORT = self.DELETE_PORT_GENERAL
64
+
65
+    def __init__(self, device_cfg):
66
+        super(DellPowerConnect, self).__init__(device_cfg)
67
+        port_mode = self.ngs_config['ngs_switchport_mode']
68
+        switchport_mode = {
69
+            'general': self._switch_to_general_mode,
70
+            'access': lambda: ()
71
+        }
72
+
73
+        def on_invalid_switchmode():
74
+            raise exc.GenericSwitchConfigException(
75
+                option="ngs_switchport_mode",
76
+                allowed_options=switchport_mode.keys()
77
+            )
78
+
79
+        switchport_mode.get(port_mode.lower(), on_invalid_switchmode)()
80
+
60 81
     ADD_NETWORK = (
61 82
         'vlan database',
62 83
         'vlan {segmentation_id}',
@@ -69,12 +90,26 @@ class DellPowerConnect(netmiko_devices.NetmikoSwitch):
69 90
         'exit',
70 91
     )
71 92
 
93
+    PLUG_PORT_TO_NETWORK_GENERAL = (
94
+        'interface {port}',
95
+        'switchport general allowed vlan add {segmentation_id} untagged',
96
+        'switchport general pvid {segmentation_id}',
97
+        'exit',
98
+    )
99
+
72 100
     PLUG_PORT_TO_NETWORK = (
73 101
         'interface {port}',
74 102
         'switchport access vlan {segmentation_id}',
75 103
         'exit',
76 104
     )
77 105
 
106
+    DELETE_PORT_GENERAL = (
107
+        'interface {port}',
108
+        'switchport general allowed vlan remove {segmentation_id}',
109
+        'no switchport general pvid',
110
+        'exit',
111
+    )
112
+
78 113
     DELETE_PORT = (
79 114
         'interface {port}',
80 115
         'switchport access vlan none',

+ 4
- 0
networking_generic_switch/exceptions.py View File

@@ -21,6 +21,10 @@ class GenericSwitchException(exceptions.NeutronException):
21 21
     message = _("%(method)s failed.")
22 22
 
23 23
 
24
+class GenericSwitchConfigException(exceptions.NeutronException):
25
+    message = _("%(option)s must be one of: %(allowed_options)s")
26
+
27
+
24 28
 class GenericSwitchEntrypointLoadError(GenericSwitchException):
25 29
     message = _("Failed to load entrypoint %(ep)s: %(err)s")
26 30
 

+ 56
- 0
networking_generic_switch/tests/unit/netmiko/test_dell.py View File

@@ -15,6 +15,7 @@
15 15
 import mock
16 16
 
17 17
 from networking_generic_switch.devices.netmiko_devices import dell
18
+from networking_generic_switch import exceptions as exc
18 19
 from networking_generic_switch.tests.unit.netmiko import test_netmiko_base
19 20
 
20 21
 
@@ -133,6 +134,18 @@ class TestNetmikoDellPowerConnect(test_netmiko_base.NetmikoSwitchTestBase):
133 134
         m_exec.assert_called_with(
134 135
             ['vlan database', 'vlan 33', 'exit'])
135 136
 
137
+    def test_invalid_switchmode(self):
138
+        with self.assertRaises(exc.GenericSwitchConfigException):
139
+            self._make_switch_device({'ngs_switchport_mode': 'BAD_PORT_MODE'})
140
+
141
+    def test_switchmode_general(self):
142
+        # should not raise an exception
143
+        self._make_switch_device({'ngs_switchport_mode': 'GENERAL'})
144
+
145
+    def test_switchmode_access(self):
146
+        # should not raise an exception
147
+        self._make_switch_device({'ngs_switchport_mode': 'access'})
148
+
136 149
     @mock.patch('networking_generic_switch.devices.netmiko_devices.'
137 150
                 'NetmikoSwitch.send_commands_to_device')
138 151
     def test_add_network_with_trunk_ports(self, mock_exec):
@@ -172,6 +185,17 @@ class TestNetmikoDellPowerConnect(test_netmiko_base.NetmikoSwitchTestBase):
172 185
         mock_exec.assert_called_with(
173 186
             ['interface 3333', 'switchport access vlan 33', 'exit'])
174 187
 
188
+    @mock.patch('networking_generic_switch.devices.netmiko_devices.'
189
+                'NetmikoSwitch.send_commands_to_device')
190
+    def test_plug_port_to_network_general_mode(self, mock_exec):
191
+        switch = self._make_switch_device({'ngs_switchport_mode': 'GENERAL'})
192
+        switch.plug_port_to_network(3333, 33)
193
+        mock_exec.assert_called_with(
194
+            ['interface 3333',
195
+             'switchport general allowed vlan add 33 untagged',
196
+             'switchport general pvid 33',
197
+             'exit'])
198
+
175 199
     @mock.patch('networking_generic_switch.devices.netmiko_devices.'
176 200
                 'NetmikoSwitch.send_commands_to_device')
177 201
     def test_delete_port(self, mock_exec):
@@ -179,6 +203,17 @@ class TestNetmikoDellPowerConnect(test_netmiko_base.NetmikoSwitchTestBase):
179 203
         mock_exec.assert_called_with(
180 204
             ['interface 3333', 'switchport access vlan none', 'exit'])
181 205
 
206
+    @mock.patch('networking_generic_switch.devices.netmiko_devices.'
207
+                'NetmikoSwitch.send_commands_to_device')
208
+    def test_delete_port_general(self, mock_exec):
209
+        switch = self._make_switch_device({'ngs_switchport_mode': 'GENERAL'})
210
+        switch.delete_port(3333, 33)
211
+        mock_exec.assert_called_with(
212
+            ['interface 3333',
213
+             'switchport general allowed vlan remove 33',
214
+             'no switchport general pvid',
215
+             'exit'])
216
+
182 217
     def test__format_commands(self):
183 218
         cmd_set = self.switch._format_commands(
184 219
             dell.DellPowerConnect.ADD_NETWORK,
@@ -221,3 +256,24 @@ class TestNetmikoDellPowerConnect(test_netmiko_base.NetmikoSwitchTestBase):
221 256
         self.assertEqual(cmd_set,
222 257
                          ['interface 3333',
223 258
                           'switchport general allowed vlan remove 33', 'exit'])
259
+
260
+    def test__format_commands_general_mode(self):
261
+        switch = self._make_switch_device({'ngs_switchport_mode': 'GENERAL'})
262
+        cmd_set = switch._format_commands(
263
+            dell.DellPowerConnect.PLUG_PORT_TO_NETWORK_GENERAL,
264
+            port=3333,
265
+            segmentation_id=33)
266
+        self.assertEqual(cmd_set,
267
+                         ['interface 3333',
268
+                          'switchport general allowed vlan add 33 untagged',
269
+                          'switchport general pvid 33',
270
+                          'exit'])
271
+        cmd_set = switch._format_commands(
272
+            dell.DellPowerConnect.DELETE_PORT_GENERAL,
273
+            port=3333,
274
+            segmentation_id=33)
275
+        self.assertEqual(cmd_set,
276
+                         ['interface 3333',
277
+                          'switchport general allowed vlan remove 33',
278
+                          'no switchport general pvid',
279
+                          'exit'])

+ 5
- 0
releasenotes/notes/add-switchmode-option-to-dell-powerconnect-87718a84430444ef.yaml View File

@@ -0,0 +1,5 @@
1
+---
2
+features:
3
+  - |
4
+    Adds a new config option, ``ngs_switchport_mode`` to the Dell
5
+    PowerConnect driver.

Loading…
Cancel
Save