Merge lp:~cjwatson/launchpad/report-pcj-oops into lp:launchpad

Proposed by Colin Watson on 2012-08-01
Status: Merged
Approved by: Aaron Bentley on 2012-08-07
Approved revision: no longer in the source branch.
Merged at revision: 15769
Proposed branch: lp:~cjwatson/launchpad/report-pcj-oops
Merge into: lp:launchpad
Diff against target: 85 lines (+30/-5)
2 files modified
lib/lp/soyuz/model/packagecopyjob.py (+11/-3)
lib/lp/soyuz/tests/test_packagecopyjob.py (+19/-2)
To merge this branch: bzr merge lp:~cjwatson/launchpad/report-pcj-oops
Reviewer Review Type Date Requested Status
Aaron Bentley (community) 2012-08-01 Approve on 2012-08-07
Review via email: mp+117601@code.launchpad.net

Commit Message

Display a slightly more helpful error message if copying a package to a PPA OOPSes.

Description of the Change

== Summary ==

Bug 1031092: When a package copy job OOPSes, the message displayed on Archive:+packages is not terribly informative.

== Proposed fix ==

Override PlainPackageCopyJob.notifyOops to store an "internal error" message in the job's error_message. The text I used is largely copied from BaseRunnableJob.getOopsMailController, with minor contextual adjustments.

== LOC Rationale ==

+24. This is part of removing the old synchronous copy path in Archive:+copy-packages and using the asynchronous path for everyone. Besides, I have 3911 lines of credit.

== Tests ==

bin/test -vvct test_packagecopyjob

== Demo and Q/A ==

This is easier to test while bug 1031089 is still open, since that provides a handy way to get a job to OOPS. Make sure you're in ~launchpad-beta-testers; copy a package from one PPA to another; delete it from the target PPA; copy it again. The message on the target PPA's +packages should be a bit more informative than before.

To post a comment you must log in.
Aaron Bentley (abentley) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/soyuz/model/packagecopyjob.py'
2--- lib/lp/soyuz/model/packagecopyjob.py 2012-07-30 16:48:37 +0000
3+++ lib/lp/soyuz/model/packagecopyjob.py 2012-08-08 09:33:36 +0000
4@@ -513,6 +513,15 @@
5 if pu is not None:
6 pu.setRejected()
7
8+ def notifyOops(self, oops):
9+ """See `IRunnableJob`."""
10+ if not self.error_message:
11+ self.reportFailure(
12+ "Launchpad encountered an internal error while copying this"
13+ " package. It was logged with id %s. Sorry for the"
14+ " inconvenience." % oops["id"])
15+ super(PlainPackageCopyJob, self).notifyOops(oops)
16+
17 def run(self):
18 """See `IRunnableJob`."""
19 try:
20@@ -524,7 +533,7 @@
21 logger = logging.getLogger()
22 logger.info("Job:\n%s\nraised CannotCopy:\n%s" % (self, e))
23 self.abort() # Abort the txn.
24- self.reportFailure(e)
25+ self.reportFailure(unicode(e))
26
27 # If there is an associated PackageUpload we need to reject it,
28 # else it will sit in ACCEPTED forever.
29@@ -636,9 +645,8 @@
30 for dsd in candidates
31 if dsd.parent_series.distributionID == source_distro_id]
32
33- def reportFailure(self, cannotcopy_exception):
34+ def reportFailure(self, message):
35 """Attempt to report failure to the user."""
36- message = unicode(cannotcopy_exception)
37 if self.target_archive.purpose != ArchivePurpose.PPA:
38 dsds = self.findMatchingDSDs()
39 comment_source = getUtility(IDistroSeriesDifferenceCommentSource)
40
41=== modified file 'lib/lp/soyuz/tests/test_packagecopyjob.py'
42--- lib/lp/soyuz/tests/test_packagecopyjob.py 2012-07-31 15:34:45 +0000
43+++ lib/lp/soyuz/tests/test_packagecopyjob.py 2012-08-08 09:33:36 +0000
44@@ -8,7 +8,10 @@
45
46 from storm.store import Store
47 from testtools.content import text_content
48-from testtools.matchers import MatchesStructure
49+from testtools.matchers import (
50+ MatchesRegex,
51+ MatchesStructure,
52+ )
53 import transaction
54 from zope.component import getUtility
55 from zope.security.interfaces import Unauthorized
56@@ -417,6 +420,20 @@
57 "Destination pocket must be 'release' for a PPA.",
58 job.error_message)
59
60+ def test_target_ppa_message_unexpected_error(self):
61+ # When copying to a PPA archive, unexpected errors are stored in the
62+ # job's metadata with an apologetic message.
63+ job = self.makePPAJob()
64+ removeSecurityProxy(job).attemptCopy = FakeMethod(failure=Exception())
65+ self.runJob(job)
66+ self.assertEqual(JobStatus.FAILED, job.status)
67+ self.assertThat(
68+ job.error_message,
69+ MatchesRegex(
70+ "Launchpad encountered an internal error while copying this"
71+ " package. It was logged with id .*. Sorry for the"
72+ " inconvenience."))
73+
74 def test_run(self):
75 # A proper test run synchronizes packages.
76
77@@ -1525,7 +1542,7 @@
78 def test_reportFailure(self):
79 job = self.makeJob()
80 switch_dbuser(self.dbuser)
81- removeSecurityProxy(job).reportFailure(CannotCopy("Mommy it hurts"))
82+ removeSecurityProxy(job).reportFailure("Mommy it hurts")
83
84
85 class TestPackageCopyJobSource(TestCaseWithFactory):