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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
#!/usr/bin/env python
from __future__ import print_function
from argparse import ArgumentParser
import json
import os
import re
from jenkins import Jenkins
from jujuci import (
add_credential_args,
get_credentials,
)
from utility import (
find_candidates,
get_auth_token,
get_candidates_path,
)
def get_args(argv=None):
parser = ArgumentParser()
parser.add_argument(
'root_dir', help='Directory containing releases and candidates dir')
parser.add_argument(
'--all', action='store_true', default=False,
help='Schedule all candidates for client-server testing.')
add_credential_args(parser)
args = parser.parse_args(argv)
return args, get_credentials(args)
def get_releases(root):
release_path = os.path.join(root, 'old-juju')
released_pattern = re.compile('^\d+\.\d+\.\d+[^~]*$')
for entry in os.listdir(release_path):
if not os.path.isdir(os.path.join(release_path, entry)):
continue
if released_pattern.match(entry):
yield entry
def get_candidate_info(candidate_path):
""" Return candidate version and revision build number. """
with open(os.path.join(candidate_path, 'buildvars.json')) as fp:
build_vars = json.load(fp)
return build_vars['version'], build_vars['revision_build']
def calculate_jobs(root, schedule_all=False):
releases = list(get_releases(root))
candidates_path = get_candidates_path(root)
for candidate_path in find_candidates(root, schedule_all):
parent, candidate = os.path.split(candidate_path)
if candidate.startswith('1.26'):
# 1.26 was renamed to 2.0 because it is not compatible with 1.x
continue
if parent != candidates_path:
raise ValueError('Wrong path')
candidate_version, revision_build = get_candidate_info(candidate_path)
for release in releases:
# Releases with the same major number must be compatible.
if release[:2] != candidate[:2]:
continue
for client_os in ('ubuntu', 'osx', 'windows'):
yield {
'old_version': release, # Client
'candidate': candidate_version, # Server
'new_to_old': 'true',
'candidate_path': candidate,
'client_os': client_os,
'revision_build': revision_build,
}
yield {
'old_version': release, # Server
'candidate': candidate_version, # Client
'new_to_old': 'false',
'candidate_path': candidate,
'client_os': client_os,
'revision_build': revision_build,
}
def build_jobs(credentials, root, jobs):
jenkins = Jenkins('http://localhost:8080', *credentials)
token = get_auth_token(root, 'compatibility-control')
os_str = {"ubuntu": "", "osx": "-osx", "windows": "-windows"}
for job in jobs:
jenkins.build_job(
'compatibility-control{}'.format(os_str[job['client_os']]), job,
token=token)
def main():
args, credentials = get_args()
build_jobs(
credentials, args.root_dir, calculate_jobs(args.root_dir, args.all))
if __name__ == '__main__':
main()
|