From b896fbf038657d85a809ee75d3a7da9228a855f7 Mon Sep 17 00:00:00 2001 From: Iain Lane Date: Thu, 9 Mar 2017 10:31:41 +0000 Subject: [PATCH] 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 --- britney.conf | 3 +++ britney.py | 6 +++++- britney2/policies/email.py | 11 ++++++++++- britney_nobreakall.conf | 3 +++ 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/britney.conf b/britney.conf index 921461d..d859f0d 100644 --- a/britney.conf +++ b/britney.conf @@ -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 diff --git a/britney.py b/britney.py index a66b266..fe9af4b 100755 --- a/britney.py +++ b/britney.py @@ -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) diff --git a/britney2/policies/email.py b/britney2/policies/email.py index bf3d812..b612bb7 100644 --- a/britney2/policies/email.py +++ b/britney2/policies/email.py @@ -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' diff --git a/britney_nobreakall.conf b/britney_nobreakall.conf index c71f539..02e3b04 100644 --- a/britney_nobreakall.conf +++ b/britney_nobreakall.conf @@ -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