Merge ~robru/britney/+git/britney2-ubuntu:write-email-cache-often into ~ubuntu-release/britney/+git/britney2-ubuntu:master

Proposed by Robert Bruce Park on 2017-03-10
Status: Merged
Merged at revision: 1b4828bfb32f65f2f3e26357d565fafeba611db4
Proposed branch: ~robru/britney/+git/britney2-ubuntu:write-email-cache-often
Merge into: ~ubuntu-release/britney/+git/britney2-ubuntu:master
Diff against target: 32 lines (+6/-4)
1 file modified
britney2/policies/email.py (+6/-4)
Reviewer Review Type Date Requested Status
Steve Langasek 2017-03-10 Needs Fixing on 2017-03-10
Review via email: mp+319604@code.launchpad.net

Description of the Change

Drop asserts that could crash britney, and write sent email cache after every email sent, thus preventing future cases of "britney is spamming mails because it's crashing before it can write it's email cache".

To post a comment you must log in.
Steve Langasek (vorlon) wrote :

The only thing I see that stands out is that you are writing a log entry each time you call save_state(), and you are now calling save_state() for each email sent. That looks spammy to me. Could you either drop the log message, or write it out only the last time save_state() is called, with britney!=None?

review: Needs Fixing
Robert Bruce Park (robru) wrote :

Ok fixed, please merge.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/britney2/policies/email.py b/britney2/policies/email.py
2index 129d665..385a7ed 100644
3--- a/britney2/policies/email.py
4+++ b/britney2/policies/email.py
5@@ -111,8 +111,8 @@ class EmailPolicy(BasePolicy, Rest):
6 for line in details.splitlines():
7 parts = line.split(':')
8 if parts[0] == 'info':
9- assert int(parts[1]) == 1 # Version
10- assert int(parts[2]) <= 1 # Count
11+ if int(parts[1]) != 1 or int(parts[2]) > 1:
12+ break
13 if parts[0] == 'uid':
14 flags = parts[4]
15 if 'e' in flags or 'r' in flags:
16@@ -185,12 +185,14 @@ class EmailPolicy(BasePolicy, Rest):
17 self.log("Failed to send mail! Is SMTP server running?")
18 self.log(err)
19 self.emails_by_pkg[source_name][version] = sent
20+ self.save_state()
21 return PolicyVerdict.PASS
22
23- def save_state(self, britney):
24+ def save_state(self, britney=None):
25 """Write source ppa data to disk"""
26 tmp = self.filename + '.tmp'
27 with open(tmp, 'w', encoding='utf-8') as data:
28 json.dump(self.emails_by_pkg, data)
29 os.rename(tmp, self.filename)
30- self.log("Wrote email data to %s" % self.filename)
31+ if britney:
32+ self.log("Wrote email data to %s" % self.filename)

Subscribers

People subscribed via source and target branches