~abentley/juju-ci-tools/client-from-config-4

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
61
62
63
64
65
66
#!/usr/bin/env python
from argparse import ArgumentParser
from glob import glob
import json
import os
from os.path import (
    dirname,
    join,
    )
import subprocess
from tempfile import NamedTemporaryFile


def main():
    scripts = dirname(__file__)
    parser = ArgumentParser()
    parser.add_argument('host', help='SSH user@hostname spec.')
    parser.add_argument('release', help='The distro version number.')
    parser.add_argument('series', help='The distro codename.')
    parser.add_argument('arch', help='The machine architecture.')
    parser.add_argument('source_package_build',
                        help='The build-source-package build to use.')
    args = parser.parse_args()
    os.environ['PATH'] = '{}:{}'.format(scripts, os.environ['PATH'])
    revision_build = os.environ['revision_build']
    job_name = os.environ['JOB_NAME']
    build_number = os.environ['BUILD_NUMBER']
    workspace = os.environ['WORKSPACE']
    s3_config = join(os.environ['JUJU_HOME'], 'juju-qa.s3cfg')

    subprocess.check_call(['jujuci.py', '-v', 'setup-workspace', workspace])

    release_glob = '*{}*'.format(args.release)

    subprocess.check_call([
        'jujuci.py', 'get', '-b', args.source_package_build,
        'build-source-packages', release_glob, workspace])
    packages = glob(release_glob)
    (dsc_file,) = [x for x in packages if x.endswith('.dsc')]
    subprocess.check_call(
        ['jujuci.py', 'get', '-b', args.source_package_build,
         'build-source-packages', '*orig.tar.gz', workspace])
    packages.extend(glob('*.orig.tar.gz'))
    command = [
        'mv', 'packages/*', '.', ';',
        '/home/ubuntu/juju-release-tools/build_package.py', '-v', 'binary',
        dsc_file, '$(pwd)', args.series, args.arch]
    prefix = 'juju-ci/products/version-{}/{}/build-{}'.format(
        revision_build, job_name, build_number)
    private_key = join(os.environ['JUJU_HOME'], 'staging-juju-rsa')
    with NamedTemporaryFile() as config_file:
        json.dump({
            'command': command,
            'install': {'packages': packages},
            'artifacts': {'packages': ['*.deb']},
            'bucket': 'juju-qa-data',
            }, config_file)
        config_file.flush()
        subprocess.check_call([
            'workspace-run', '-v', config_file.name, args.host, prefix,
            '--s3-config', s3_config, '-i', private_key,
            ])


if __name__ == '__main__':
    main()