From f2f20eb4609c39d122942aa933d414976f034b7f Mon Sep 17 00:00:00 2001 From: Paul Gevers Date: Wed, 18 Oct 2017 21:43:32 +0200 Subject: [PATCH] Limit accumulated bounties to configurable minum age --- britney.conf | 1 + britney2/policies/policy.py | 16 ++++++++++++++++ tests/__init__.py | 1 + tests/test_autopkgtest.py | 5 +++-- 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/britney.conf b/britney.conf index 1cb65a6..bfc295c 100644 --- a/britney.conf +++ b/britney.conf @@ -52,6 +52,7 @@ MINDAYS_CRITICAL = 0 MINDAYS_EMERGENCY = 0 DEFAULT_URGENCY = medium NO_PENALTIES = high critical emergency +BOUNTY_MIN_AGE = 2 HINTSDIR = /srv/release.debian.org/britney/hints diff --git a/britney2/policies/policy.py b/britney2/policies/policy.py index 946958b..e1f8807 100644 --- a/britney2/policies/policy.py +++ b/britney2/policies/policy.py @@ -291,6 +291,22 @@ class AgePolicy(BasePolicy): self.log('Applying penalty for %s given by %s: %d days' % (source_name, penalty, excuse.penalty[penalty])) min_days += excuse.penalty[penalty] + try: + bounty_min_age = int(self.options.bounty_min_age) + except ValueError: + if self.options.bounty_min_age in self._min_days: + bounty_min_age = self._min_days[self.options.bounty_min_age] + else: + raise ValueError('Please fix BOUNTY_MIN_AGE in the britney configuration') + except AttributeError: + # The option wasn't defined in the configuration + bounty_min_age = 0 + # the age in BOUNTY_MIN_AGE can be higher than the one associated with + # the real urgency, so don't forget to take it into account + bounty_min_age = min(bounty_min_age, self._min_days[urgency]) + if min_days < bounty_min_age: + min_days = bounty_min_age + excuse.addhtml('Required age is not allowed to drop below %d days' % min_days) age_info['age-requirement'] = min_days age_info['current-age'] = days_old diff --git a/tests/__init__.py b/tests/__init__.py index 4f0b3fb..3f10c10 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -368,6 +368,7 @@ MINDAYS_CRITICAL = 0 MINDAYS_EMERGENCY = 0 DEFAULT_URGENCY = medium NO_PENALTIES = high critical emergency +BOUNTY_MIN_AGE = 8 HINTSDIR = data/hints diff --git a/tests/test_autopkgtest.py b/tests/test_autopkgtest.py index 6be4003..ab12231 100755 --- a/tests/test_autopkgtest.py +++ b/tests/test_autopkgtest.py @@ -2566,7 +2566,7 @@ class T(TestBase): self.assertEqual(exc['green']['policy_info']['age']['age-requirement'], 13) def test_passing_package_receives_bounty(self): - '''Does not request a test for an uninstallable package''' + '''Test bounty system (instead of policy verdict)''' # Don't use policy verdics, but age packages appropriate for line in fileinput.input(self.britney_conf, inplace=True): @@ -2596,7 +2596,8 @@ class T(TestBase): {})[1] # it should cause the age to drop - self.assertEqual(exc['green']['policy_info']['age']['age-requirement'], 7) + self.assertEqual(exc['green']['policy_info']['age']['age-requirement'], 8) + self.assertEqual(exc['green']['excuses'][-1], 'Required age is not allowed to drop below 8 days') if __name__ == '__main__':