From d592ee61ae02d303f96711a4476fe16504796a21 Mon Sep 17 00:00:00 2001 From: Iain Lane Date: Thu, 16 Jan 2020 10:12:19 +0000 Subject: [PATCH 1/2] LPExcuseBugsPolicy: handle the ExcuseBugs file not existing When we're not run via b1 - for example when running the testsuite - this file will not have been created. Treat that as if there are no bugs to note. --- britney2/policies/policy.py | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/britney2/policies/policy.py b/britney2/policies/policy.py index a81db75..9cddd33 100644 --- a/britney2/policies/policy.py +++ b/britney2/policies/policy.py @@ -2,6 +2,7 @@ import json import os import time from abc import abstractmethod +from collections import defaultdict from urllib.parse import quote import apt_pkg @@ -699,6 +700,7 @@ class LPBlockBugPolicy(BasePolicy): return PolicyVerdict.REJECTED_PERMANENTLY + class LPExcuseBugsPolicy(BasePolicy): """update-excuse Launchpad bug policy to link to a bug report, does not prevent migration @@ -716,26 +718,25 @@ class LPExcuseBugsPolicy(BasePolicy): def initialise(self, britney): super().initialise(britney) - self.excuse_bugs = {} # srcpkg -> [(bug, date), ...] + self.excuse_bugs = defaultdict(list) # srcpkg -> [(bug, date), ...] filename = os.path.join(self.options.unstable, "ExcuseBugs") self.log("Loading user-supplied excuse bug data from %s" % filename) - for line in open(filename): - l = line.split() - if len(l) != 3: - self.log("ExcuseBugs, ignoring malformed line %s" % line, type='W') - continue - try: - self.excuse_bugs.setdefault(l[0], []) - self.excuse_bugs[l[0]].append((l[1], int(l[2]))) - except ValueError: - self.log("ExcuseBugs, unable to parse \"%s\"" % line, type='E') + try: + for line in open(filename): + l = line.split() + if len(l) != 3: + self.log("ExcuseBugs, ignoring malformed line %s" % line, type='W') + continue + try: + self.excuse_bugs[l[0]].append((l[1], int(l[2]))) + except ValueError: + self.log("ExcuseBugs, unable to parse \"%s\"" % line, type='E') + except FileNotFoundError: + self.log("ExcuseBugs, data file not found, no bugs will be recorded" % filename) def apply_policy_impl(self, excuse_bugs_info, suite, source_name, source_data_tdist, source_data_srcdist, excuse): - try: - excuse_bug = self.excuse_bugs[source_name] - except KeyError: - return PolicyVerdict.PASS + excuse_bug = self.excuse_bugs[source_name] for bug, date in excuse_bug: excuse_bugs_info[bug] = date From 177c7a69f7f920b1178b8c2f5b26259fa9df0b8b Mon Sep 17 00:00:00 2001 From: Iain Lane Date: Thu, 16 Jan 2020 10:13:41 +0000 Subject: [PATCH 2/2] test_autopkgtest: Strip submit-time Testsuite regression from 4c27eadffa01bc1c084e947a7fa1e8a7509d1653. submit-time is the time the request was submitted to amqp. For tests it's the time the testcase was run. Many of our testcases test the exact parameters that were passed to amqp, so they now fail because submit-time is in there but it's not being checked for. It would be possible to either verify the submit-time too, or switch to fuzzy matching - but it's actually not very valuable to test submit-time, since it is only for human readers of autopkgtest-cloud log files or autopkgtest.ubuntu.com/running. Instead strip the field from the amqp parameters before any tests see them. --- tests/test_autopkgtest.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/test_autopkgtest.py b/tests/test_autopkgtest.py index 3fbba9d..3152270 100755 --- a/tests/test_autopkgtest.py +++ b/tests/test_autopkgtest.py @@ -171,7 +171,14 @@ class T(TestBase): try: with open(self.fake_amqp) as f: for line in f: - self.amqp_requests.add(line.strip()) + # debci-series-amd64:darkgreen {"triggers": ["darkgreen/2"], "submit-time": "2020-01-16 09:47:12"} + # strip the submit time from the requests we're testing; it + # is only for info for people reading the queue + (queuepkg, data) = line.split(' ', 1) + data_json = json.loads(data) + del data_json["submit-time"] + self.amqp_requests.add("{} {}".format(queuepkg, + json.dumps(data_json))) os.unlink(self.fake_amqp) except IOError: pass