Tweak recurring email frequency.

master
Robert Bruce Park 7 years ago committed by Steve Langasek
parent 41ac7a81f9
commit 9c76c762cc

@ -28,13 +28,13 @@ BOTS = {
MESSAGE = """From: Ubuntu Release Team <noreply@canonical.com> MESSAGE = """From: Ubuntu Release Team <noreply@canonical.com>
To: {recipients} To: {recipients}
X-Proposed-Migration: notice X-Proposed-Migration: notice
Subject: [proposed-migration] {source_name} {version} stuck in {series}-proposed for {rounded_age} days. Subject: [proposed-migration] {source_name} {version} stuck in {series}-proposed for {rounded_age} day{plural}.
Hi, Hi,
{source_name} {version} needs attention. {source_name} {version} needs attention.
It has been stuck in {series}-proposed for {rounded_age} days. It has been stuck in {series}-proposed for {rounded_age} day{plural}.
You either sponsored or uploaded this package, please investigate why it hasn't been approved for migration. You either sponsored or uploaded this package, please investigate why it hasn't been approved for migration.
@ -158,22 +158,24 @@ class EmailPolicy(BasePolicy, Rest):
def apply_policy_impl(self, email_info, suite, source_name, source_data_tdist, source_data_srcdist, excuse): def apply_policy_impl(self, email_info, suite, source_name, source_data_tdist, source_data_srcdist, excuse):
"""Send email if package is rejected.""" """Send email if package is rejected."""
max_age = 5 if excuse.is_valid else 1
series = self.options.series series = self.options.series
version = source_data_srcdist.version version = source_data_srcdist.version
age = excuse.daysold or 0 age = excuse.daysold or 0
rounded_age = int(age) rounded_age = int(age)
plural = '' if rounded_age == 1 else 's'
# an item is stuck if it's # an item is stuck if it's
# - old enough # - old enough
# - not blocked # - not blocked
# - not temporarily rejected (e.g. by the autopkgtest policy when tests # - not temporarily rejected (e.g. by the autopkgtest policy when tests
# are still running) # are still running)
stuck = age >= 3 and 'block' not in excuse.reason and \ stuck = age >= max_age and 'block' not in excuse.reason and \
excuse.current_policy_verdict != PolicyVerdict.REJECTED_TEMPORARILY excuse.current_policy_verdict != PolicyVerdict.REJECTED_TEMPORARILY
cached = self.cache.get(source_name, {}).get(version) cached = self.cache.get(source_name, {}).get(version)
try: try:
emails, sent_age = cached emails, sent_age = cached
sent = (age - sent_age) < min(MAX_FREQUENCY, age / 2.0) sent = (age - sent_age) < min(MAX_FREQUENCY, (age / 2.0) + 0.5)
except TypeError: except TypeError:
# This exception happens when source_name, version never seen before # This exception happens when source_name, version never seen before
emails = [] emails = []

@ -225,8 +225,9 @@ class T(unittest.TestCase):
@patch('britney2.policies.email.EmailPolicy.lp_get_emails') @patch('britney2.policies.email.EmailPolicy.lp_get_emails')
@patch('britney2.policies.email.smtplib', autospec=True) @patch('britney2.policies.email.smtplib', autospec=True)
def test_smtp_repetition(self, smtp, lp): def smtp_repetition(self, smtp, lp, valid=False, expected=None):
"""Resend mails periodically, with decreasing frequency.""" """Resend mails periodically, with decreasing frequency."""
FakeExcuse.is_valid = valid
lp.return_value = ['email@address.com'] lp.return_value = ['email@address.com']
sendmail = smtp.SMTP().sendmail sendmail = smtp.SMTP().sendmail
e = EmailPolicy(FakeOptions, None) e = EmailPolicy(FakeOptions, None)
@ -240,9 +241,19 @@ class T(unittest.TestCase):
if sendmail.call_count > previous: if sendmail.call_count > previous:
e.initialise(None) # Refill e.cache from disk e.initialise(None) # Refill e.cache from disk
called.append(age) called.append(age)
name, args, kwargs = sendmail.mock_calls[-1]
text = args[2]
self.assertNotIn(' 1 days.', text)
self.assertSequenceEqual(called, expected)
def test_smtp_repetition(self):
"""Confirm that emails are sent at appropriate intervals."""
# Emails were sent when daysold reached these values: # Emails were sent when daysold reached these values:
self.assertSequenceEqual(called, [ self.smtp_repetition(valid=False, expected=[
3.0, 6.0, 12.0, 24.0, 48.0, 78.0, 108.0, 138.0, 168.0, 198.0 1.0, 3.0, 7.0, 15.0, 31.0, 61.0, 91.0, 121.0, 151.0, 181.0
])
self.smtp_repetition(valid=True, expected=[
5.0, 11.0, 23.0, 47.0, 77.0, 107.0, 137.0, 167.0, 197.0
]) ])

Loading…
Cancel
Save