29
def destroy_all_services(name, base):
30
"""Destroy all services for a particular juju environment.
32
This is necessary since destroying the environment does not shut down
33
services cleanly. This can result in (for example) stale rabbit
36
# This can take a while, so let's limit the damage to 5 minutes:
38
env_dir = os.path.join(base, name)
39
env = os.environ.copy()
40
env['JUJU_HOME'] = env_dir
42
for service in get_active_services(name, base):
44
['juju', 'destroy-service', service],
47
start_time = time.time()
48
while time.time() - start_time < timeout:
49
services = get_active_services(name, base)
50
if len(services) == 0:
53
except subprocess.CalledProcessError as e:
54
print("juju status failed: %s" % e)
58
def get_active_services(name, base):
59
"""Get a list of the services currently active.
61
Ignores ksplice, landscape and basenode.
69
env_dir = os.path.join(base, name)
70
env = os.environ.copy()
71
env['JUJU_HOME'] = env_dir
73
args = ['juju', 'status']
74
juju_status = yaml.load(
75
subprocess.check_output(args, env=env)
77
return [s for s in juju_status['services'] if s not in ignored_services]
29
80
def destroy_environment(name, base):
30
81
# We can safely destroy the existing environment, as the services are
31
82
# promised to be idempotent.