3 # All rights reserved. This program and the accompanying materials
4 # are made available under the terms of the Apache License, Version 2.0
5 # which accompanies this distribution, and is available at
6 # http://www.apache.org/licenses/LICENSE-2.0
12 from functest.utils import openstack_clean
13 from functest.tests.unit import test_utils
16 class OSCleanTesting(unittest.TestCase):
18 logging.disable(logging.CRITICAL)
20 def _get_instance(self, key):
21 mock_obj = mock.Mock()
22 attrs = {'id': 'id' + str(key), 'name': 'name' + str(key),
23 'ip': 'ip' + str(key)}
24 mock_obj.configure_mock(**attrs)
28 self.client = mock.Mock()
29 self.test_list = [self._get_instance(1), self._get_instance(2)]
30 self.update_list = {'id1': 'name1', 'id2': 'name2'}
31 self.remove_list = {'id3': 'name3', 'id4': 'name4'}
32 self.test_dict_list = [{'id': 'id1', 'name': 'name1', 'ip': 'ip1',
33 'router:external': False,
34 'external_gateway_info': None},
35 {'id': 'id2', 'name': 'name2', 'ip': 'ip2',
36 'router:external': False,
37 'external_gateway_info': None}]
38 self.routers = [mock.Mock()]
39 self.ports = [mock.Mock()]
41 @mock.patch('functest.utils.openstack_clean.logger.debug')
42 def test_separator(self, mock_logger_debug):
43 openstack_clean.separator()
44 mock_logger_debug.assert_called_once_with("-----------------"
48 @mock.patch('functest.utils.openstack_clean.logger.debug')
49 def test_remove_instances(self, mock_logger_debug):
50 with mock.patch('functest.utils.openstack_clean.os_utils'
51 '.get_instances', return_value=self.test_list):
52 openstack_clean.remove_instances(self.client, self.update_list)
53 mock_logger_debug.assert_any_call("Removing Nova instances...")
54 mock_logger_debug.assert_any_call(" > this is a default "
58 @mock.patch('functest.utils.openstack_clean.logger.debug')
59 def test_remove_instances_missing_instances(self, mock_logger_debug):
60 with mock.patch('functest.utils.openstack_clean.os_utils'
61 '.get_instances', return_value=[]):
62 openstack_clean.remove_instances(self.client, self.update_list)
63 mock_logger_debug.assert_any_call("Removing Nova instances...")
64 mock_logger_debug.assert_any_call("No instances found.")
66 @mock.patch('functest.utils.openstack_clean.logger.debug')
67 def test_remove_instances_delete_success(self, mock_logger_debug):
68 with mock.patch('functest.utils.openstack_clean.os_utils'
69 '.get_instances', return_value=self.test_list), \
70 mock.patch('functest.utils.openstack_clean.os_utils'
71 '.delete_instance', return_value=True):
72 openstack_clean.remove_instances(self.client, self.remove_list)
73 mock_logger_debug.assert_any_call("Removing Nova instances...")
74 mock_logger_debug.assert_any_call(" > Request sent.")
75 mock_logger_debug.assert_any_call(test_utils.RegexMatch("Removing"
80 @mock.patch('functest.utils.openstack_clean.logger.error')
81 @mock.patch('functest.utils.openstack_clean.logger.debug')
82 def test_remove_instances_delete_failed(self, mock_logger_debug,
84 with mock.patch('functest.utils.openstack_clean.os_utils'
85 '.get_instances', return_value=self.test_list), \
86 mock.patch('functest.utils.openstack_clean.os_utils'
87 '.delete_instance', return_value=False):
88 openstack_clean.remove_instances(self.client, self.remove_list)
89 mock_logger_debug.assert_any_call("Removing Nova instances...")
90 mock_logger_error.assert_any_call(test_utils.
91 RegexMatch("There has been a "
95 mock_logger_debug.assert_any_call(test_utils.RegexMatch("Removing"
100 @mock.patch('functest.utils.openstack_clean.logger.debug')
101 def test_remove_images(self, mock_logger_debug):
102 with mock.patch('functest.utils.openstack_clean.os_utils'
103 '.get_images', return_value=self.test_list):
104 openstack_clean.remove_images(self.client, self.update_list)
105 mock_logger_debug.assert_any_call("Removing Glance images...")
106 mock_logger_debug.assert_any_call(" > this is a default "
110 @mock.patch('functest.utils.openstack_clean.logger.debug')
111 def test_remove_images_missing_images(self, mock_logger_debug):
112 with mock.patch('functest.utils.openstack_clean.os_utils'
113 '.get_images', return_value=[]):
114 openstack_clean.remove_images(self.client, self.update_list)
115 mock_logger_debug.assert_any_call("Removing Glance images...")
116 mock_logger_debug.assert_any_call("No images found.")
118 @mock.patch('functest.utils.openstack_clean.logger.debug')
119 def test_remove_images_delete_success(self, mock_logger_debug):
120 with mock.patch('functest.utils.openstack_clean.os_utils'
121 '.get_images', return_value=self.test_list), \
122 mock.patch('functest.utils.openstack_clean.os_utils'
123 '.delete_glance_image', return_value=True):
124 openstack_clean.remove_images(self.client, self.remove_list)
125 mock_logger_debug.assert_any_call("Removing Glance images...")
126 mock_logger_debug.assert_any_call(" > Done!")
127 mock_logger_debug.assert_any_call(test_utils.
128 RegexMatch("Removing image "
132 @mock.patch('functest.utils.openstack_clean.logger.error')
133 @mock.patch('functest.utils.openstack_clean.logger.debug')
134 def test_remove_images_delete_failed(self, mock_logger_debug,
136 with mock.patch('functest.utils.openstack_clean.os_utils'
137 '.get_images', return_value=self.test_list), \
138 mock.patch('functest.utils.openstack_clean.os_utils'
139 '.delete_glance_image', return_value=False):
140 openstack_clean.remove_images(self.client, self.remove_list)
141 mock_logger_debug.assert_any_call("Removing Glance images...")
142 mock_logger_error.assert_any_call(test_utils.
143 RegexMatch("There has been a "
144 "problem removing the"
146 mock_logger_debug.assert_any_call(test_utils.
147 RegexMatch("Removing image "
151 @mock.patch('functest.utils.openstack_clean.logger.debug')
152 def test_remove_volumes(self, mock_logger_debug):
153 with mock.patch('functest.utils.openstack_clean.os_utils'
154 '.get_volumes', return_value=self.test_list):
155 openstack_clean.remove_volumes(self.client, self.update_list)
156 mock_logger_debug.assert_any_call("Removing Cinder volumes...")
157 mock_logger_debug.assert_any_call(" > this is a default "
161 @mock.patch('functest.utils.openstack_clean.logger.debug')
162 def test_remove_volumes_missing_volumes(self, mock_logger_debug):
163 with mock.patch('functest.utils.openstack_clean.os_utils'
164 '.get_volumes', return_value=[]):
165 openstack_clean.remove_volumes(self.client, self.update_list)
166 mock_logger_debug.assert_any_call("Removing Cinder volumes...")
167 mock_logger_debug.assert_any_call("No volumes found.")
169 @mock.patch('functest.utils.openstack_clean.logger.debug')
170 def test_remove_volumes_delete_success(self, mock_logger_debug):
171 with mock.patch('functest.utils.openstack_clean.os_utils'
172 '.get_volumes', return_value=self.test_list), \
173 mock.patch('functest.utils.openstack_clean.os_utils'
174 '.delete_volume', return_value=True):
175 openstack_clean.remove_volumes(self.client, self.remove_list)
176 mock_logger_debug.assert_any_call("Removing Cinder volumes...")
177 mock_logger_debug.assert_any_call(" > Done!")
178 mock_logger_debug.assert_any_call(test_utils.
179 RegexMatch("Removing cinder "
180 "volume \s*\S+ ..."))
182 @mock.patch('functest.utils.openstack_clean.logger.error')
183 @mock.patch('functest.utils.openstack_clean.logger.debug')
184 def test_remove_volumes_delete_failed(self, mock_logger_debug,
186 with mock.patch('functest.utils.openstack_clean.os_utils'
187 '.get_volumes', return_value=self.test_list), \
188 mock.patch('functest.utils.openstack_clean.os_utils'
189 '.delete_volume', return_value=False):
190 openstack_clean.remove_volumes(self.client, self.remove_list)
191 mock_logger_debug.assert_any_call("Removing Cinder volumes...")
192 mock_logger_error.assert_any_call(test_utils.
193 RegexMatch("There has been a "
197 mock_logger_debug.assert_any_call(test_utils.
198 RegexMatch("Removing cinder "
199 "volume \s*\S+ ..."))
201 @mock.patch('functest.utils.openstack_clean.logger.debug')
202 def test_remove_floatingips(self, mock_logger_debug):
203 with mock.patch('functest.utils.openstack_clean.os_utils'
204 '.get_floating_ips', return_value=self.test_list):
205 openstack_clean.remove_floatingips(self.client, self.update_list)
206 mock_logger_debug.assert_any_call("Removing floating IPs...")
207 mock_logger_debug.assert_any_call(" > this is a default "
208 "floating IP and will "
211 @mock.patch('functest.utils.openstack_clean.logger.debug')
212 def test_remove_floatingips_missing_floatingips(self, mock_logger_debug):
213 with mock.patch('functest.utils.openstack_clean.os_utils'
214 '.get_floating_ips', return_value=[]):
215 openstack_clean.remove_floatingips(self.client, self.update_list)
216 mock_logger_debug.assert_any_call("Removing floating IPs...")
217 mock_logger_debug.assert_any_call("No floating IPs found.")
219 @mock.patch('functest.utils.openstack_clean.logger.debug')
220 def test_remove_floatingips_delete_success(self, mock_logger_debug):
221 with mock.patch('functest.utils.openstack_clean.os_utils'
222 '.get_floating_ips', return_value=self.test_list), \
223 mock.patch('functest.utils.openstack_clean.os_utils'
224 '.delete_volume', return_value=True):
225 openstack_clean.remove_floatingips(self.client, self.remove_list)
226 mock_logger_debug.assert_any_call("Removing floating IPs...")
227 mock_logger_debug.assert_any_call(" > Done!")
228 mock_logger_debug.assert_any_call(test_utils.
229 RegexMatch("Removing floating "
232 @mock.patch('functest.utils.openstack_clean.logger.error')
233 @mock.patch('functest.utils.openstack_clean.logger.debug')
234 def test_remove_floatingips_delete_failed(self, mock_logger_debug,
236 with mock.patch('functest.utils.openstack_clean.os_utils'
237 '.get_floating_ips', return_value=self.test_list), \
238 mock.patch('functest.utils.openstack_clean.os_utils'
239 '.delete_floating_ip', return_value=False):
240 openstack_clean.remove_floatingips(self.client, self.remove_list)
241 mock_logger_debug.assert_any_call("Removing floating IPs...")
242 mock_logger_error.assert_any_call(test_utils.
243 RegexMatch("There has been a "
247 mock_logger_debug.assert_any_call(test_utils.
248 RegexMatch("Removing floating "
251 @mock.patch('functest.utils.openstack_clean.remove_routers')
252 @mock.patch('functest.utils.openstack_clean.remove_ports')
253 @mock.patch('functest.utils.openstack_clean.logger.debug')
254 def test_remove_networks(self, mock_logger_debug,
256 mock_remove_routers):
257 with mock.patch('functest.utils.openstack_clean.os_utils'
259 return_value=self.test_dict_list), \
260 mock.patch('functest.utils.openstack_clean.os_utils'
261 '.get_port_list', return_value=self.ports), \
262 mock.patch('functest.utils.openstack_clean.os_utils'
263 '.get_router_list', return_value=self.routers):
264 openstack_clean.remove_networks(self.client, self.update_list,
266 mock_logger_debug.assert_any_call("Removing Neutron objects")
267 mock_logger_debug.assert_any_call(" > this is a default "
270 mock_remove_ports.assert_called_once_with(self.client, self.ports,
272 mock_remove_routers.assert_called_once_with(self.client,
276 @mock.patch('functest.utils.openstack_clean.remove_routers')
277 @mock.patch('functest.utils.openstack_clean.remove_ports')
278 @mock.patch('functest.utils.openstack_clean.logger.debug')
279 def test_remove_networks_missing_networks(self, mock_logger_debug,
281 mock_remove_routers):
282 with mock.patch('functest.utils.openstack_clean.os_utils'
283 '.get_network_list', return_value=None), \
284 mock.patch('functest.utils.openstack_clean.os_utils'
285 '.get_port_list', return_value=self.ports), \
286 mock.patch('functest.utils.openstack_clean.os_utils'
287 '.get_router_list', return_value=self.routers):
288 openstack_clean.remove_networks(self.client, self.update_list,
290 mock_logger_debug.assert_any_call("Removing Neutron objects")
291 mock_logger_debug.assert_any_call("There are no networks in the"
293 mock_remove_ports.assert_called_once_with(self.client, self.ports,
295 mock_remove_routers.assert_called_once_with(self.client,
299 @mock.patch('functest.utils.openstack_clean.remove_routers')
300 @mock.patch('functest.utils.openstack_clean.remove_ports')
301 @mock.patch('functest.utils.openstack_clean.logger.debug')
302 def test_remove_networks_delete_success(self, mock_logger_debug,
304 mock_remove_routers):
306 with mock.patch('functest.utils.openstack_clean.os_utils'
308 return_value=self.test_dict_list), \
309 mock.patch('functest.utils.openstack_clean.os_utils'
310 '.delete_neutron_net', return_value=True), \
311 mock.patch('functest.utils.openstack_clean.os_utils'
312 '.get_port_list', return_value=self.ports), \
313 mock.patch('functest.utils.openstack_clean.os_utils'
314 '.get_router_list', return_value=self.routers):
315 openstack_clean.remove_networks(self.client, self.remove_list,
317 mock_logger_debug.assert_any_call("Removing Neutron objects")
318 mock_logger_debug.assert_any_call(" > this network will be "
320 mock_logger_debug.assert_any_call(" > Done!")
321 mock_logger_debug.assert_any_call(test_utils.
322 RegexMatch("Removing network "
324 mock_remove_ports.assert_called_once_with(self.client, self.ports,
326 mock_remove_routers.assert_called_once_with(self.client,
330 @mock.patch('functest.utils.openstack_clean.remove_routers')
331 @mock.patch('functest.utils.openstack_clean.remove_ports')
332 @mock.patch('functest.utils.openstack_clean.logger.error')
333 @mock.patch('functest.utils.openstack_clean.logger.debug')
334 def test_remove_networks_delete_failed(self, mock_logger_debug,
337 mock_remove_routers):
338 with mock.patch('functest.utils.openstack_clean.os_utils'
340 return_value=self.test_dict_list), \
341 mock.patch('functest.utils.openstack_clean.os_utils'
342 '.delete_neutron_net', return_value=False), \
343 mock.patch('functest.utils.openstack_clean.os_utils'
344 '.get_port_list', return_value=self.ports), \
345 mock.patch('functest.utils.openstack_clean.os_utils'
346 '.get_router_list', return_value=self.routers):
347 openstack_clean.remove_networks(self.client, self.remove_list,
349 mock_logger_debug.assert_any_call("Removing Neutron objects")
350 mock_logger_error.assert_any_call(test_utils.
351 RegexMatch("There has been a"
353 " the network \s*\S+"
355 mock_logger_debug.assert_any_call(test_utils.
356 RegexMatch("Removing network "
358 mock_remove_ports.assert_called_once_with(self.client, self.ports,
360 mock_remove_routers.assert_called_once_with(self.client,
365 @mock.patch('functest.utils.openstack_clean.os_utils.update_neutron_port')
366 @mock.patch('functest.utils.openstack_clean.logger.error')
367 @mock.patch('functest.utils.openstack_clean.logger.debug')
368 def test_force_remove_port(self, mock_logger_debug,
370 mock_update_neutron_port):
371 with mock.patch('functest.utils.openstack_clean.os_utils'
372 '.delete_neutron_port',
374 openstack_clean.force_remove_port(self.client, 'id')
375 mock_logger_debug.assert_any_call(" > Done!")
376 mock_logger_debug.assert_any_call(test_utils.
377 RegexMatch("Clearing device_"
381 @mock.patch('functest.utils.openstack_clean.os_utils.update_neutron_port')
382 @mock.patch('functest.utils.openstack_clean.logger.error')
383 @mock.patch('functest.utils.openstack_clean.logger.debug')
384 def test_force_remove_port_failed(self, mock_logger_debug,
386 mock_update_neutron_port):
387 with mock.patch('functest.utils.openstack_clean.os_utils'
388 '.delete_neutron_port',
390 openstack_clean.force_remove_port(self.client, 'id')
391 mock_logger_error.assert_any_call("There has been a "
394 mock_logger_debug.assert_any_call(test_utils.
395 RegexMatch("Clearing device_"
399 @mock.patch('functest.utils.openstack_clean.logger.debug')
400 def test_remove_routers_missing_routers(self, mock_logger_debug):
401 with mock.patch('functest.utils.openstack_clean.os_utils'
402 '.delete_neutron_router',
404 openstack_clean.remove_routers(self.client, self.test_dict_list,
406 mock_logger_debug.assert_any_call("Router is not connected"
408 "Ready to remove...")
409 mock_logger_debug.assert_any_call(" > Done!")
410 mock_logger_debug.assert_any_call(test_utils.
411 RegexMatch("Removing router "
412 "\s*\S+(\s*\S+) ..."))
414 @mock.patch('functest.utils.openstack_clean.logger.error')
415 @mock.patch('functest.utils.openstack_clean.logger.debug')
416 def test_remove_routers_failed(self, mock_logger_debug,
418 with mock.patch('functest.utils.openstack_clean.os_utils'
419 '.delete_neutron_router',
421 openstack_clean.remove_routers(self.client, self.test_dict_list,
423 mock_logger_debug.assert_any_call("Router is not connected"
425 "Ready to remove...")
426 mock_logger_debug.assert_any_call(test_utils.
427 RegexMatch("Removing router "
428 "\s*\S+(\s*\S+) ..."))
429 mock_logger_error.assert_any_call(test_utils.
430 RegexMatch("There has been "
436 @mock.patch('functest.utils.openstack_clean.logger.error')
437 @mock.patch('functest.utils.openstack_clean.logger.debug')
438 def test_remove_missing_external_gateway(self, mock_logger_debug,
440 with mock.patch('functest.utils.openstack_clean.os_utils'
441 '.delete_neutron_router',
442 return_value=False), \
443 mock.patch('functest.utils.openstack_clean.os_utils'
444 '.remove_gateway_router',
446 self.test_dict_list[0]['external_gateway_info'] = mock.Mock()
447 openstack_clean.remove_routers(self.client, self.test_dict_list,
449 mock_logger_debug.assert_any_call("Router has gateway to external"
450 " network.Removing link...")
451 mock_logger_error.assert_any_call("There has been a problem "
452 "removing the gateway...")
453 mock_logger_debug.assert_any_call(test_utils.
454 RegexMatch("Removing router "
455 "\s*\S+(\s*\S+) ..."))
456 mock_logger_error.assert_any_call(test_utils.
457 RegexMatch("There has been "
463 @mock.patch('functest.utils.openstack_clean.logger.debug')
464 def remove_security_groups(self, mock_logger_debug):
465 with mock.patch('functest.utils.openstack_clean.os_utils'
466 '.get_security_groups',
467 return_value=self.test_dict_list):
468 openstack_clean.remove_security_groups(self.client,
470 mock_logger_debug.assert_any_call("Removing Security groups...")
471 mock_logger_debug.assert_any_call(" > this is a default "
472 "security group and will NOT "
475 @mock.patch('functest.utils.openstack_clean.logger.debug')
476 def test_remove_security_groups_missing_sec_group(self, mock_logger_debug):
477 with mock.patch('functest.utils.openstack_clean.os_utils'
478 '.get_security_groups', return_value=[]):
479 openstack_clean.remove_security_groups(self.client,
481 mock_logger_debug.assert_any_call("Removing Security groups...")
482 mock_logger_debug.assert_any_call("No security groups found.")
484 @mock.patch('functest.utils.openstack_clean.logger.debug')
485 def test_remove_security_groups_delete_success(self, mock_logger_debug):
486 with mock.patch('functest.utils.openstack_clean.os_utils'
487 '.get_security_groups',
488 return_value=self.test_dict_list), \
489 mock.patch('functest.utils.openstack_clean.os_utils'
490 '.delete_security_group', return_value=True):
491 openstack_clean.remove_security_groups(self.client,
493 mock_logger_debug.assert_any_call("Removing Security groups...")
494 mock_logger_debug.assert_any_call(" > Done!")
495 mock_logger_debug.assert_any_call(test_utils.
496 RegexMatch(" Removing \s*\S+"
499 @mock.patch('functest.utils.openstack_clean.logger.error')
500 @mock.patch('functest.utils.openstack_clean.logger.debug')
501 def test_remove_security_groups_delete_failed(self, mock_logger_debug,
503 with mock.patch('functest.utils.openstack_clean.os_utils'
504 '.get_security_groups',
505 return_value=self.test_dict_list), \
506 mock.patch('functest.utils.openstack_clean.os_utils'
507 '.delete_security_group', return_value=False):
508 openstack_clean.remove_security_groups(self.client,
510 mock_logger_debug.assert_any_call("Removing Security groups...")
511 mock_logger_error.assert_any_call(test_utils.
512 RegexMatch("There has been a "
516 mock_logger_debug.assert_any_call(test_utils.
517 RegexMatch(" Removing \s*\S+"
520 @mock.patch('functest.utils.openstack_clean.logger.debug')
521 def test_remove_users(self, mock_logger_debug):
522 with mock.patch('functest.utils.openstack_clean.os_utils'
523 '.get_users', return_value=self.test_list):
524 openstack_clean.remove_users(self.client, self.update_list)
525 mock_logger_debug.assert_any_call("Removing Users...")
526 mock_logger_debug.assert_any_call(" > this is a default "
530 @mock.patch('functest.utils.openstack_clean.logger.debug')
531 def test_remove_users_missing_users(self, mock_logger_debug):
532 with mock.patch('functest.utils.openstack_clean.os_utils'
533 '.get_users', return_value=None):
534 openstack_clean.remove_users(self.client, self.update_list)
535 mock_logger_debug.assert_any_call("Removing Users...")
536 mock_logger_debug.assert_any_call("There are no users in"
539 @mock.patch('functest.utils.openstack_clean.logger.debug')
540 def test_remove_users_delete_success(self, mock_logger_debug):
541 with mock.patch('functest.utils.openstack_clean.os_utils'
542 '.get_users', return_value=self.test_list), \
543 mock.patch('functest.utils.openstack_clean.os_utils'
544 '.delete_user', return_value=True):
545 openstack_clean.remove_users(self.client, self.remove_list)
546 mock_logger_debug.assert_any_call("Removing Users...")
547 mock_logger_debug.assert_any_call(" > Done!")
548 mock_logger_debug.assert_any_call(test_utils.
549 RegexMatch(" Removing "
552 @mock.patch('functest.utils.openstack_clean.logger.error')
553 @mock.patch('functest.utils.openstack_clean.logger.debug')
554 def test_remove_users_delete_failed(self, mock_logger_debug,
556 with mock.patch('functest.utils.openstack_clean.os_utils'
557 '.get_users', return_value=self.test_list), \
558 mock.patch('functest.utils.openstack_clean.os_utils'
559 '.delete_user', return_value=False):
560 openstack_clean.remove_users(self.client, self.remove_list)
561 mock_logger_debug.assert_any_call("Removing Users...")
562 mock_logger_error.assert_any_call(test_utils.
563 RegexMatch("There has been a "
567 mock_logger_debug.assert_any_call(test_utils.
568 RegexMatch(" Removing "
571 @mock.patch('functest.utils.openstack_clean.logger.debug')
572 def test_remove_tenants(self, mock_logger_debug):
573 with mock.patch('functest.utils.openstack_clean.os_utils'
574 '.get_tenants', return_value=self.test_list):
575 openstack_clean.remove_tenants(self.client, self.update_list)
576 mock_logger_debug.assert_any_call("Removing Tenants...")
577 mock_logger_debug.assert_any_call(" > this is a default"
581 @mock.patch('functest.utils.openstack_clean.logger.debug')
582 def test_remove_tenants_missing_tenants(self, mock_logger_debug):
583 with mock.patch('functest.utils.openstack_clean.os_utils'
584 '.get_tenants', return_value=None):
585 openstack_clean.remove_tenants(self.client, self.update_list)
586 mock_logger_debug.assert_any_call("Removing Tenants...")
587 mock_logger_debug.assert_any_call("There are no tenants in"
590 @mock.patch('functest.utils.openstack_clean.logger.debug')
591 def test_remove_tenants_delete_success(self, mock_logger_debug):
592 with mock.patch('functest.utils.openstack_clean.os_utils'
593 '.get_tenants', return_value=self.test_list), \
594 mock.patch('functest.utils.openstack_clean.os_utils'
595 '.delete_tenant', return_value=True):
596 openstack_clean.remove_tenants(self.client, self.remove_list)
597 mock_logger_debug.assert_any_call("Removing Tenants...")
598 mock_logger_debug.assert_any_call(" > Done!")
599 mock_logger_debug.assert_any_call(test_utils.
600 RegexMatch(" Removing "
603 @mock.patch('functest.utils.openstack_clean.logger.error')
604 @mock.patch('functest.utils.openstack_clean.logger.debug')
605 def test_remove_tenants_delete_failed(self, mock_logger_debug,
607 with mock.patch('functest.utils.openstack_clean.os_utils'
608 '.get_tenants', return_value=self.test_list), \
609 mock.patch('functest.utils.openstack_clean.os_utils'
610 '.delete_tenant', return_value=False):
611 openstack_clean.remove_tenants(self.client, self.remove_list)
612 mock_logger_debug.assert_any_call("Removing Tenants...")
613 mock_logger_error.assert_any_call(test_utils.
614 RegexMatch("There has been a "
618 mock_logger_debug.assert_any_call(test_utils.
619 RegexMatch(" Removing "
622 @mock.patch('functest.utils.openstack_clean.os_utils.get_cinder_client')
623 @mock.patch('functest.utils.openstack_clean.os_utils'
624 '.get_keystone_client')
625 @mock.patch('functest.utils.openstack_clean.os_utils'
626 '.get_neutron_client')
627 @mock.patch('functest.utils.openstack_clean.os_utils.get_nova_client')
628 @mock.patch('functest.utils.openstack_clean.os_utils.check_credentials',
630 @mock.patch('functest.utils.openstack_clean.logger.info')
631 @mock.patch('functest.utils.openstack_clean.logger.debug')
632 def test_main_default(self, mock_logger_debug, mock_logger_info,
633 mock_creds, mock_nova, mock_neutron,
634 mock_keystone, mock_cinder):
636 with mock.patch('functest.utils.openstack_clean.remove_instances') \
637 as mock_remove_instances, \
638 mock.patch('functest.utils.openstack_clean.remove_images') \
639 as mock_remove_images, \
640 mock.patch('functest.utils.openstack_clean.remove_volumes') \
641 as mock_remove_volumes, \
642 mock.patch('functest.utils.openstack_clean.remove_floatingips') \
643 as mock_remove_floatingips, \
644 mock.patch('functest.utils.openstack_clean.remove_networks') \
645 as mock_remove_networks, \
646 mock.patch('functest.utils.openstack_clean.'
647 'remove_security_groups') \
648 as mock_remove_security_groups, \
649 mock.patch('functest.utils.openstack_clean.remove_users') \
650 as mock_remove_users, \
651 mock.patch('functest.utils.openstack_clean.remove_tenants') \
652 as mock_remove_tenants, \
653 mock.patch('functest.utils.openstack_clean.yaml.safe_load',
654 return_value=mock.Mock()), \
655 mock.patch('__builtin__.open', mock.mock_open()) as m:
656 openstack_clean.main()
657 self.assertTrue(mock_remove_instances)
658 self.assertTrue(mock_remove_images)
659 self.assertTrue(mock_remove_volumes)
660 self.assertTrue(mock_remove_floatingips)
661 self.assertTrue(mock_remove_networks)
662 self.assertTrue(mock_remove_security_groups)
663 self.assertTrue(mock_remove_users)
664 self.assertTrue(mock_remove_tenants)
665 m.assert_called_once_with(openstack_clean.OS_SNAPSHOT_FILE)
666 mock_logger_info.assert_called_once_with("Cleaning OpenStack "
670 if __name__ == "__main__":
671 unittest.main(verbosity=2)