blob: 1bd94853eb371c6c196fe9339381e383029d2835 [file] [log] [blame]
David Kranzb9d97502013-05-01 15:55:04 -04001#!/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
19from tempest import clients
Marc Kodererb714de52013-08-08 09:21:46 +020020from tempest.openstack.common import log as logging
21
22LOG = logging.getLogger(__name__)
David Kranzb9d97502013-05-01 15:55:04 -040023
24
Marc Kodererb714de52013-08-08 09:21:46 +020025def cleanup():
David Kranzb9d97502013-05-01 15:55:04 -040026 admin_manager = clients.AdminManager()
27
28 _, body = admin_manager.servers_client.list_servers({"all_tenants": True})
Marc Kodererb714de52013-08-08 09:21:46 +020029 LOG.info("Cleanup::remove %s servers" % len(body['servers']))
David Kranzb9d97502013-05-01 15:55:04 -040030 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 Kodererb714de52013-08-08 09:21:46 +020043 LOG.info("Cleanup::remove %s keypairs" % len(keypairs))
David Kranzb9d97502013-05-01 15:55:04 -040044 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 Kodererb714de52013-08-08 09:21:46 +020051 LOG.info("Cleanup::remove %s floating ips" % len(floating_ips))
David Kranzb9d97502013-05-01 15:55:04 -040052 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 Kodererb714de52013-08-08 09:21:46 +020059 LOG.info("Cleanup::remove %s users" % len(users))
David Kranzb9d97502013-05-01 15:55:04 -040060 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 Kodererb714de52013-08-08 09:21:46 +020065 LOG.info("Cleanup::remove %s tenants" % len(tenants))
David Kranzb9d97502013-05-01 15:55:04 -040066 for tenant in tenants:
67 if tenant['name'].startswith("stress_tenant"):
68 admin_manager.identity_client.delete_tenant(tenant['id'])
Giulio Fidentebbb69e72013-06-18 16:06:24 +020069
Walter A. Boring IVb725e622013-07-11 17:21:33 -070070 # 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 Kodererb714de52013-08-08 09:21:46 +020075 LOG.info("Cleanup::remove %s snapshots" % len(snaps))
Walter A. Boring IVb725e622013-07-11 17:21:33 -070076 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 Fidentebbb69e72013-06-18 16:06:24 +020090 _, vols = admin_manager.volumes_client.list_volumes({"all_tenants": True})
Marc Kodererb714de52013-08-08 09:21:46 +020091 LOG.info("Cleanup::remove %s volumes" % len(vols))
Giulio Fidentebbb69e72013-06-18 16:06:24 +020092 for v in vols:
93 try:
Walter A. Boring IVb725e622013-07-11 17:21:33 -070094 admin_manager.volumes_client.\
95 wait_for_volume_status(v['id'], 'available')
Giulio Fidentebbb69e72013-06-18 16:06:24 +020096 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