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

« back to all changes in this revision

Viewing changes to schedule_hetero_control.py

  • Committer: Aaron Bentley
  • Date: 2014-02-24 17:18:29 UTC
  • mto: This revision was merged to the branch mainline in revision 252.
  • Revision ID: aaron.bentley@canonical.com-20140224171829-sz644yhoygu7m9dm
Use tags to identify and shut down instances.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python
2
 
from __future__ import print_function
3
 
 
4
 
from argparse import ArgumentParser
5
 
import json
6
 
import os
7
 
import re
8
 
 
9
 
from jenkins import Jenkins
10
 
from jujuci import (
11
 
    add_credential_args,
12
 
    get_credentials,
13
 
    )
14
 
from utility import (
15
 
    find_candidates,
16
 
    get_auth_token,
17
 
    get_candidates_path,
18
 
    )
19
 
 
20
 
 
21
 
def get_args(argv=None):
22
 
    parser = ArgumentParser()
23
 
    parser.add_argument(
24
 
        'root_dir', help='Directory containing releases and candidates dir')
25
 
    parser.add_argument(
26
 
        '--all', action='store_true', default=False,
27
 
        help='Schedule all candidates for client-server testing.')
28
 
    add_credential_args(parser)
29
 
    args = parser.parse_args(argv)
30
 
    return args, get_credentials(args)
31
 
 
32
 
 
33
 
def get_releases(root):
34
 
    release_path = os.path.join(root, 'old-juju')
35
 
    released_pattern = re.compile('^\d+\.\d+\.\d+[^~]*$')
36
 
    for entry in os.listdir(release_path):
37
 
        if not os.path.isdir(os.path.join(release_path, entry)):
38
 
            continue
39
 
        if released_pattern.match(entry):
40
 
            yield entry
41
 
 
42
 
 
43
 
def get_candidate_info(candidate_path):
44
 
    """ Return candidate version and revision build number. """
45
 
    with open(os.path.join(candidate_path, 'buildvars.json')) as fp:
46
 
        build_vars = json.load(fp)
47
 
    return build_vars['version'], build_vars['revision_build']
48
 
 
49
 
 
50
 
def calculate_jobs(root, schedule_all=False):
51
 
    releases = list(get_releases(root))
52
 
    candidates_path = get_candidates_path(root)
53
 
    for candidate_path in find_candidates(root, schedule_all):
54
 
        parent, candidate = os.path.split(candidate_path)
55
 
        if candidate.startswith('1.26'):
56
 
            # 1.26 was renamed to 2.0 because it is not compatible with 1.x
57
 
            continue
58
 
        if parent != candidates_path:
59
 
            raise ValueError('Wrong path')
60
 
        candidate_version, revision_build = get_candidate_info(candidate_path)
61
 
        for release in releases:
62
 
            # Releases with the same major number must be compatible.
63
 
            if release[:2] != candidate[:2]:
64
 
                continue
65
 
            for client_os in ('ubuntu', 'osx', 'windows'):
66
 
                yield {
67
 
                    'old_version': release,  # Client
68
 
                    'candidate': candidate_version,  # Server
69
 
                    'new_to_old': 'true',
70
 
                    'candidate_path': candidate,
71
 
                    'client_os': client_os,
72
 
                    'revision_build': revision_build,
73
 
                }
74
 
                yield {
75
 
                    'old_version': release,  # Server
76
 
                    'candidate': candidate_version,  # Client
77
 
                    'new_to_old': 'false',
78
 
                    'candidate_path': candidate,
79
 
                    'client_os': client_os,
80
 
                    'revision_build': revision_build,
81
 
                }
82
 
 
83
 
 
84
 
def build_jobs(credentials, root, jobs):
85
 
    jenkins = Jenkins('http://localhost:8080', *credentials)
86
 
    token = get_auth_token(root, 'compatibility-control')
87
 
    os_str = {"ubuntu": "", "osx": "-osx", "windows": "-windows"}
88
 
    for job in jobs:
89
 
        jenkins.build_job(
90
 
            'compatibility-control{}'.format(os_str[job['client_os']]), job,
91
 
            token=token)
92
 
 
93
 
 
94
 
def main():
95
 
    args, credentials = get_args()
96
 
    build_jobs(
97
 
        credentials, args.root_dir, calculate_jobs(args.root_dir, args.all))
98
 
 
99
 
 
100
 
if __name__ == '__main__':
101
 
    main()