2 # -*- coding: utf-8 -*-
4 # This task takes patch series messages off one of the ‘patchq_test_*’
5 # queues and tests the patch series.
7 # If you run it without arguments, it will pick up patches from each
8 # test queue in turn and test them (but not in parallel). You can
9 # also list one or more tests on the command line, in which case only
10 # that test or tests are considered.
12 # This script does not perform tests in parallel, but doesn't care if
13 # other instances of the script are running (even across machines).
14 # Because of the message broker each patch series is only tested once.
28 connection = pika.BlockingConnection(pika.ConnectionParameters(
29 host = config.mq_server))
30 channel = connection.channel()
33 channel.basic_ack(delivery_tag = method.delivery_tag)
36 if len(sys.argv) <= 1:
40 for arg in sys.argv[1:]:
41 if arg not in config.tests:
42 sys.exit("%s is not listed in config.tests" % arg)
48 qname = "patchq_test_%s" % t
50 method, _, body = channel.basic_get(queue = qname, no_ack = False)
53 # Parse the ordered list of messages forming the patch series.
54 msgs = json.loads(body)
55 msgs = [email.message_from_string(m) for m in msgs]
57 # This should never happen, but the rest of the code
58 # below assumes number of msgs > 0, so ...
63 print ("%s: Running test:" % t)
65 # Save them to a temporary directory.
66 dir = tempfile.mkdtemp()
69 # Save the patches to files.
72 args.append("%s/%s.sh" % (pwd, t))
76 filename = ("%05d" % i)
78 print ("%05d %s" % (i, m['Subject']))
79 with open(filename, "w") as file:
80 file.write(m.as_string())
84 with open("output", "w") as out:
85 r = subprocess.call(args, stdout=out, stderr=out)
88 print ("%s: Test skipped" % t)
90 # Do a "group reply" to the last email.
91 tos = last_msg.get_all('to', [])
92 ccs = last_msg.get_all('cc', [])
93 from_ = last_msg['From']
94 to = email.utils.getaddresses(tos + ccs + [from_])
95 ref = last_msg['Message-Id']
100 subject = "%s %s (was: Re: %s)" % (t, status, last_msg['Subject'])
101 with open("output", "r") as file:
102 content = file.read()
104 body = json.dumps((to, subject, ref, content))
105 channel.basic_publish(exchange = 'patchq_reports',
109 # Ack the input message since we have processed it.
112 shutil.rmtree(dir, ignore_errors = True)