283
by Andy Whitcroft
run-autopkgtest: reinstate |
1 |
#!/usr/bin/python3
|
2 |
# Request re-runs of autopkgtests for packages
|
|
3 |
||
4 |
from datetime import datetime |
|
5 |
import os |
|
6 |
import sys |
|
7 |
import argparse |
|
8 |
import json |
|
9 |
import urllib.parse |
|
10 |
||
11 |
import amqplib.client_0_8 as amqp |
|
12 |
||
284
by Andy Whitcroft
run-autopkgtest: adjust configuration path for its new home |
13 |
#my_dir = os.path.dirname(os.path.realpath(sys.argv[0]))
|
14 |
my_dir = os.path.expanduser('~ubuntu-archive/proposed-migration/code/b2') |
|
283
by Andy Whitcroft
run-autopkgtest: reinstate |
15 |
|
16 |
||
17 |
def parse_args(): |
|
18 |
'''Parse command line arguments'''
|
|
19 |
||
20 |
parser = argparse.ArgumentParser() |
|
21 |
parser.add_argument('-c', '--config', |
|
22 |
help='britney config file (default: britney.conf.ubuntu.<series>)') |
|
23 |
parser.add_argument('-s', '--series', required=True, |
|
24 |
help='Distro series name (required).') |
|
25 |
parser.add_argument('-a', '--architecture', action='append', default=[], |
|
26 |
help='Only run test(s) on given architecture name(s). ' |
|
27 |
'Can be specified multiple times (default: all).') |
|
28 |
parser.add_argument('--trigger', action='append', default=[], |
|
29 |
metavar='SOURCE/VERSION', |
|
30 |
help='Add triggering package to request. ' |
|
31 |
'Can be specified multiple times.') |
|
32 |
parser.add_argument('--ppa', metavar='LPUSER/PPANAME', action='append', |
|
33 |
default=[], |
|
34 |
help='Enable PPA for requested test(s). ' |
|
35 |
'Can be specified multiple times.') |
|
36 |
parser.add_argument('--env', metavar='KEY=VALUE', action='append', |
|
37 |
default=[], |
|
38 |
help='List of VAR=value strings. ' |
|
39 |
'This can be used to influence a test\'s behaviour ' |
|
40 |
'from a test request. '
|
|
41 |
'Can be specified multiple times.') |
|
42 |
parser.add_argument('--test-git', |
|
43 |
metavar='URL [branchname]', |
|
44 |
help='A single URL or URL branchname. ' |
|
45 |
'The test will be git cloned from that URL and ran '
|
|
46 |
'from the checkout. This will not build binary '
|
|
47 |
'packages from the branch and run tests against '
|
|
48 |
'those, the test dependencies will be taken from the '
|
|
49 |
'archive, or PPA if given. In this case the '
|
|
50 |
'srcpkgname will only be used for the result path in '
|
|
51 |
'swift and be irrelevant for the actual test.') |
|
52 |
parser.add_argument('--build-git', |
|
53 |
metavar='URL [branchname]', |
|
54 |
help='A single URL or URL branchname. ' |
|
55 |
'Like --test-git`, but will first build binary '
|
|
56 |
'packages from the branch and run tests against those.') |
|
57 |
parser.add_argument('--test-bzr', |
|
58 |
help='A single URL. ' |
|
59 |
'The test will be checked out with bzr from that URL. '
|
|
60 |
'Otherwise this has the same behaviour as test-git.') |
|
61 |
parser.add_argument('--all-proposed', action='store_true', |
|
62 |
help='Disable apt pinning and use all of -proposed') |
|
63 |
parser.add_argument('--bulk', action='store_true', |
|
64 |
help='Mark this as a bulk (low priority) test where possible') |
|
65 |
parser.add_argument('package', nargs='+', |
|
66 |
help='Source package name(s) whose tests to run.') |
|
67 |
args = parser.parse_args() |
|
68 |
||
69 |
if not args.trigger and not args.ppa: |
|
70 |
parser.error('One of --trigger or --ppa must be given') |
|
71 |
||
72 |
# verify syntax of triggers
|
|
73 |
for t in args.trigger: |
|
74 |
try: |
|
75 |
(src, ver) = t.split('/') |
|
76 |
except ValueError: |
|
77 |
parser.error('Invalid trigger format "%s", must be "sourcepkg/version"' % t) |
|
78 |
||
79 |
# verify syntax of PPAs
|
|
80 |
for t in args.ppa: |
|
81 |
try: |
|
82 |
(user, name) = t.split('/') |
|
83 |
except ValueError: |
|
84 |
parser.error('Invalid ppa format "%s", must be "lpuser/ppaname"' % t) |
|
85 |
||
86 |
return args |
|
87 |
||
88 |
||
89 |
def parse_config(config_file): |
|
90 |
'''Parse config file (like britney.py)'''
|
|
91 |
||
92 |
config = argparse.Namespace() |
|
93 |
with open(config_file) as f: |
|
94 |
for k, v in [r.split('=', 1) for r in f if '=' in r and not r.strip().startswith('#')]: |
|
95 |
k = k.strip() |
|
96 |
if not getattr(config, k.lower(), None): |
|
97 |
setattr(config, k.lower(), v.strip()) |
|
98 |
return config |
|
99 |
||
100 |
||
101 |
if __name__ == '__main__': |
|
102 |
args = parse_args() |
|
103 |
britney_conf = os.path.join(my_dir, 'britney.conf') |
|
104 |
if args.config: |
|
105 |
config = parse_config(args.config) |
|
106 |
elif os.path.exists(britney_conf + '.ubuntu.' + args.series): |
|
107 |
config = parse_config(britney_conf + '.ubuntu.' + args.series) |
|
108 |
else: |
|
109 |
config = parse_config(britney_conf) |
|
110 |
if not args.architecture: |
|
111 |
args.architecture = config.adt_arches.split() |
|
112 |
||
113 |
context = '' |
|
114 |
params = {} |
|
115 |
if args.bulk: |
|
116 |
context = 'huge-' |
|
117 |
if args.trigger: |
|
118 |
params['triggers'] = args.trigger |
|
119 |
if args.ppa: |
|
120 |
params['ppas'] = args.ppa |
|
121 |
context = 'ppa-' |
|
122 |
if args.env: |
|
123 |
params['env'] = args.env |
|
124 |
if args.test_git: |
|
125 |
params['test-git'] = args.test_git |
|
126 |
context = 'upstream-' |
|
127 |
elif args.build_git: |
|
128 |
params['build-git'] = args.build_git |
|
129 |
context = 'upstream-' |
|
130 |
if args.test_bzr: |
|
131 |
params['test-bzr'] = args.test_bzr |
|
132 |
context = 'upstream-' |
|
133 |
if args.all_proposed: |
|
134 |
params['all-proposed'] = True |
|
135 |
try: |
|
136 |
params['requester'] = os.environ['SUDO_USER'] |
|
137 |
except KeyError: |
|
138 |
pass
|
|
139 |
params['submit-time'] = datetime.strftime(datetime.utcnow(), '%Y-%m-%d %H:%M:%S%z') |
|
140 |
params = '\n' + json.dumps(params) |
|
141 |
||
142 |
creds = urllib.parse.urlsplit(config.adt_amqp, allow_fragments=False) |
|
143 |
assert creds.scheme == 'amqp' |
|
144 |
||
145 |
with amqp.Connection(creds.hostname, userid=creds.username, |
|
146 |
password=creds.password) as amqp_con: |
|
147 |
with amqp_con.channel() as ch: |
|
148 |
for arch in args.architecture: |
|
149 |
queue = 'debci-%s%s-%s' % (context, args.series, arch) |
|
150 |
for pkg in args.package: |
|
151 |
ch.basic_publish(amqp.Message(pkg + params, |
|
152 |
delivery_mode=2), # persistent |
|
153 |
routing_key=queue) |