mirror of
				https://git.launchpad.net/~ubuntu-release/britney/+git/britney2-ubuntu
				synced 2025-11-04 10:34:05 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			120 lines
		
	
	
		
			4.6 KiB
		
	
	
	
		
			Python
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			120 lines
		
	
	
		
			4.6 KiB
		
	
	
	
		
			Python
		
	
	
		
			Executable File
		
	
	
	
	
#!/usr/bin/python3
 | 
						|
# Request re-runs of autopkgtests for packages
 | 
						|
 | 
						|
import os
 | 
						|
import sys
 | 
						|
import argparse
 | 
						|
import json
 | 
						|
import urllib.parse
 | 
						|
 | 
						|
import amqplib.client_0_8 as amqp
 | 
						|
 | 
						|
my_dir = os.path.dirname(os.path.realpath(sys.argv[0]))
 | 
						|
 | 
						|
 | 
						|
def parse_args():
 | 
						|
    '''Parse command line arguments'''
 | 
						|
 | 
						|
    parser = argparse.ArgumentParser()
 | 
						|
    parser.add_argument('-c', '--config',
 | 
						|
                        default=os.path.join(my_dir, 'britney.conf'),
 | 
						|
                        help='britney config file (default: %(default)s)')
 | 
						|
    parser.add_argument('-s', '--series', required=True,
 | 
						|
                        help='Distro series name (required).')
 | 
						|
    parser.add_argument('-a', '--architecture', action='append', default=[],
 | 
						|
                        help='Only run test(s) on given architecture name(s). '
 | 
						|
                        'Can be specified multiple times (default: all).')
 | 
						|
    parser.add_argument('--trigger', action='append', default=[],
 | 
						|
                        metavar='SOURCE/VERSION',
 | 
						|
                        help='Add triggering package to request. '
 | 
						|
                        'Can be specified multiple times.')
 | 
						|
    parser.add_argument('--ppa', metavar='LPUSER/PPANAME', action='append',
 | 
						|
                        default=[],
 | 
						|
                        help='Enable PPA for requested test(s). '
 | 
						|
                        'Can be specified multiple times.')
 | 
						|
    parser.add_argument('--env', metavar='KEY=VALUE', action='append',
 | 
						|
                        default=[],
 | 
						|
                        help='List of VAR=value strings. '
 | 
						|
                        'This can be used to influence a test\'s behaviour '
 | 
						|
                        'from a test request. '
 | 
						|
                        'Can be specified multiple times.')
 | 
						|
    parser.add_argument('--test-git',
 | 
						|
                        help='A single URL or URL branchname. '
 | 
						|
                        'The test will be git cloned from that URL and ran '
 | 
						|
                        'from the checkout. This will not build binary '
 | 
						|
                        'packages from the branch and run tests against '
 | 
						|
                        'those, the test dependencies will be taken from the '
 | 
						|
                        'archive, or PPA if given. In this case the '
 | 
						|
                        'srcpkgname will only be used for the result path in '
 | 
						|
                        'swift and be irrelevant for the actual test.')
 | 
						|
    parser.add_argument('--test-bzr',
 | 
						|
                        help='A single URL. '
 | 
						|
                        'The test will be checked out with bzr from that URL. '
 | 
						|
                        'Otherwise this has the same behaviour as test-git.')
 | 
						|
    parser.add_argument('package', nargs='+',
 | 
						|
                        help='Source package name(s) whose tests to run.')
 | 
						|
    args = parser.parse_args()
 | 
						|
 | 
						|
    if not args.trigger and not args.ppa:
 | 
						|
        parser.error('One of --trigger or --ppa must be given')
 | 
						|
 | 
						|
    # verify syntax of triggers
 | 
						|
    for t in args.trigger:
 | 
						|
        try:
 | 
						|
            (src, ver) = t.split('/')
 | 
						|
        except ValueError:
 | 
						|
            parser.error('Invalid trigger format "%s", must be "sourcepkg/version"' % t)
 | 
						|
 | 
						|
    # verify syntax of PPAs
 | 
						|
    for t in args.ppa:
 | 
						|
        try:
 | 
						|
            (user, name) = t.split('/')
 | 
						|
        except ValueError:
 | 
						|
            parser.error('Invalid ppa format "%s", must be "lpuser/ppaname"' % t)
 | 
						|
 | 
						|
    return args
 | 
						|
 | 
						|
 | 
						|
def parse_config(config_file):
 | 
						|
    '''Parse config file (like britney.py)'''
 | 
						|
 | 
						|
    config = argparse.Namespace()
 | 
						|
    with open(config_file) as f:
 | 
						|
        for k, v in [r.split('=', 1) for r in f if '=' in r and not r.strip().startswith('#')]:
 | 
						|
            k = k.strip()
 | 
						|
            if not getattr(config, k.lower(), None):
 | 
						|
                setattr(config, k.lower(), v.strip())
 | 
						|
    return config
 | 
						|
 | 
						|
 | 
						|
if __name__ == '__main__':
 | 
						|
    args = parse_args()
 | 
						|
    config = parse_config(args.config)
 | 
						|
    if not args.architecture:
 | 
						|
        args.architecture = config.adt_arches.split()
 | 
						|
 | 
						|
    params = {}
 | 
						|
    if args.trigger:
 | 
						|
        params['triggers'] = args.trigger
 | 
						|
    if args.ppa:
 | 
						|
        params['ppas'] = args.ppa
 | 
						|
    if args.env:
 | 
						|
        params['env'] = args.env
 | 
						|
    if args.test_git:
 | 
						|
        params['test-git'] = args.test_git
 | 
						|
    if args.test_bzr:
 | 
						|
        params['test-bzr'] = args.test_bzr
 | 
						|
    params = '\n' + json.dumps(params)
 | 
						|
 | 
						|
    creds = urllib.parse.urlsplit(config.adt_amqp, allow_fragments=False)
 | 
						|
    assert creds.scheme == 'amqp'
 | 
						|
 | 
						|
    with amqp.Connection(creds.hostname, userid=creds.username,
 | 
						|
                         password=creds.password) as amqp_con:
 | 
						|
        with amqp_con.channel() as ch:
 | 
						|
            for arch in args.architecture:
 | 
						|
                queue = 'debci-%s-%s' % (args.series, arch)
 | 
						|
                for pkg in args.package:
 | 
						|
                    ch.basic_publish(amqp.Message(pkg + params),
 | 
						|
                                     routing_key=queue)
 |