~nskaggs/juju-ci-tools/add-essential-operations

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python
from argparse import ArgumentParser
from json import dump
import os
from os.path import (
    basename,
    dirname,
    join,
)
import subprocess
import sys


SCRIPTS = dirname(__file__)


def main(argv=None):
    parser = ArgumentParser()
    parser.add_argument('host', help='The machine to test on.')
    parser.add_argument('revision_or_tarfile',
                        help='The revision-build or tarfile path to test.')
    parser.add_argument('package', nargs='?', default='github.com/juju/juju',
                        help='The package to test.')
    args = parser.parse_args(argv)

    if args.revision_or_tarfile.endswith('tar.gz'):
        downloaded = args.revision_or_tarfile
    else:
        revision = args.revision_or_tarfile
        juju_ci_path = join(SCRIPTS, 'jujuci.py')
        downloaded = subprocess.check_output([
            juju_ci_path, 'get', '-b', revision, 'build-revision',
            '*.tar.gz', './'])
        subprocess.check_call([
            juju_ci_path, 'get-build-vars', '--summary', revision])
    (tarfile,) = [basename(l) for l in downloaded.splitlines()]

    with open('temp-config.yaml', 'w') as temp_file:
        dump({
            'install': {'ci': [
                tarfile,
                join(SCRIPTS, 'gotesttarfile.py'),
                join(SCRIPTS, 'jujucharm.py'),
                join(SCRIPTS, 'utility.py'),
                ]},
            'command': [
                'python', 'ci/gotesttarfile.py', '-v', '-g', 'go.exe', '-p',
                args.package, '--remove', 'ci/{}'.format(tarfile)
                ]},
             temp_file)
    juju_home = os.environ.get('JUJU_HOME',
                               join(dirname(SCRIPTS), 'cloud-city'))
    subprocess.check_call([
        'workspace-run', '-v', '-i', join(juju_home, 'staging-juju-rsa'),
        'temp-config.yaml', 'Administrator@{}'.format(args.host)
        ])


if __name__ == '__main__':
    main(sys.argv[1:])