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 |
Marc Koderer | b714de5 | 2013-08-08 09:21:46 +0200 | [diff] [blame] | 20 | from tempest.openstack.common import log as logging |
| 21 | |
| 22 | LOG = logging.getLogger(__name__) |
David Kranz | b9d9750 | 2013-05-01 15:55:04 -0400 | [diff] [blame] | 23 | |
| 24 | |
Marc Koderer | b714de5 | 2013-08-08 09:21:46 +0200 | [diff] [blame] | 25 | def cleanup(): |
David Kranz | b9d9750 | 2013-05-01 15:55:04 -0400 | [diff] [blame] | 26 | admin_manager = clients.AdminManager() |
| 27 | |
| 28 | _, body = admin_manager.servers_client.list_servers({"all_tenants": True}) |
Marc Koderer | b714de5 | 2013-08-08 09:21:46 +0200 | [diff] [blame] | 29 | LOG.info("Cleanup::remove %s servers" % len(body['servers'])) |
David Kranz | b9d9750 | 2013-05-01 15:55:04 -0400 | [diff] [blame] | 30 | for s in body['servers']: |
| 31 | try: |
| 32 | admin_manager.servers_client.delete_server(s['id']) |
| 33 | except Exception: |
| 34 | pass |
| 35 | |
| 36 | for s in body['servers']: |
| 37 | try: |
| 38 | admin_manager.servers_client.wait_for_server_termination(s['id']) |
| 39 | except Exception: |
| 40 | pass |
| 41 | |
| 42 | _, keypairs = admin_manager.keypairs_client.list_keypairs() |
Marc Koderer | b714de5 | 2013-08-08 09:21:46 +0200 | [diff] [blame] | 43 | LOG.info("Cleanup::remove %s keypairs" % len(keypairs)) |
David Kranz | b9d9750 | 2013-05-01 15:55:04 -0400 | [diff] [blame] | 44 | for k in keypairs: |
| 45 | try: |
| 46 | admin_manager.keypairs_client.delete_keypair(k['name']) |
| 47 | except Exception: |
| 48 | pass |
| 49 | |
| 50 | _, floating_ips = admin_manager.floating_ips_client.list_floating_ips() |
Marc Koderer | b714de5 | 2013-08-08 09:21:46 +0200 | [diff] [blame] | 51 | LOG.info("Cleanup::remove %s floating ips" % len(floating_ips)) |
David Kranz | b9d9750 | 2013-05-01 15:55:04 -0400 | [diff] [blame] | 52 | for f in floating_ips: |
| 53 | try: |
| 54 | admin_manager.floating_ips_client.delete_floating_ip(f['id']) |
| 55 | except Exception: |
| 56 | pass |
| 57 | |
| 58 | _, users = admin_manager.identity_client.get_users() |
Marc Koderer | b714de5 | 2013-08-08 09:21:46 +0200 | [diff] [blame] | 59 | LOG.info("Cleanup::remove %s users" % len(users)) |
David Kranz | b9d9750 | 2013-05-01 15:55:04 -0400 | [diff] [blame] | 60 | for user in users: |
| 61 | if user['name'].startswith("stress_user"): |
| 62 | admin_manager.identity_client.delete_user(user['id']) |
| 63 | |
| 64 | _, tenants = admin_manager.identity_client.list_tenants() |
Marc Koderer | b714de5 | 2013-08-08 09:21:46 +0200 | [diff] [blame] | 65 | LOG.info("Cleanup::remove %s tenants" % len(tenants)) |
David Kranz | b9d9750 | 2013-05-01 15:55:04 -0400 | [diff] [blame] | 66 | for tenant in tenants: |
| 67 | if tenant['name'].startswith("stress_tenant"): |
| 68 | admin_manager.identity_client.delete_tenant(tenant['id']) |
Giulio Fidente | bbb69e7 | 2013-06-18 16:06:24 +0200 | [diff] [blame] | 69 | |
Walter A. Boring IV | b725e62 | 2013-07-11 17:21:33 -0700 | [diff] [blame] | 70 | # We have to delete snapshots first or |
| 71 | # volume deletion may block |
| 72 | |
| 73 | _, snaps = admin_manager.snapshots_client.\ |
| 74 | list_snapshots({"all_tenants": True}) |
Marc Koderer | b714de5 | 2013-08-08 09:21:46 +0200 | [diff] [blame] | 75 | LOG.info("Cleanup::remove %s snapshots" % len(snaps)) |
Walter A. Boring IV | b725e62 | 2013-07-11 17:21:33 -0700 | [diff] [blame] | 76 | for v in snaps: |
| 77 | try: |
| 78 | admin_manager.snapshots_client.\ |
| 79 | wait_for_snapshot_status(v['id'], 'available') |
| 80 | admin_manager.snapshots_client.delete_snapshot(v['id']) |
| 81 | except Exception: |
| 82 | pass |
| 83 | |
| 84 | for v in snaps: |
| 85 | try: |
| 86 | admin_manager.snapshots_client.wait_for_resource_deletion(v['id']) |
| 87 | except Exception: |
| 88 | pass |
| 89 | |
Giulio Fidente | bbb69e7 | 2013-06-18 16:06:24 +0200 | [diff] [blame] | 90 | _, vols = admin_manager.volumes_client.list_volumes({"all_tenants": True}) |
Marc Koderer | b714de5 | 2013-08-08 09:21:46 +0200 | [diff] [blame] | 91 | LOG.info("Cleanup::remove %s volumes" % len(vols)) |
Giulio Fidente | bbb69e7 | 2013-06-18 16:06:24 +0200 | [diff] [blame] | 92 | for v in vols: |
| 93 | try: |
Walter A. Boring IV | b725e62 | 2013-07-11 17:21:33 -0700 | [diff] [blame] | 94 | admin_manager.volumes_client.\ |
| 95 | wait_for_volume_status(v['id'], 'available') |
Giulio Fidente | bbb69e7 | 2013-06-18 16:06:24 +0200 | [diff] [blame] | 96 | admin_manager.volumes_client.delete_volume(v['id']) |
| 97 | except Exception: |
| 98 | pass |
| 99 | |
| 100 | for v in vols: |
| 101 | try: |
| 102 | admin_manager.volumes_client.wait_for_resource_deletion(v['id']) |
| 103 | except Exception: |
| 104 | pass |