David Kranz | b9d9750 | 2013-05-01 15:55:04 -0400 | [diff] [blame^] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | # vim: tabstop=4 shiftwidth=4 softtabstop=4 |
| 4 | |
| 5 | # Copyright 2013 Quanta Research Cambridge, Inc. |
| 6 | # |
| 7 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | # you may not use this file except in compliance with the License. |
| 9 | # You may obtain a copy of the License at |
| 10 | # |
| 11 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | # |
| 13 | # Unless required by applicable law or agreed to in writing, software |
| 14 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | # See the License for the specific language governing permissions and |
| 17 | # limitations under the License. |
| 18 | |
| 19 | from tempest import clients |
| 20 | |
| 21 | |
| 22 | def cleanup(): |
| 23 | admin_manager = clients.AdminManager() |
| 24 | |
| 25 | _, body = admin_manager.servers_client.list_servers({"all_tenants": True}) |
| 26 | for s in body['servers']: |
| 27 | try: |
| 28 | admin_manager.servers_client.delete_server(s['id']) |
| 29 | except Exception: |
| 30 | pass |
| 31 | |
| 32 | for s in body['servers']: |
| 33 | try: |
| 34 | admin_manager.servers_client.wait_for_server_termination(s['id']) |
| 35 | except Exception: |
| 36 | pass |
| 37 | |
| 38 | _, keypairs = admin_manager.keypairs_client.list_keypairs() |
| 39 | for k in keypairs: |
| 40 | try: |
| 41 | admin_manager.keypairs_client.delete_keypair(k['name']) |
| 42 | except Exception: |
| 43 | pass |
| 44 | |
| 45 | _, floating_ips = admin_manager.floating_ips_client.list_floating_ips() |
| 46 | for f in floating_ips: |
| 47 | try: |
| 48 | admin_manager.floating_ips_client.delete_floating_ip(f['id']) |
| 49 | except Exception: |
| 50 | pass |
| 51 | |
| 52 | _, users = admin_manager.identity_client.get_users() |
| 53 | for user in users: |
| 54 | if user['name'].startswith("stress_user"): |
| 55 | admin_manager.identity_client.delete_user(user['id']) |
| 56 | |
| 57 | _, tenants = admin_manager.identity_client.list_tenants() |
| 58 | for tenant in tenants: |
| 59 | if tenant['name'].startswith("stress_tenant"): |
| 60 | admin_manager.identity_client.delete_tenant(tenant['id']) |