Enable email policy based on a config flag

So we can turn it off for the "notest" run and for the non-dev series.

This is a tristate

 - 'yes': send email as normal
 - 'dry-run': log what it would do, but send no email [nor update the
   cache, so each run is effectively a fresh run]
 - 'no': disable completely
email-direct-upload-sponsor
Iain Lane 8 years ago
parent 2775a5435c
commit b896fbf038

@ -100,3 +100,6 @@ ADT_PPAS =
# set this to the path of a (r/o) results.cache for running many parallel
# britney instances for PPAs without updating the cache
ADT_SHARED_RESULTS_CACHE =
# email uploaders for stuck uploads
EMAIL_ENABLE = dry-run

@ -538,7 +538,11 @@ class Britney(object):
if getattr(self.options, 'adt_enable') == 'yes':
self.policies.append(AutopkgtestPolicy(self.options, self.suite_info))
self.policies.append(SourcePPAPolicy(self.options, self.suite_info))
self.policies.append(EmailPolicy(self.options, self.suite_info))
add_email_policy = getattr(self.options, 'email_enable', 'no')
if add_email_policy in ('yes', 'dry-run'):
self.policies.append(EmailPolicy(self.options,
self.suite_info,
dry_run=add_email_policy == 'dry-run'))
for policy in self.policies:
policy.register_hints(self._hint_parser)

@ -65,13 +65,14 @@ def address_chooser(addresses):
class EmailPolicy(BasePolicy, Rest):
"""Send an email when a package has been rejected."""
def __init__(self, options, suite_info):
def __init__(self, options, suite_info, dry_run=False):
super().__init__('email', options, suite_info, {'unstable'})
self.filename = os.path.join(options.unstable, 'EmailCache')
# Dict of dicts; maps pkg name -> pkg version -> boolean
self.emails_by_pkg = defaultdict(dict)
# self.cache contains self.emails_by_pkg from previous run
self.cache = {}
self.dry_run = dry_run
def initialise(self, britney):
"""Load cached source ppa data"""
@ -144,6 +145,14 @@ class EmailPolicy(BasePolicy, Rest):
version = source_data_srcdist.version
sent = self.cache.get(source_name, {}).get(version, False)
stuck = (excuse.daysold or 0) >= max_age
if self.dry_run:
self.log("[email dry run] Considering: %s/%s: %s" %
(source_name, version, "stuck" if stuck else "not stuck"))
if stuck:
self.log("[email dry run] Age %d >= threshold %d: would email: %s" %
(excuse.daysold or 0, max_age, self.lp_get_emails(source_name, version)))
# don't update the cache file in dry run mode; we'll see all output each time
return PolicyVerdict.PASS
if stuck and not sent:
msg = MIMEText(MESSAGE_BODY.format(**locals()))
msg['X-Proposed-Migration'] = 'notice'

@ -98,3 +98,6 @@ ADT_PPAS =
# set this to the path of a (r/o) results.cache for running many parallel
# britney instances for PPAs without updating the cache
ADT_SHARED_RESULTS_CACHE =
# email uploaders for stuck uploads
EMAIL_ENABLE = dry-run

Loading…
Cancel
Save