def main():
args = parse_args()
log_dir = args.logs
try:
setup_juju_path(args.juju_path)
client = make_client(args.juju_path, args.debug, args.env_name,
args.temp_env_name)
juju_home = get_juju_home()
ensure_deleted(get_jenv_path(juju_home, client.env.environment))
with temp_bootstrap_env(juju_home, client):
client.bootstrap()
bootstrap_host = get_machine_dns_name(client, 0)
try:
try:
client.get_status(60)
except CannotConnectEnv:
print("Status got Unable to connect to env. Retrying...")
client.get_status(60)
client.wait_for_started()
client.juju("deploy", ('local:trusty/fill-logs',))
client.wait_for_started(60)
test_unit_rotation(client)
test_machine_rotation(client)
except Exception as e:
try:
if bootstrap_host is None:
bootstrap_host = parse_new_state_server_from_error(e)
dump_env_logs(client, bootstrap_host, log_dir)
except Exception as e2:
# make sure we don't mask the original exception if this stuff fails.
print_now("exception while dumping logs:\n")
logging.exception(e2)
raise
finally:
client.destroy_environment()
except Exception as e3:
print_now("\nEXCEPTION CAUGHT:\n")
logging.exception(e3)
if getattr(e3, 'output', None):
print_now('\n')
print_now(e.output)
print_now("\nFAIL")
sys.exit(1)