~andrewjbeach/juju-ci-tools/make-local-patcher

« back to all changes in this revision

Viewing changes to build_vagrant_boxes.py

  • Committer: John George
  • Date: 2015-01-14 22:03:47 UTC
  • mto: This revision was merged to the branch mainline in revision 798.
  • Revision ID: john.george@canonical.com-20150114220347-e8q5wezs1qg9a00u
Added support for setting the juju path, series and agent_url.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/env python
2
2
from argparse import ArgumentParser
 
3
from jenkins import Jenkins
3
4
import logging
4
5
import os
 
6
import re
5
7
import shutil
6
8
import subprocess
7
9
import sys
8
10
 
9
 
from jujuci import (
10
 
    add_credential_args,
11
 
    get_artifacts,
12
 
    get_credentials,
13
 
    PUBLISH_REVISION
14
 
)
 
11
 
 
12
from utility import builds_for_revision
15
13
 
16
14
"""Build Juju-Vagrant boxes for Juju packages build by publish-revision.
17
15
 
22
20
        lp:~ubuntu-on-ec2/vmbuilder/jenkins_kvm (main build scripts)
23
21
"""
24
22
 
 
23
JENKINS_URL = 'http://juju-ci.vapour.ws:8080'
 
24
PUBLISH_REVISION_JOB = 'publish-revision'
25
25
SERIES_TO_NUMBERS = {
26
26
    'trusty': '14.04',
27
27
    'precise': '12.04',
30
30
WORKSPACE = 'WORKSPACE'
31
31
 
32
32
 
33
 
def get_package_globs(series, arch):
34
 
    series_number = SERIES_TO_NUMBERS[series]
 
33
def package_regexes(series, arch):
 
34
    series_number = SERIES_TO_NUMBERS[series].replace('.', r'\.')
 
35
    regex_core = re.compile(
 
36
        r'^juju-core_.*%s.*%s\.deb$' % (series_number, arch))
 
37
    regex_local = re.compile(
 
38
        r'^juju-local_.*%s.*all\.deb$' % series_number)
35
39
    return {
36
 
        'core': 'juju-core_*%s*_%s.deb' % (series_number, arch),
37
 
        'local': 'juju-local_*%s*_all.deb' % series_number,
 
40
        'core': regex_core,
 
41
        'local': regex_local,
38
42
    }
39
43
 
40
44
 
41
 
def get_debian_packages(credentials, workspace, series, arch, revision_build):
 
45
def get_debian_packages(jenkins, workspace, series, arch, revision_build):
 
46
    builds = builds_for_revision(PUBLISH_REVISION_JOB, revision_build, jenkins)
 
47
    if len(builds) == 0:
 
48
        logging.error('No builds found for revision_build %s' % revision_build)
 
49
        sys.exit(1)
 
50
 
 
51
    build_info = builds[0]
42
52
    result = {}
43
 
    package_globs = get_package_globs(series, arch)
 
53
    regexes = package_regexes(series, arch)
44
54
    try:
45
 
        for package, glob in package_globs.items():
46
 
            artifacts = get_artifacts(
47
 
                credentials, PUBLISH_REVISION, revision_build, glob,
48
 
                workspace, dry_run=False, verbose=False)
49
 
            file_path = os.path.join(workspace, artifacts[0].file_name)
50
 
            result[package] = file_path
 
55
        for artifact in build_info['artifacts']:
 
56
            filename = artifact['fileName']
 
57
            for package, matcher in regexes.items():
 
58
                if matcher.search(filename) is not None:
 
59
                    package_url = '%s/artifact/%s' % (
 
60
                        build_info['url'], filename)
 
61
                    local_path = os.path.join(workspace, filename)
 
62
                    logging.info(
 
63
                        'copying %s from build %s' % (
 
64
                            filename, build_info['number']))
 
65
                    result[package] = local_path
 
66
                    command = 'wget -q -O %s %s' % (
 
67
                        local_path, package_url)
 
68
                    subprocess.check_call(command.split(' '))
 
69
                    break
51
70
    except Exception:
52
71
        for file_path in result.values():
53
72
            if os.path.exists(file_path):
132
151
            'this option is a revision_build number. The debian packages '
133
152
            'are retrieved from a run of the publish-revision for this '
134
153
            'revision_build.'))
135
 
    add_credential_args(parser)
136
154
    args = parser.parse_args()
137
155
    clean_workspace(args.workspace)
 
156
    jenkins = Jenkins(JENKINS_URL)
138
157
    if args.use_ci_juju_packages is not None:
139
 
        credentials = get_credentials(args)
140
158
        package_info = get_debian_packages(
141
 
            credentials, args.workspace, args.series, args.arch,
 
159
            jenkins, args.workspace, args.series, args.arch,
142
160
            args.use_ci_juju_packages)
143
161
        if 'core' not in package_info:
144
162
            logging.error('Could not find juju-core package')