~juju-qa/juju-ci-tools/trunk

« back to all changes in this revision

Viewing changes to run_deployer.py

  • Committer: John George
  • Date: 2015-06-30 07:22:09 UTC
  • mto: This revision was merged to the branch mainline in revision 1013.
  • Revision ID: john.george@canonical.com-20150630072209-cjredkcw9cd2gm9q
Add juju-ci-openstack-check.sh and move run_deployer() out of deploy_stack.py.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/env python
2
 
from deploy_stack import run_deployer
 
2
from argparse import ArgumentParser
 
3
import logging
 
4
import subprocess
 
5
 
 
6
from deploy_stack import (
 
7
    boot_context,
 
8
    get_log_level,
 
9
    get_juju_path,
 
10
)
 
11
from jujupy import (
 
12
    EnvJujuClient,
 
13
    SimpleEnvironment,
 
14
)
 
15
from utility import (
 
16
    configure_logging,
 
17
)
 
18
 
 
19
 
 
20
def is_healthy(cmd_path):
 
21
    """Returns a boolean after running the health_checker."""
 
22
    try:
 
23
        sub_output = subprocess.check_output(cmd_path)
 
24
        logging.info('Health check output: {}'.format(sub_output))
 
25
    except OSError as e:
 
26
        logging.error(
 
27
            'The health check script failed to execute with: {}'.format(
 
28
                e))
 
29
        raise
 
30
    except subprocess.CalledProcessError as e:
 
31
        logging.error('Non-zero exit code returned from {}: {}'.format(
 
32
            cmd_path, e))
 
33
        logging.error(e.output)
 
34
        return False
 
35
    return True
 
36
 
 
37
 
 
38
def run_deployer():
 
39
    parser = ArgumentParser()
 
40
    parser.add_argument('bundle_path',
 
41
                        help='URL or path to a bundle')
 
42
    parser.add_argument('env',
 
43
                        help='The juju environment to test')
 
44
    parser.add_argument('logs', help='log directory.')
 
45
    parser.add_argument('job_name', help='Name of the Jenkins job.')
 
46
    parser.add_argument('--bundle-name', default=None,
 
47
                        help='Name of the bundle to deploy.')
 
48
    parser.add_argument('--health-cmd', default=None,
 
49
                        help='A binary for checking the health of the'
 
50
                        ' deployed bundle.')
 
51
    parser.add_argument('--keep-env', action='store_true', default=False,
 
52
                        help='Keep the Juju environment after the test'
 
53
                        ' completes.')
 
54
    parser.add_argument('--agent-url', default=None,
 
55
                        help='URL to use for retrieving agent binaries.')
 
56
    parser.add_argument('--agent-stream', default=None,
 
57
                        help='stream name for retrieving agent binaries.')
 
58
    parser.add_argument('--series',
 
59
                        help='Name of the Ubuntu series to use.')
 
60
    parser.add_argument('--debug', action="store_true", default=False,
 
61
                        help='Use --debug juju logging.')
 
62
    parser.add_argument('--verbose', '-v', action="store_true", default=False,
 
63
                        help='Increase logging verbosity.')
 
64
 
 
65
    parser.add_argument('--new-juju-bin', default=None,
 
66
                        help='Dirctory containing the new Juju binary.')
 
67
    args = parser.parse_args()
 
68
    juju_path = get_juju_path(args)
 
69
    configure_logging(get_log_level(args))
 
70
    env = SimpleEnvironment.from_config(args.env)
 
71
    client = EnvJujuClient.by_version(env, juju_path, debug=args.debug)
 
72
    with boot_context(args.job_name, client, None, [], args.series,
 
73
                      args.agent_url, args.agent_stream, args.logs,
 
74
                      args.keep_env, False):
 
75
        client.deployer(args.bundle_path, args.bundle_name)
 
76
        if args.health_cmd:
 
77
            is_healthy(args.health_cmd)
3
78
if __name__ == '__main__':
4
79
    run_deployer()