From 4f9a33ddab2aca4539250d23e6132f7c3c13be8a Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Thu, 31 Oct 2013 10:33:04 -0700 Subject: [PATCH] Allow blocking uploads by way of bugs with the block-proposed tag set --- britney.py | 5 +++ britney2/policies/policy.py | 48 +++++++++++++++++++++++++ tests/test_autopkgtest.py | 22 ------------ tests/test_lpblockbug.py | 70 +++++++++++++++++++++++++++++++++++++ 4 files changed, 123 insertions(+), 22 deletions(-) create mode 100644 tests/test_lpblockbug.py diff --git a/britney.py b/britney.py index a71bb6b..210e0b7 100755 --- a/britney.py +++ b/britney.py @@ -62,6 +62,9 @@ Other than source and binary packages, Britney loads the following data: * Hints, which contains lists of commands which modify the standard behaviour of Britney (see Britney.read_hints). + * Blocks, which contains user-supplied blocks read from Launchpad bugs + (see LPBlockBugPolicy). + For a more detailed explanation about the format of these files, please read the documentation of the related methods. The exact meaning of them will be instead explained in the chapter "Excuses Generation". @@ -210,6 +213,7 @@ from britney2.policies.policy import (AgePolicy, BuiltUsingPolicy, BuiltOnBuilddPolicy, ImplicitDependencyPolicy, + LPBlockBugPolicy, ) from britney2.policies.autopkgtest import AutopkgtestPolicy from britney2.utils import (log_and_format_old_libraries, @@ -517,6 +521,7 @@ class Britney(object): self._policy_engine.add_policy(ImplicitDependencyPolicy(self.options, self.suite_info)) if getattr(self.options, 'check_buildd', 'no') == 'yes': self._policy_engine.add_policy(BuiltOnBuilddPolicy(self.options, self.suite_info)) + self._policy_engine.add_policy(LPBlockBugPolicy(self.options, self.suite_info)) @property def hints(self): diff --git a/britney2/policies/policy.py b/britney2/policies/policy.py index d2cb103..52614a2 100644 --- a/britney2/policies/policy.py +++ b/britney2/policies/policy.py @@ -1731,3 +1731,51 @@ class ImplicitDependencyPolicy(BasePolicy): sorted(broken_old | broken_binaries) return verdict + + +class LPBlockBugPolicy(BasePolicy): + """block-proposed Launchpad bug policy for source migrations + + This policy will read an user-supplied "Blocks" file from the unstable + directory (provided by an external script) with rows of the following + format: + + + + The dates are expressed as the number of seconds from the Unix epoch + (1970-01-01 00:00:00 UTC). + """ + def __init__(self, options, suite_info): + super().__init__('block-bugs', options, suite_info, {SuiteClass.PRIMARY_SOURCE_SUITE}) + + def initialise(self, britney): + super().initialise(britney) + self.blocks = {} # srcpkg -> [(bug, date), ...] + + filename = os.path.join(self.options.unstable, "Blocks") + self.log("Loading user-supplied block data from %s" % filename) + for line in open(filename): + ln = line.split() + if len(ln) != 3: + self.logger.warning("Blocks, ignoring malformed line %s", line) + continue + try: + self.blocks.setdefault(ln[0], []) + self.blocks[ln[0]].append((ln[1], int(ln[2]))) + except ValueError: + self.log("Blocks, unable to parse \"%s\"" % line, type='E') + + def apply_src_policy_impl(self, block_bugs_info, item, source_data_tdist, source_data_srcdist, excuse): + source_name = item.package + try: + blocks = self.blocks[source_name] + except KeyError: + return PolicyVerdict.PASS + + for bug, date in blocks: + block_bugs_info[bug] = date + excuse.addinfo("Not touching package as requested in bug %s on %s" % + (bug, bug, time.asctime(time.gmtime(date)))) + excuse.addreason('block') + + return PolicyVerdict.REJECTED_PERMANENTLY diff --git a/tests/test_autopkgtest.py b/tests/test_autopkgtest.py index 1ec1752..ee83506 100644 --- a/tests/test_autopkgtest.py +++ b/tests/test_autopkgtest.py @@ -1920,28 +1920,6 @@ class AT(TestAutopkgtestBase): {'lightgreen': [('reason', 'block')]} ) - ################################################################ - # Tests for non-hint policies (Ubuntu only) - ################################################################ - -# # def test_lp_bug_block(self): -# # self.data.add_default_packages(darkgreen=False) -# # -# # with open(os.path.join(self.data.path, 'data/unstable/Blocks'), 'w') as f: -# # f.write('darkgreen 12345 1471505000\ndarkgreen 98765 1471500000\n') -# # -# # exc = self.run_it( -# # [('darkgreen', {'Version': '2'}, 'autopkgtest')], -# # {'darkgreen': (False, {'darkgreen': {'i386': 'RUNNING-ALWAYSFAIL', 'amd64': 'RUNNING-ALWAYSFAIL'}})}, -# # {'darkgreen': [('reason', 'block'), -# # ('excuses', 'Not touching package as requested in bug 12345 on Thu Aug 18 07:23:20 2016'), -# # ('is-candidate', False), -# # ] -# # } -# # )[1] -# # self.assertEqual(exc['darkgreen']['policy_info']['block-bugs'], -# # {'12345': 1471505000, '98765': 1471500000}) - ################################################################ # Kernel related tests ################################################################ diff --git a/tests/test_lpblockbug.py b/tests/test_lpblockbug.py new file mode 100644 index 0000000..b489ded --- /dev/null +++ b/tests/test_lpblockbug.py @@ -0,0 +1,70 @@ +#!/usr/bin/python3 +# (C) 2020 Canonical Ltd. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. + +from collections import defaultdict + +import calendar +import fileinput +import json +import os +import pprint +import sys +import time +import unittest +import yaml +from unittest.mock import DEFAULT, patch, call + +PROJECT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +sys.path.insert(0, PROJECT_DIR) + +from britney2.policies.policy import PolicyVerdict +# We want to reuse run_it +from tests.test_autopkgtest import TestAutopkgtestBase + + +class T(TestAutopkgtestBase): + def test_lp_bug_block(self): + self.data.add_default_packages(darkgreen=False) + + with open( + os.path.join(self.data.path, "data/unstable/Blocks"), "w" + ) as f: + f.write("darkgreen 12345 1471505000\ndarkgreen 98765 1471500000\n") + + exc = self.run_it( + [("darkgreen", {"Version": "2"}, "autopkgtest")], + { + "darkgreen": ( + False, + { + "darkgreen": { + "i386": "RUNNING-ALWAYSFAIL", + "amd64": "RUNNING-ALWAYSFAIL", + } + }, + ) + }, + { + "darkgreen": [ + ("reason", "block"), + ( + "excuses", + 'Not touching package as requested in bug 12345 on Thu Aug 18 07:23:20 2016', + ), + ("is-candidate", False), + ] + }, + )[1] + self.assertEqual( + exc["darkgreen"]["policy_info"]["block-bugs"], + { + "12345": 1471505000, + "98765": 1471500000, + "verdict": "REJECTED_PERMANENTLY", + }, + )