Allow blocking uploads by way of bugs with the block-proposed tag set

ubuntu/dry-run
Colin Watson 11 years ago committed by Iain Lane
parent 1487096a15
commit 4f9a33ddab

@ -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):

@ -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:
<source-name> <bug> <date>
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 <a href=\"https://launchpad.net/bugs/%s\">bug %s</a> on %s" %
(bug, bug, time.asctime(time.gmtime(date))))
excuse.addreason('block')
return PolicyVerdict.REJECTED_PERMANENTLY

@ -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 <a href="https://launchpad.net/bugs/12345">bug 12345</a> 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
################################################################

@ -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 <a href="https://launchpad.net/bugs/12345">bug 12345</a> 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",
},
)
Loading…
Cancel
Save