Merge lp:~wgrant/launchpad/poppy-transaction-unbreakage into lp:launchpad

Proposed by William Grant
Status: Merged
Approved by: Tim Penhey
Approved revision: no longer in the source branch.
Merged at revision: 12581
Proposed branch: lp:~wgrant/launchpad/poppy-transaction-unbreakage
Merge into: lp:launchpad
Diff against target: 221 lines (+29/-10)
11 files modified
lib/lp/bugs/externalbugtracker/base.py (+1/-1)
lib/lp/bugs/externalbugtracker/bugzilla.py (+1/-1)
lib/lp/bugs/externalbugtracker/debbugs.py (+1/-1)
lib/lp/bugs/externalbugtracker/mantis.py (+1/-1)
lib/lp/bugs/externalbugtracker/rt.py (+1/-1)
lib/lp/bugs/externalbugtracker/trac.py (+1/-1)
lib/lp/bugs/scripts/checkwatches/base.py (+1/-1)
lib/lp/bugs/scripts/checkwatches/tests/test_base.py (+2/-2)
lib/lp/poppy/tests/test_twistedftp.py (+17/-0)
lib/lp/poppy/twistedftp.py (+2/-0)
lib/lp/services/database/tests/test_isolation.py (+1/-1)
To merge this branch: bzr merge lp:~wgrant/launchpad/poppy-transaction-unbreakage
Reviewer Review Type Date Requested Status
Tim Penhey (community) code Approve
Steve Kowalik (community) code* Approve
Review via email: mp+52967@code.launchpad.net

Commit message

[r=stevenk,thumper][bug=733033] Ensure that poppy-sftp aborts the transaction after validating GPG signatures.

Description of the change

poppy-sftp's FTP handler checks the signature of uploaded changes files, but then fails to end the transaction. This branch wraps the check method in @read_transaction, ensuring that the transaction is aborted afterwards.

I also moved lp.bugs.externalbugtracker.isolation to lp.services.database.isolation, since it's generic and useful for the new test.

To post a comment you must log in.
Revision history for this message
Steve Kowalik (stevenk) wrote :

This looks great to me.

review: Approve (code*)
Revision history for this message
Tim Penhey (thumper) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/bugs/externalbugtracker/base.py'
2--- lib/lp/bugs/externalbugtracker/base.py 2011-03-02 00:04:45 +0000
3+++ lib/lp/bugs/externalbugtracker/base.py 2011-03-11 03:36:15 +0000
4@@ -32,7 +32,6 @@
5
6 from canonical.config import config
7 from lp.bugs.adapters import treelookup
8-from lp.bugs.externalbugtracker.isolation import ensure_no_transaction
9 from lp.bugs.interfaces.bugtask import BugTaskStatus
10 from lp.bugs.interfaces.externalbugtracker import (
11 IExternalBugTracker,
12@@ -40,6 +39,7 @@
13 ISupportsCommentImport,
14 ISupportsCommentPushing,
15 )
16+from lp.services.database.isolation import ensure_no_transaction
17
18 # The user agent we send in our requests
19 LP_USER_AGENT = "Launchpad Bugscraper/0.2 (https://bugs.launchpad.net/)"
20
21=== modified file 'lib/lp/bugs/externalbugtracker/bugzilla.py'
22--- lib/lp/bugs/externalbugtracker/bugzilla.py 2011-02-23 06:44:23 +0000
23+++ lib/lp/bugs/externalbugtracker/bugzilla.py 2011-03-11 03:36:15 +0000
24@@ -39,7 +39,6 @@
25 UnparsableBugData,
26 UnparsableBugTrackerVersion,
27 )
28-from lp.bugs.externalbugtracker.isolation import ensure_no_transaction
29 from lp.bugs.externalbugtracker.xmlrpc import UrlLib2Transport
30 from lp.bugs.interfaces.bugtask import (
31 BugTaskImportance,
32@@ -52,6 +51,7 @@
33 UNKNOWN_REMOTE_IMPORTANCE,
34 )
35 from lp.services import encoding
36+from lp.services.database.isolation import ensure_no_transaction
37
38
39 class Bugzilla(ExternalBugTracker):
40
41=== modified file 'lib/lp/bugs/externalbugtracker/debbugs.py'
42--- lib/lp/bugs/externalbugtracker/debbugs.py 2010-08-20 20:31:18 +0000
43+++ lib/lp/bugs/externalbugtracker/debbugs.py 2011-03-11 03:36:15 +0000
44@@ -35,7 +35,6 @@
45 InvalidBugId,
46 UnknownRemoteStatusError,
47 )
48-from lp.bugs.externalbugtracker.isolation import ensure_no_transaction
49 from lp.bugs.interfaces.bugtask import (
50 BugTaskImportance,
51 BugTaskStatus,
52@@ -47,6 +46,7 @@
53 UNKNOWN_REMOTE_IMPORTANCE,
54 )
55 from lp.bugs.scripts import debbugs
56+from lp.services.database.isolation import ensure_no_transaction
57
58
59 debbugsstatusmap = {'open': BugTaskStatus.NEW,
60
61=== modified file 'lib/lp/bugs/externalbugtracker/mantis.py'
62--- lib/lp/bugs/externalbugtracker/mantis.py 2011-03-02 00:04:45 +0000
63+++ lib/lp/bugs/externalbugtracker/mantis.py 2011-03-11 03:36:15 +0000
64@@ -30,12 +30,12 @@
65 UnknownRemoteStatusError,
66 UnparsableBugData,
67 )
68-from lp.bugs.externalbugtracker.isolation import ensure_no_transaction
69 from lp.bugs.interfaces.bugtask import (
70 BugTaskImportance,
71 BugTaskStatus,
72 )
73 from lp.bugs.interfaces.externalbugtracker import UNKNOWN_REMOTE_IMPORTANCE
74+from lp.services.database.isolation import ensure_no_transaction
75 from lp.services.propertycache import cachedproperty
76
77
78
79=== modified file 'lib/lp/bugs/externalbugtracker/rt.py'
80--- lib/lp/bugs/externalbugtracker/rt.py 2010-08-24 10:45:57 +0000
81+++ lib/lp/bugs/externalbugtracker/rt.py 2011-03-11 03:36:15 +0000
82@@ -20,9 +20,9 @@
83 LookupTree,
84 UnknownRemoteStatusError,
85 )
86-from lp.bugs.externalbugtracker.isolation import ensure_no_transaction
87 from lp.bugs.interfaces.bugtask import BugTaskStatus
88 from lp.bugs.interfaces.externalbugtracker import UNKNOWN_REMOTE_IMPORTANCE
89+from lp.services.database.isolation import ensure_no_transaction
90 from lp.services.propertycache import cachedproperty
91
92
93
94=== modified file 'lib/lp/bugs/externalbugtracker/trac.py'
95--- lib/lp/bugs/externalbugtracker/trac.py 2011-03-09 05:50:48 +0000
96+++ lib/lp/bugs/externalbugtracker/trac.py 2011-03-11 03:36:15 +0000
97@@ -33,7 +33,6 @@
98 UnknownRemoteStatusError,
99 UnparsableBugData,
100 )
101-from lp.bugs.externalbugtracker.isolation import ensure_no_transaction
102 from lp.bugs.externalbugtracker.xmlrpc import UrlLib2Transport
103 from lp.bugs.interfaces.bugtask import (
104 BugTaskImportance,
105@@ -45,6 +44,7 @@
106 ISupportsCommentPushing,
107 UNKNOWN_REMOTE_IMPORTANCE,
108 )
109+from lp.services.database.isolation import ensure_no_transaction
110
111 # Symbolic constants used for the Trac LP plugin.
112 LP_PLUGIN_BUG_IDS_ONLY = 0
113
114=== modified file 'lib/lp/bugs/scripts/checkwatches/base.py'
115--- lib/lp/bugs/scripts/checkwatches/base.py 2010-11-08 18:33:15 +0000
116+++ lib/lp/bugs/scripts/checkwatches/base.py 2011-03-11 03:36:15 +0000
117@@ -32,7 +32,7 @@
118 from canonical.launchpad.webapp.interaction import setupInteraction
119 from canonical.launchpad.webapp.interfaces import IPlacelessAuthUtility
120 from lp.bugs.externalbugtracker import BugWatchUpdateWarning
121-from lp.bugs.externalbugtracker.isolation import check_no_transaction
122+from lp.services.database.isolation import check_no_transaction
123 from lp.services.limitedlist import LimitedList
124
125 # For OOPS reporting keep up to this number of SQL statements.
126
127=== modified file 'lib/lp/bugs/scripts/checkwatches/tests/test_base.py'
128--- lib/lp/bugs/scripts/checkwatches/tests/test_base.py 2010-12-20 03:21:03 +0000
129+++ lib/lp/bugs/scripts/checkwatches/tests/test_base.py 2011-03-11 03:36:15 +0000
130@@ -16,11 +16,11 @@
131 queryInteraction,
132 )
133 from canonical.testing.layers import LaunchpadZopelessLayer
134-from lp.bugs.externalbugtracker.isolation import (
135+from lp.bugs.scripts.checkwatches.base import WorkingBase
136+from lp.services.database.isolation import (
137 is_transaction_in_progress,
138 TransactionInProgress,
139 )
140-from lp.bugs.scripts.checkwatches.base import WorkingBase
141 from lp.services.log.logger import BufferLogger
142 from lp.testing import TestCaseWithFactory
143
144
145=== modified file 'lib/lp/poppy/tests/test_twistedftp.py'
146--- lib/lp/poppy/tests/test_twistedftp.py 2011-02-24 17:42:26 +0000
147+++ lib/lp/poppy/tests/test_twistedftp.py 2011-03-11 03:36:15 +0000
148@@ -10,6 +10,7 @@
149 from testtools.deferredruntest import (
150 AsynchronousDeferredRunTest,
151 )
152+import transaction
153 from twisted.protocols import ftp
154 from zope.component import getUtility
155
156@@ -22,6 +23,7 @@
157 from lp.registry.interfaces.gpg import (
158 GPGKeyAlgorithm,
159 IGPGKeySet)
160+from lp.services.database.isolation import check_no_transaction
161 from lp.testing import TestCaseWithFactory
162 from lp.testing.keyserver import KeyServerTac
163
164@@ -56,6 +58,8 @@
165 algorithm=GPGKeyAlgorithm.items[key.algorithm],
166 keysize=key.keysize, can_encrypt=key.can_encrypt,
167 active=True)
168+ # validateGPG runs in its own transaction.
169+ transaction.commit()
170
171 # Locate the directory with test files.
172 self.test_files_dir = os.path.join(
173@@ -92,3 +96,16 @@
174 d = file_writer.close()
175 d.addCallbacks(success_callback, error_callback)
176 return d
177+
178+ def test_aborts_transaction(self):
179+ valid_changes_file = os.path.join(
180+ self.test_files_dir, "etherwake_1.08-1_source.changes")
181+
182+ def callback(result):
183+ check_no_transaction()
184+
185+ with open(valid_changes_file) as opened_file:
186+ file_writer = PoppyFileWriter(opened_file)
187+ d = file_writer.close()
188+ d.addBoth(callback)
189+ return d
190
191=== modified file 'lib/lp/poppy/twistedftp.py'
192--- lib/lp/poppy/twistedftp.py 2011-02-25 16:36:38 +0000
193+++ lib/lp/poppy/twistedftp.py 2011-03-11 03:36:15 +0000
194@@ -33,6 +33,7 @@
195 from lp.poppy.filesystem import UploadFileSystem
196 from lp.poppy.hooks import Hooks
197 from lp.registry.interfaces.gpg import IGPGKeySet
198+from lp.services.database import read_transaction
199
200
201 class PoppyAccessCheck:
202@@ -156,6 +157,7 @@
203 return defer.fail(ftp.PermissionDeniedError(error))
204 return defer.succeed(None)
205
206+ @read_transaction
207 def validateGPG(self, signed_file):
208 """Check the GPG signature in the file referenced by signed_file.
209
210
211=== renamed file 'lib/lp/bugs/externalbugtracker/isolation.py' => 'lib/lp/services/database/isolation.py'
212=== renamed file 'lib/lp/bugs/externalbugtracker/tests/test_isolation.py' => 'lib/lp/services/database/tests/test_isolation.py'
213--- lib/lp/bugs/externalbugtracker/tests/test_isolation.py 2011-01-22 17:57:02 +0000
214+++ lib/lp/services/database/tests/test_isolation.py 2011-03-11 03:36:15 +0000
215@@ -11,7 +11,7 @@
216 from zope.component import getUtility
217
218 from canonical.testing.layers import LaunchpadZopelessLayer
219-from lp.bugs.externalbugtracker import isolation
220+from lp.services.database import isolation
221 from lp.testing import TestCase
222
223