Browse Source

Detection of errors for Dell PowerConnect devices

Adds some commonly seen error messages in Dell PowerConnect switches:

% Incomplete command
VLAN was not created by user
Configuration Database locked by another application - try later

If these messages are found in the response from a device, an exception
will be raised.

Change-Id: Ia2d27cd659611cd7dad6663f1ac90c457658f697
Story: 2003148
Task: 24643
Mark Goddard 8 months ago
parent
commit
e306c935d0

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

@@ -12,6 +12,8 @@
12 12
 #    License for the specific language governing permissions and limitations
13 13
 #    under the License.
14 14
 
15
+import re
16
+
15 17
 from networking_generic_switch.devices import netmiko_devices
16 18
 from networking_generic_switch import exceptions as exc
17 19
 
@@ -127,3 +129,10 @@ class DellPowerConnect(netmiko_devices.NetmikoSwitch):
127 129
         'switchport general allowed vlan remove {segmentation_id}',
128 130
         'exit',
129 131
     )
132
+
133
+    ERROR_MSG_PATTERNS = (
134
+        re.compile(r'\% Incomplete command'),
135
+        re.compile(r'VLAN was not created by user'),
136
+        re.compile(r'Configuration Database locked by another application \- '
137
+                   r'try later'),
138
+    )

+ 87
- 17
networking_generic_switch/tests/unit/netmiko/test_dell.py View File

@@ -128,11 +128,15 @@ class TestNetmikoDellPowerConnect(test_netmiko_base.NetmikoSwitchTestBase):
128 128
         self.assertIsNone(self.switch.SAVE_CONFIGURATION)
129 129
 
130 130
     @mock.patch('networking_generic_switch.devices.netmiko_devices.'
131
-                'NetmikoSwitch.send_commands_to_device')
132
-    def test_add_network(self, m_exec):
131
+                'NetmikoSwitch.send_commands_to_device',
132
+                return_value='fake output')
133
+    @mock.patch('networking_generic_switch.devices.netmiko_devices.'
134
+                'NetmikoSwitch.check_output')
135
+    def test_add_network(self, mock_check, mock_exec):
133 136
         self.switch.add_network(33, '0ae071f5-5be9-43e4-80ea-e41fefe85b21')
134
-        m_exec.assert_called_with(
137
+        mock_exec.assert_called_with(
135 138
             ['vlan database', 'vlan 33', 'exit'])
139
+        mock_check.assert_called_once_with('fake output', 'add network')
136 140
 
137 141
     def test_invalid_switchmode(self):
138 142
         with self.assertRaises(exc.GenericSwitchConfigException):
@@ -147,8 +151,11 @@ class TestNetmikoDellPowerConnect(test_netmiko_base.NetmikoSwitchTestBase):
147 151
         self._make_switch_device({'ngs_switchport_mode': 'access'})
148 152
 
149 153
     @mock.patch('networking_generic_switch.devices.netmiko_devices.'
150
-                'NetmikoSwitch.send_commands_to_device')
151
-    def test_add_network_with_trunk_ports(self, mock_exec):
154
+                'NetmikoSwitch.send_commands_to_device',
155
+                return_value='fake output')
156
+    @mock.patch('networking_generic_switch.devices.netmiko_devices.'
157
+                'NetmikoSwitch.check_output')
158
+    def test_add_network_with_trunk_ports(self, mock_check, mock_exec):
152 159
         switch = self._make_switch_device({'ngs_trunk_ports': 'port1,port2'})
153 160
         switch.add_network(33, '0ae071f5-5be9-43e4-80ea-e41fefe85b21')
154 161
         mock_exec.assert_called_with(
@@ -159,16 +166,24 @@ class TestNetmikoDellPowerConnect(test_netmiko_base.NetmikoSwitchTestBase):
159 166
              'interface port2',
160 167
              'switchport general allowed vlan add 33 tagged',
161 168
              'exit'])
169
+        mock_check.assert_called_once_with('fake output', 'add network')
162 170
 
163 171
     @mock.patch('networking_generic_switch.devices.netmiko_devices.'
164
-                'NetmikoSwitch.send_commands_to_device')
165
-    def test_del_network(self, mock_exec):
172
+                'NetmikoSwitch.send_commands_to_device',
173
+                return_value='fake output')
174
+    @mock.patch('networking_generic_switch.devices.netmiko_devices.'
175
+                'NetmikoSwitch.check_output')
176
+    def test_del_network(self, mock_check, mock_exec):
166 177
         self.switch.del_network(33, '0ae071f5-5be9-43e4-80ea-e41fefe85b21')
167 178
         mock_exec.assert_called_with(['vlan database', 'no vlan 33', 'exit'])
179
+        mock_check.assert_called_once_with('fake output', 'delete network')
168 180
 
169 181
     @mock.patch('networking_generic_switch.devices.netmiko_devices.'
170
-                'NetmikoSwitch.send_commands_to_device')
171
-    def test_del_network_with_trunk_ports(self, mock_exec):
182
+                'NetmikoSwitch.send_commands_to_device',
183
+                return_value='fake output')
184
+    @mock.patch('networking_generic_switch.devices.netmiko_devices.'
185
+                'NetmikoSwitch.check_output')
186
+    def test_del_network_with_trunk_ports(self, mock_check, mock_exec):
172 187
         switch = self._make_switch_device({'ngs_trunk_ports': 'port1,port2'})
173 188
         switch.del_network(33, '0ae071f55be943e480eae41fefe85b21')
174 189
         mock_exec.assert_called_with(
@@ -177,17 +192,26 @@ class TestNetmikoDellPowerConnect(test_netmiko_base.NetmikoSwitchTestBase):
177 192
              'interface port2', 'switchport general allowed vlan remove 33',
178 193
              'exit',
179 194
              'vlan database', 'no vlan 33', 'exit'])
195
+        mock_check.assert_called_once_with('fake output', 'delete network')
180 196
 
181 197
     @mock.patch('networking_generic_switch.devices.netmiko_devices.'
182
-                'NetmikoSwitch.send_commands_to_device')
183
-    def test_plug_port_to_network(self, mock_exec):
198
+                'NetmikoSwitch.send_commands_to_device',
199
+                return_value='fake output')
200
+    @mock.patch('networking_generic_switch.devices.netmiko_devices.'
201
+                'NetmikoSwitch.check_output')
202
+    def test_plug_port_to_network(self, mock_check, mock_exec):
184 203
         self.switch.plug_port_to_network(3333, 33)
185 204
         mock_exec.assert_called_with(
186 205
             ['interface 3333', 'switchport access vlan 33', 'exit'])
206
+        mock_check.assert_called_once_with('fake output',
207
+                                           'plug port')
187 208
 
188 209
     @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):
210
+                'NetmikoSwitch.send_commands_to_device',
211
+                return_value='fake output')
212
+    @mock.patch('networking_generic_switch.devices.netmiko_devices.'
213
+                'NetmikoSwitch.check_output')
214
+    def test_plug_port_to_network_general_mode(self, mock_check, mock_exec):
191 215
         switch = self._make_switch_device({'ngs_switchport_mode': 'GENERAL'})
192 216
         switch.plug_port_to_network(3333, 33)
193 217
         mock_exec.assert_called_with(
@@ -195,17 +219,26 @@ class TestNetmikoDellPowerConnect(test_netmiko_base.NetmikoSwitchTestBase):
195 219
              'switchport general allowed vlan add 33 untagged',
196 220
              'switchport general pvid 33',
197 221
              'exit'])
222
+        mock_check.assert_called_once_with('fake output',
223
+                                           'plug port')
198 224
 
199 225
     @mock.patch('networking_generic_switch.devices.netmiko_devices.'
200
-                'NetmikoSwitch.send_commands_to_device')
201
-    def test_delete_port(self, mock_exec):
226
+                'NetmikoSwitch.send_commands_to_device',
227
+                return_value='fake output')
228
+    @mock.patch('networking_generic_switch.devices.netmiko_devices.'
229
+                'NetmikoSwitch.check_output')
230
+    def test_delete_port(self, mock_check, mock_exec):
202 231
         self.switch.delete_port(3333, 33)
203 232
         mock_exec.assert_called_with(
204 233
             ['interface 3333', 'switchport access vlan none', 'exit'])
234
+        mock_check.assert_called_once_with('fake output', 'unplug port')
205 235
 
206 236
     @mock.patch('networking_generic_switch.devices.netmiko_devices.'
207
-                'NetmikoSwitch.send_commands_to_device')
208
-    def test_delete_port_general(self, mock_exec):
237
+                'NetmikoSwitch.send_commands_to_device',
238
+                return_value='fake output')
239
+    @mock.patch('networking_generic_switch.devices.netmiko_devices.'
240
+                'NetmikoSwitch.check_output')
241
+    def test_delete_port_general(self, mock_check, mock_exec):
209 242
         switch = self._make_switch_device({'ngs_switchport_mode': 'GENERAL'})
210 243
         switch.delete_port(3333, 33)
211 244
         mock_exec.assert_called_with(
@@ -213,6 +246,43 @@ class TestNetmikoDellPowerConnect(test_netmiko_base.NetmikoSwitchTestBase):
213 246
              'switchport general allowed vlan remove 33',
214 247
              'no switchport general pvid',
215 248
              'exit'])
249
+        mock_check.assert_called_once_with('fake output', 'unplug port')
250
+
251
+    def test_check_output(self):
252
+        self.switch.check_output('fake output', 'fake op')
253
+
254
+    def _test_check_output_error(self, output):
255
+        msg = ("Found invalid configuration in device response. Operation: "
256
+               "fake op. Output: %s" % output)
257
+        self.assertRaisesRegexp(exc.GenericSwitchNetmikoConfigError, msg,
258
+                                self.switch.check_output, output, 'fake op')
259
+
260
+    def test_check_output_incomplete_command(self):
261
+        output = """
262
+vlan database
263
+vlan 33
264
+exit
265
+% Incomplete command
266
+"""
267
+        self._test_check_output_error(output)
268
+
269
+    def test_check_output_vlan_not_recognised(self):
270
+        output = """
271
+vlan database
272
+vlan 33
273
+exit
274
+VLAN was not created by user
275
+"""
276
+        self._test_check_output_error(output)
277
+
278
+    def test_check_output_incomplete_db_locked(self):
279
+        output = """
280
+vlan database
281
+vlan 33
282
+exit
283
+Configuration Database locked by another application - try later
284
+"""
285
+        self._test_check_output_error(output)
216 286
 
217 287
     def test__format_commands(self):
218 288
         cmd_set = self.switch._format_commands(

Loading…
Cancel
Save