summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2018-08-29 18:15:54 +0000
committerGerrit Code Review <review@openstack.org>2018-08-29 18:15:54 +0000
commit644d56e10376e196e385692843056362f41e44cf (patch)
treed676adf1e7228c90cb78fd95c9b5822c32268979
parentb53ede82a3d9b199d39fae1cbf0a58d470183abc (diff)
parente306c935d017d440dee51efcab7b3b394fda8538 (diff)
Merge "Detection of errors for Dell PowerConnect devices"
-rw-r--r--networking_generic_switch/devices/netmiko_devices/dell.py9
-rw-r--r--networking_generic_switch/tests/unit/netmiko/test_dell.py104
2 files changed, 96 insertions, 17 deletions
diff --git a/networking_generic_switch/devices/netmiko_devices/dell.py b/networking_generic_switch/devices/netmiko_devices/dell.py
index 8a9ce3f..5eb9fd0 100644
--- a/networking_generic_switch/devices/netmiko_devices/dell.py
+++ b/networking_generic_switch/devices/netmiko_devices/dell.py
@@ -12,6 +12,8 @@
12# License for the specific language governing permissions and limitations 12# License for the specific language governing permissions and limitations
13# under the License. 13# under the License.
14 14
15import re
16
15from networking_generic_switch.devices import netmiko_devices 17from networking_generic_switch.devices import netmiko_devices
16from networking_generic_switch import exceptions as exc 18from networking_generic_switch import exceptions as exc
17 19
@@ -127,3 +129,10 @@ class DellPowerConnect(netmiko_devices.NetmikoSwitch):
127 'switchport general allowed vlan remove {segmentation_id}', 129 'switchport general allowed vlan remove {segmentation_id}',
128 'exit', 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 )
diff --git a/networking_generic_switch/tests/unit/netmiko/test_dell.py b/networking_generic_switch/tests/unit/netmiko/test_dell.py
index 8ce9686..590be03 100644
--- a/networking_generic_switch/tests/unit/netmiko/test_dell.py
+++ b/networking_generic_switch/tests/unit/netmiko/test_dell.py
@@ -128,11 +128,15 @@ class TestNetmikoDellPowerConnect(test_netmiko_base.NetmikoSwitchTestBase):
128 self.assertIsNone(self.switch.SAVE_CONFIGURATION) 128 self.assertIsNone(self.switch.SAVE_CONFIGURATION)
129 129
130 @mock.patch('networking_generic_switch.devices.netmiko_devices.' 130 @mock.patch('networking_generic_switch.devices.netmiko_devices.'
131 'NetmikoSwitch.send_commands_to_device') 131 'NetmikoSwitch.send_commands_to_device',
132 def test_add_network(self, m_exec): 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 self.switch.add_network(33, '0ae071f5-5be9-43e4-80ea-e41fefe85b21') 136 self.switch.add_network(33, '0ae071f5-5be9-43e4-80ea-e41fefe85b21')
134 m_exec.assert_called_with( 137 mock_exec.assert_called_with(
135 ['vlan database', 'vlan 33', 'exit']) 138 ['vlan database', 'vlan 33', 'exit'])
139 mock_check.assert_called_once_with('fake output', 'add network')
136 140
137 def test_invalid_switchmode(self): 141 def test_invalid_switchmode(self):
138 with self.assertRaises(exc.GenericSwitchConfigException): 142 with self.assertRaises(exc.GenericSwitchConfigException):
@@ -147,8 +151,11 @@ class TestNetmikoDellPowerConnect(test_netmiko_base.NetmikoSwitchTestBase):
147 self._make_switch_device({'ngs_switchport_mode': 'access'}) 151 self._make_switch_device({'ngs_switchport_mode': 'access'})
148 152
149 @mock.patch('networking_generic_switch.devices.netmiko_devices.' 153 @mock.patch('networking_generic_switch.devices.netmiko_devices.'
150 'NetmikoSwitch.send_commands_to_device') 154 'NetmikoSwitch.send_commands_to_device',
151 def test_add_network_with_trunk_ports(self, mock_exec): 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 switch = self._make_switch_device({'ngs_trunk_ports': 'port1,port2'}) 159 switch = self._make_switch_device({'ngs_trunk_ports': 'port1,port2'})
153 switch.add_network(33, '0ae071f5-5be9-43e4-80ea-e41fefe85b21') 160 switch.add_network(33, '0ae071f5-5be9-43e4-80ea-e41fefe85b21')
154 mock_exec.assert_called_with( 161 mock_exec.assert_called_with(
@@ -159,16 +166,24 @@ class TestNetmikoDellPowerConnect(test_netmiko_base.NetmikoSwitchTestBase):
159 'interface port2', 166 'interface port2',
160 'switchport general allowed vlan add 33 tagged', 167 'switchport general allowed vlan add 33 tagged',
161 'exit']) 168 'exit'])
169 mock_check.assert_called_once_with('fake output', 'add network')
162 170
163 @mock.patch('networking_generic_switch.devices.netmiko_devices.' 171 @mock.patch('networking_generic_switch.devices.netmiko_devices.'
164 'NetmikoSwitch.send_commands_to_device') 172 'NetmikoSwitch.send_commands_to_device',
165 def test_del_network(self, mock_exec): 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 self.switch.del_network(33, '0ae071f5-5be9-43e4-80ea-e41fefe85b21') 177 self.switch.del_network(33, '0ae071f5-5be9-43e4-80ea-e41fefe85b21')
167 mock_exec.assert_called_with(['vlan database', 'no vlan 33', 'exit']) 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 @mock.patch('networking_generic_switch.devices.netmiko_devices.' 181 @mock.patch('networking_generic_switch.devices.netmiko_devices.'
170 'NetmikoSwitch.send_commands_to_device') 182 'NetmikoSwitch.send_commands_to_device',
171 def test_del_network_with_trunk_ports(self, mock_exec): 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 switch = self._make_switch_device({'ngs_trunk_ports': 'port1,port2'}) 187 switch = self._make_switch_device({'ngs_trunk_ports': 'port1,port2'})
173 switch.del_network(33, '0ae071f55be943e480eae41fefe85b21') 188 switch.del_network(33, '0ae071f55be943e480eae41fefe85b21')
174 mock_exec.assert_called_with( 189 mock_exec.assert_called_with(
@@ -177,17 +192,26 @@ class TestNetmikoDellPowerConnect(test_netmiko_base.NetmikoSwitchTestBase):
177 'interface port2', 'switchport general allowed vlan remove 33', 192 'interface port2', 'switchport general allowed vlan remove 33',
178 'exit', 193 'exit',
179 'vlan database', 'no vlan 33', 'exit']) 194 'vlan database', 'no vlan 33', 'exit'])
195 mock_check.assert_called_once_with('fake output', 'delete network')
180 196
181 @mock.patch('networking_generic_switch.devices.netmiko_devices.' 197 @mock.patch('networking_generic_switch.devices.netmiko_devices.'
182 'NetmikoSwitch.send_commands_to_device') 198 'NetmikoSwitch.send_commands_to_device',
183 def test_plug_port_to_network(self, mock_exec): 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 self.switch.plug_port_to_network(3333, 33) 203 self.switch.plug_port_to_network(3333, 33)
185 mock_exec.assert_called_with( 204 mock_exec.assert_called_with(
186 ['interface 3333', 'switchport access vlan 33', 'exit']) 205 ['interface 3333', 'switchport access vlan 33', 'exit'])
206 mock_check.assert_called_once_with('fake output',
207 'plug port')
187 208
188 @mock.patch('networking_generic_switch.devices.netmiko_devices.' 209 @mock.patch('networking_generic_switch.devices.netmiko_devices.'
189 'NetmikoSwitch.send_commands_to_device') 210 'NetmikoSwitch.send_commands_to_device',
190 def test_plug_port_to_network_general_mode(self, mock_exec): 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 switch = self._make_switch_device({'ngs_switchport_mode': 'GENERAL'}) 215 switch = self._make_switch_device({'ngs_switchport_mode': 'GENERAL'})
192 switch.plug_port_to_network(3333, 33) 216 switch.plug_port_to_network(3333, 33)
193 mock_exec.assert_called_with( 217 mock_exec.assert_called_with(
@@ -195,17 +219,26 @@ class TestNetmikoDellPowerConnect(test_netmiko_base.NetmikoSwitchTestBase):
195 'switchport general allowed vlan add 33 untagged', 219 'switchport general allowed vlan add 33 untagged',
196 'switchport general pvid 33', 220 'switchport general pvid 33',
197 'exit']) 221 'exit'])
222 mock_check.assert_called_once_with('fake output',
223 'plug port')
198 224
199 @mock.patch('networking_generic_switch.devices.netmiko_devices.' 225 @mock.patch('networking_generic_switch.devices.netmiko_devices.'
200 'NetmikoSwitch.send_commands_to_device') 226 'NetmikoSwitch.send_commands_to_device',
201 def test_delete_port(self, mock_exec): 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 self.switch.delete_port(3333, 33) 231 self.switch.delete_port(3333, 33)
203 mock_exec.assert_called_with( 232 mock_exec.assert_called_with(
204 ['interface 3333', 'switchport access vlan none', 'exit']) 233 ['interface 3333', 'switchport access vlan none', 'exit'])
234 mock_check.assert_called_once_with('fake output', 'unplug port')
205 235
206 @mock.patch('networking_generic_switch.devices.netmiko_devices.' 236 @mock.patch('networking_generic_switch.devices.netmiko_devices.'
207 'NetmikoSwitch.send_commands_to_device') 237 'NetmikoSwitch.send_commands_to_device',
208 def test_delete_port_general(self, mock_exec): 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 switch = self._make_switch_device({'ngs_switchport_mode': 'GENERAL'}) 242 switch = self._make_switch_device({'ngs_switchport_mode': 'GENERAL'})
210 switch.delete_port(3333, 33) 243 switch.delete_port(3333, 33)
211 mock_exec.assert_called_with( 244 mock_exec.assert_called_with(
@@ -213,6 +246,43 @@ class TestNetmikoDellPowerConnect(test_netmiko_base.NetmikoSwitchTestBase):
213 'switchport general allowed vlan remove 33', 246 'switchport general allowed vlan remove 33',
214 'no switchport general pvid', 247 'no switchport general pvid',
215 'exit']) 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 = """
262vlan database
263vlan 33
264exit
265% Incomplete command
266"""
267 self._test_check_output_error(output)
268
269 def test_check_output_vlan_not_recognised(self):
270 output = """
271vlan database
272vlan 33
273exit
274VLAN 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 = """
280vlan database
281vlan 33
282exit
283Configuration Database locked by another application - try later
284"""
285 self._test_check_output_error(output)
216 286
217 def test__format_commands(self): 287 def test__format_commands(self):
218 cmd_set = self.switch._format_commands( 288 cmd_set = self.switch._format_commands(