2
# Request re-runs of autopkgtests for packages
4
from datetime import datetime
11
import amqplib.client_0_8 as amqp
13
#my_dir = os.path.dirname(os.path.realpath(sys.argv[0]))
14
my_dir = os.path.expanduser('~ubuntu-archive/proposed-migration/code/b2')
18
'''Parse command line arguments'''
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',
34
help='Enable PPA for requested test(s). '
35
'Can be specified multiple times.')
36
parser.add_argument('--env', metavar='KEY=VALUE', action='append',
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',
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()
69
if not args.trigger and not args.ppa:
70
parser.error('One of --trigger or --ppa must be given')
72
# verify syntax of triggers
73
for t in args.trigger:
75
(src, ver) = t.split('/')
77
parser.error('Invalid trigger format "%s", must be "sourcepkg/version"' % t)
79
# verify syntax of PPAs
82
(user, name) = t.split('/')
84
parser.error('Invalid ppa format "%s", must be "lpuser/ppaname"' % t)
89
def parse_config(config_file):
90
'''Parse config file (like britney.py)'''
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('#')]:
96
if not getattr(config, k.lower(), None):
97
setattr(config, k.lower(), v.strip())
101
if __name__ == '__main__':
103
britney_conf = os.path.join(my_dir, 'britney.conf')
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)
109
config = parse_config(britney_conf)
110
if not args.architecture:
111
args.architecture = config.adt_arches.split()
118
params['triggers'] = args.trigger
120
params['ppas'] = args.ppa
123
params['env'] = args.env
125
params['test-git'] = args.test_git
126
context = 'upstream-'
128
params['build-git'] = args.build_git
129
context = 'upstream-'
131
params['test-bzr'] = args.test_bzr
132
context = 'upstream-'
133
if args.all_proposed:
134
params['all-proposed'] = True
136
params['requester'] = os.environ['SUDO_USER']
139
params['submit-time'] = datetime.strftime(datetime.utcnow(), '%Y-%m-%d %H:%M:%S%z')
140
params = '\n' + json.dumps(params)
142
creds = urllib.parse.urlsplit(config.adt_amqp, allow_fragments=False)
143
assert creds.scheme == 'amqp'
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