Merge ~cjwatson/launchpad:stormify-libraryfile-queries into launchpad:master
- Git
- lp:~cjwatson/launchpad
- stormify-libraryfile-queries
- Merge into master
Proposed by
Colin Watson
Status: | Merged |
---|---|
Approved by: | Colin Watson |
Approved revision: | 43722f731ecb94626ecda7c7cfe7b07922d86a34 |
Merge reported by: | Otto Co-Pilot |
Merged at revision: | not available |
Proposed branch: | ~cjwatson/launchpad:stormify-libraryfile-queries |
Merge into: | launchpad:master |
Diff against target: |
665 lines (+113/-92) 14 files modified
cronscripts/parse-librarian-apache-access-logs.py (+6/-5) lib/lp/archiveuploader/tests/test_nascentupload_documentation.py (+2/-1) lib/lp/registry/model/person.py (+5/-4) lib/lp/registry/stories/productrelease/xx-productrelease-view.rst (+5/-2) lib/lp/services/librarian/client.py (+2/-6) lib/lp/services/librarian/model.py (+9/-8) lib/lp/services/librarian/tests/test_client.py (+6/-5) lib/lp/services/librarianserver/db.py (+6/-1) lib/lp/services/librarianserver/testing/server.py (+2/-1) lib/lp/services/librarianserver/tests/test_gc.py (+62/-53) lib/lp/services/librarianserver/tests/test_storage.py (+1/-1) lib/lp/soyuz/browser/tests/distroseriesqueue-views.rst (+2/-1) lib/lp/soyuz/doc/package-diff.rst (+3/-2) lib/lp/soyuz/doc/soyuz-set-of-uploads.rst (+2/-2) |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Simone Pelosi | Approve | ||
Review via email: mp+451635@code.launchpad.net |
Commit message
Convert LibraryFile{
Description of the change
`LibraryFileAlias` and `LibraryFileCon
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | diff --git a/cronscripts/parse-librarian-apache-access-logs.py b/cronscripts/parse-librarian-apache-access-logs.py |
2 | index 935f12e..1a724b5 100755 |
3 | --- a/cronscripts/parse-librarian-apache-access-logs.py |
4 | +++ b/cronscripts/parse-librarian-apache-access-logs.py |
5 | @@ -16,9 +16,9 @@ updating the counts of every LFA, in order to get through the backlog. |
6 | |
7 | import _pythonpath # noqa: F401 |
8 | |
9 | -from storm.sqlobject import SQLObjectNotFound |
10 | from zope.component import getUtility |
11 | |
12 | +from lp.app.errors import NotFoundError |
13 | from lp.services.apachelogparser.script import ParseApacheLogs |
14 | from lp.services.config import config |
15 | from lp.services.librarian.interfaces import ILibraryFileAliasSet |
16 | @@ -47,10 +47,11 @@ class ParseLibrarianApacheLogs(ParseApacheLogs): |
17 | def getDownloadCountUpdater(self, file_id): |
18 | """See `ParseApacheLogs`.""" |
19 | try: |
20 | - return self.libraryfilealias_set[file_id].updateDownloadCount |
21 | - except SQLObjectNotFound: |
22 | - # This file has been deleted from the librarian, so don't |
23 | - # try to store download counters for it. |
24 | + return self.libraryfilealias_set[int(file_id)].updateDownloadCount |
25 | + except (ValueError, NotFoundError): |
26 | + # Either this isn't a valid file ID or this file has been |
27 | + # deleted from the librarian, so don't try to store download |
28 | + # counters for it. |
29 | return None |
30 | |
31 | |
32 | diff --git a/lib/lp/archiveuploader/tests/test_nascentupload_documentation.py b/lib/lp/archiveuploader/tests/test_nascentupload_documentation.py |
33 | index 1b27830..f163b4f 100644 |
34 | --- a/lib/lp/archiveuploader/tests/test_nascentupload_documentation.py |
35 | +++ b/lib/lp/archiveuploader/tests/test_nascentupload_documentation.py |
36 | @@ -12,6 +12,7 @@ from lp.archiveuploader.nascentupload import NascentUpload |
37 | from lp.archiveuploader.tests import datadir, getPolicy |
38 | from lp.archiveuploader.uploadpolicy import ArchiveUploadType |
39 | from lp.registry.interfaces.distribution import IDistributionSet |
40 | +from lp.services.database.interfaces import IStore |
41 | from lp.services.librarian.model import LibraryFileAlias |
42 | from lp.services.log.logger import DevNullLogger |
43 | from lp.soyuz.interfaces.component import IComponentSet |
44 | @@ -76,7 +77,7 @@ def prepareHoaryForUploads(test): |
45 | ComponentSelection(distroseries=hoary, component=universe) |
46 | |
47 | # Create a fake hoary/i386 chroot. |
48 | - fake_chroot = LibraryFileAlias.get(1) |
49 | + fake_chroot = IStore(LibraryFileAlias).get(LibraryFileAlias, 1) |
50 | hoary["i386"].addOrUpdateChroot(fake_chroot) |
51 | |
52 | LaunchpadZopelessLayer.txn.commit() |
53 | diff --git a/lib/lp/registry/model/person.py b/lib/lp/registry/model/person.py |
54 | index 8aef249..3dea058 100644 |
55 | --- a/lib/lp/registry/model/person.py |
56 | +++ b/lib/lp/registry/model/person.py |
57 | @@ -234,7 +234,7 @@ from lp.services.identity.interfaces.emailaddress import ( |
58 | ) |
59 | from lp.services.identity.model.account import Account |
60 | from lp.services.identity.model.emailaddress import EmailAddress, HasOwnerMixin |
61 | -from lp.services.librarian.model import LibraryFileAlias |
62 | +from lp.services.librarian.model import LibraryFileAlias, LibraryFileContent |
63 | from lp.services.mail.helpers import ( |
64 | get_contact_email_addresses, |
65 | get_email_template, |
66 | @@ -4603,9 +4603,10 @@ class PersonSet: |
67 | return |
68 | # Listify, since this is a pure cache. |
69 | list( |
70 | - LibraryFileAlias.select( |
71 | - "LibraryFileAlias.id IN %s" % sqlvalues(aliases), |
72 | - prejoins=["content"], |
73 | + IStore(LibraryFileAlias).find( |
74 | + (LibraryFileAlias, LibraryFileContent), |
75 | + LibraryFileAlias.id.is_in(aliases), |
76 | + LibraryFileAlias.content == LibraryFileContent.id, |
77 | ) |
78 | ) |
79 | |
80 | diff --git a/lib/lp/registry/stories/productrelease/xx-productrelease-view.rst b/lib/lp/registry/stories/productrelease/xx-productrelease-view.rst |
81 | index 867b8aa..b411b02 100644 |
82 | --- a/lib/lp/registry/stories/productrelease/xx-productrelease-view.rst |
83 | +++ b/lib/lp/registry/stories/productrelease/xx-productrelease-view.rst |
84 | @@ -41,9 +41,12 @@ downloaded and the date of the last download on that table as well. |
85 | # Manually update the download counter for that file above so that we can |
86 | # test it. |
87 | >>> from datetime import date, datetime, timezone |
88 | + >>> from lp.services.database.interfaces import IStore |
89 | >>> from lp.services.librarian.model import LibraryFileAlias |
90 | - >>> lfa = LibraryFileAlias.selectOne( |
91 | - ... LibraryFileAlias.q.filename == "firefox_0.9.2.orig.tar.gz" |
92 | + >>> lfa = ( |
93 | + ... IStore(LibraryFileAlias) |
94 | + ... .find(LibraryFileAlias, filename="firefox_0.9.2.orig.tar.gz") |
95 | + ... .one() |
96 | ... ) |
97 | >>> lfa.updateDownloadCount(date(2006, 5, 4), None, 1) |
98 | |
99 | diff --git a/lib/lp/services/librarian/client.py b/lib/lp/services/librarian/client.py |
100 | index c8a803e..b3c8ad7 100644 |
101 | --- a/lib/lp/services/librarian/client.py |
102 | +++ b/lib/lp/services/librarian/client.py |
103 | @@ -28,9 +28,8 @@ from storm.store import Store |
104 | from zope.interface import implementer |
105 | |
106 | from lp.services.config import config, dbconfig |
107 | -from lp.services.database.interfaces import IPrimaryStore |
108 | +from lp.services.database.interfaces import IPrimaryStore, IStore |
109 | from lp.services.database.postgresql import ConnectionString |
110 | -from lp.services.database.sqlobject import SQLObjectNotFound |
111 | from lp.services.librarian.interfaces.client import ( |
112 | LIBRARIAN_SERVER_DEFAULT_TIMEOUT, |
113 | DownloadFailed, |
114 | @@ -410,10 +409,7 @@ class FileDownloadClient: |
115 | """ |
116 | from lp.services.librarian.model import LibraryFileAlias |
117 | |
118 | - try: |
119 | - lfa = LibraryFileAlias.get(aliasID) |
120 | - except SQLObjectNotFound: |
121 | - lfa = None |
122 | + lfa = IStore(LibraryFileAlias).get(LibraryFileAlias, aliasID) |
123 | |
124 | if lfa is None: |
125 | raise DownloadFailed("Alias %d not found" % aliasID) |
126 | diff --git a/lib/lp/services/librarian/model.py b/lib/lp/services/librarian/model.py |
127 | index 83ca952..9c517c5 100644 |
128 | --- a/lib/lp/services/librarian/model.py |
129 | +++ b/lib/lp/services/librarian/model.py |
130 | @@ -19,6 +19,7 @@ from storm.locals import Date, Desc, Int, Reference, ReferenceSet, Store |
131 | from zope.component import adapter, getUtility |
132 | from zope.interface import Interface, implementer |
133 | |
134 | +from lp.app.errors import NotFoundError |
135 | from lp.registry.errors import InvalidFilename |
136 | from lp.services.config import config |
137 | from lp.services.database.constants import DEFAULT, UTC_NOW |
138 | @@ -278,17 +279,17 @@ class LibraryFileAliasSet: |
139 | |
140 | def __getitem__(self, key): |
141 | """See ILibraryFileAliasSet.__getitem__""" |
142 | - return LibraryFileAlias.get(key) |
143 | + lfa = IStore(LibraryFileAlias).get(LibraryFileAlias, key) |
144 | + if lfa is None: |
145 | + raise NotFoundError(key) |
146 | + return lfa |
147 | |
148 | def findBySHA256(self, sha256): |
149 | """See ILibraryFileAliasSet.""" |
150 | - return LibraryFileAlias.select( |
151 | - """ |
152 | - content = LibraryFileContent.id |
153 | - AND LibraryFileContent.sha256 = '%s' |
154 | - """ |
155 | - % sha256, |
156 | - clauseTables=["LibraryFileContent"], |
157 | + return IStore(LibraryFileAlias).find( |
158 | + LibraryFileAlias, |
159 | + LibraryFileAlias.content == LibraryFileContent.id, |
160 | + LibraryFileContent.sha256 == sha256, |
161 | ) |
162 | |
163 | def preloadLastDownloaded(self, lfas): |
164 | diff --git a/lib/lp/services/librarian/tests/test_client.py b/lib/lp/services/librarian/tests/test_client.py |
165 | index 39f6ee8..012d1e1 100644 |
166 | --- a/lib/lp/services/librarian/tests/test_client.py |
167 | +++ b/lib/lp/services/librarian/tests/test_client.py |
168 | @@ -20,7 +20,7 @@ from testtools.testcase import ExpectedException |
169 | |
170 | from lp.services.config import config |
171 | from lp.services.daemons.tachandler import TacTestSetup |
172 | -from lp.services.database.interfaces import IStandbyStore |
173 | +from lp.services.database.interfaces import IStandbyStore, IStore |
174 | from lp.services.database.policy import StandbyDatabasePolicy |
175 | from lp.services.database.sqlbase import block_implicit_flushes |
176 | from lp.services.librarian import client as client_module |
177 | @@ -387,8 +387,9 @@ class LibrarianClientTestCase(TestCase): |
178 | sha256 = hashlib.sha256(data).hexdigest() |
179 | |
180 | client = LibrarianClient() |
181 | - lfa = LibraryFileAlias.get( |
182 | - client.addFile("file", len(data), io.BytesIO(data), "text/plain") |
183 | + lfa = IStore(LibraryFileAlias).get( |
184 | + LibraryFileAlias, |
185 | + client.addFile("file", len(data), io.BytesIO(data), "text/plain"), |
186 | ) |
187 | |
188 | self.assertEqual(md5, lfa.content.md5) |
189 | @@ -427,7 +428,7 @@ class LibrarianClientTestCase(TestCase): |
190 | "expected %s to start with %s" % (download_url, expected_host), |
191 | ) |
192 | # If the alias has been deleted, _getURLForDownload returns None. |
193 | - lfa = LibraryFileAlias.get(alias_id) |
194 | + lfa = IStore(LibraryFileAlias).get(LibraryFileAlias, alias_id) |
195 | lfa.content = None |
196 | call = block_implicit_flushes( # Prevent a ProgrammingError |
197 | LibrarianClient._getURLForDownload |
198 | @@ -469,7 +470,7 @@ class LibrarianClientTestCase(TestCase): |
199 | "expected %s to start with %s" % (download_url, expected_host), |
200 | ) |
201 | # If the alias has been deleted, _getURLForDownload returns None. |
202 | - lfa = LibraryFileAlias.get(alias_id) |
203 | + lfa = IStore(LibraryFileAlias).get(LibraryFileAlias, alias_id) |
204 | lfa.content = None |
205 | call = block_implicit_flushes( # Prevent a ProgrammingError |
206 | RestrictedLibrarianClient._getURLForDownload |
207 | diff --git a/lib/lp/services/librarianserver/db.py b/lib/lp/services/librarianserver/db.py |
208 | index b747c2c..1ffc2f6 100644 |
209 | --- a/lib/lp/services/librarianserver/db.py |
210 | +++ b/lib/lp/services/librarianserver/db.py |
211 | @@ -49,7 +49,12 @@ class Library: |
212 | # The following methods are read-only queries. |
213 | |
214 | def lookupBySHA1(self, digest): |
215 | - return [fc.id for fc in LibraryFileContent.selectBy(sha1=digest)] |
216 | + return [ |
217 | + fc.id |
218 | + for fc in IStore(LibraryFileContent).find( |
219 | + LibraryFileContent, sha1=digest |
220 | + ) |
221 | + ] |
222 | |
223 | @defer.inlineCallbacks |
224 | def _verifyMacaroon(self, macaroon, aliasid): |
225 | diff --git a/lib/lp/services/librarianserver/testing/server.py b/lib/lp/services/librarianserver/testing/server.py |
226 | index c2ef75b..26a7914 100644 |
227 | --- a/lib/lp/services/librarianserver/testing/server.py |
228 | +++ b/lib/lp/services/librarianserver/testing/server.py |
229 | @@ -19,6 +19,7 @@ from fixtures import Fixture, FunctionFixture |
230 | |
231 | from lp.services.config import config |
232 | from lp.services.daemons.tachandler import TacException, TacTestSetup |
233 | +from lp.services.database.interfaces import IStore |
234 | from lp.services.librarian.model import LibraryFileContent |
235 | from lp.services.librarianserver.storage import _relFileLocation |
236 | from lp.services.osutils import get_pid_from_file |
237 | @@ -255,7 +256,7 @@ class LibrarianServerFixture(TacTestSetup): |
238 | def fillLibrarianFile(fileid, content=None): |
239 | """Write contents in disk for a librarian sampledata.""" |
240 | with dbuser("librariangc"): |
241 | - lfc = LibraryFileContent.get(fileid) |
242 | + lfc = IStore(LibraryFileContent).get(LibraryFileContent, fileid) |
243 | if content is None: |
244 | content = b"x" * lfc.filesize |
245 | else: |
246 | diff --git a/lib/lp/services/librarianserver/tests/test_gc.py b/lib/lp/services/librarianserver/tests/test_gc.py |
247 | index 41087cc..0d2a163 100644 |
248 | --- a/lib/lp/services/librarianserver/tests/test_gc.py |
249 | +++ b/lib/lp/services/librarianserver/tests/test_gc.py |
250 | @@ -22,13 +22,12 @@ from swiftclient import client as swiftclient |
251 | from testtools.matchers import AnyMatch, Equals, MatchesListwise, MatchesRegex |
252 | |
253 | from lp.services.config import config |
254 | -from lp.services.database.interfaces import IPrimaryStore |
255 | +from lp.services.database.interfaces import IStore |
256 | from lp.services.database.sqlbase import ( |
257 | ISOLATION_LEVEL_AUTOCOMMIT, |
258 | connect, |
259 | cursor, |
260 | ) |
261 | -from lp.services.database.sqlobject import SQLObjectNotFound |
262 | from lp.services.features.testing import FeatureFixture |
263 | from lp.services.librarian.client import LibrarianClient |
264 | from lp.services.librarian.model import LibraryFileAlias, LibraryFileContent |
265 | @@ -50,6 +49,7 @@ class TestLibrarianGarbageCollectionBase: |
266 | |
267 | def setUp(self): |
268 | super().setUp() |
269 | + self.store = IStore(LibraryFileContent) |
270 | self.client = LibrarianClient() |
271 | self.patch(librariangc, "log", BufferLogger()) |
272 | |
273 | @@ -74,8 +74,7 @@ class TestLibrarianGarbageCollectionBase: |
274 | # Make sure that every file the database knows about exists on disk. |
275 | # We manually remove them for tests that need to cope with missing |
276 | # library items. |
277 | - store = IPrimaryStore(LibraryFileContent) |
278 | - for content in store.find(LibraryFileContent): |
279 | + for content in self.store.find(LibraryFileContent): |
280 | path = librariangc.get_file_path(content.id) |
281 | if not os.path.exists(path): |
282 | if not os.path.exists(os.path.dirname(path)): |
283 | @@ -121,14 +120,14 @@ class TestLibrarianGarbageCollectionBase: |
284 | io.BytesIO(content), |
285 | "text/plain", |
286 | ) |
287 | - f1 = LibraryFileAlias.get(f1_id) |
288 | + f1 = self.store.get(LibraryFileAlias, f1_id) |
289 | f2_id = self.client.addFile( |
290 | "foo.txt", |
291 | len(content), |
292 | io.BytesIO(content), |
293 | "text/plain", |
294 | ) |
295 | - f2 = LibraryFileAlias.get(f2_id) |
296 | + f2 = self.store.get(LibraryFileAlias, f2_id) |
297 | |
298 | # Make sure the duplicates really are distinct |
299 | self.assertNotEqual(f1_id, f2_id) |
300 | @@ -165,16 +164,16 @@ class TestLibrarianGarbageCollectionBase: |
301 | |
302 | # Confirm that the duplicates have been merged |
303 | self.ztm.begin() |
304 | - f1 = LibraryFileAlias.get(self.f1_id) |
305 | - f2 = LibraryFileAlias.get(self.f2_id) |
306 | + f1 = self.store.get(LibraryFileAlias, self.f1_id) |
307 | + f2 = self.store.get(LibraryFileAlias, self.f2_id) |
308 | self.assertEqual(f1.contentID, f2.contentID) |
309 | |
310 | def test_DeleteUnreferencedAliases(self): |
311 | self.ztm.begin() |
312 | |
313 | # Confirm that our sample files are there. |
314 | - f1 = LibraryFileAlias.get(self.f1_id) |
315 | - f2 = LibraryFileAlias.get(self.f2_id) |
316 | + f1 = self.store.get(LibraryFileAlias, self.f1_id) |
317 | + f2 = self.store.get(LibraryFileAlias, self.f2_id) |
318 | # Grab the content IDs related to these |
319 | # unreferenced LibraryFileAliases |
320 | c1_id = f1.contentID |
321 | @@ -188,13 +187,13 @@ class TestLibrarianGarbageCollectionBase: |
322 | # This should have committed |
323 | self.ztm.begin() |
324 | |
325 | - # Confirm that the LibaryFileContents are still there. |
326 | - LibraryFileContent.get(c1_id) |
327 | - LibraryFileContent.get(c2_id) |
328 | + # Confirm that the LibraryFileContents are still there. |
329 | + self.assertIsNotNone(self.store.get(LibraryFileContent, c1_id)) |
330 | + self.assertIsNotNone(self.store.get(LibraryFileContent, c2_id)) |
331 | |
332 | # But the LibraryFileAliases should be gone |
333 | - self.assertRaises(SQLObjectNotFound, LibraryFileAlias.get, self.f1_id) |
334 | - self.assertRaises(SQLObjectNotFound, LibraryFileAlias.get, self.f2_id) |
335 | + self.assertIsNone(self.store.get(LibraryFileAlias, self.f1_id)) |
336 | + self.assertIsNone(self.store.get(LibraryFileAlias, self.f2_id)) |
337 | |
338 | def test_DeleteUnreferencedAliases2(self): |
339 | # Don't delete LibraryFileAliases accessed recently |
340 | @@ -205,8 +204,8 @@ class TestLibrarianGarbageCollectionBase: |
341 | |
342 | # We now have two aliases sharing the same content. |
343 | self.ztm.begin() |
344 | - f1 = LibraryFileAlias.get(self.f1_id) |
345 | - f2 = LibraryFileAlias.get(self.f2_id) |
346 | + f1 = self.store.get(LibraryFileAlias, self.f1_id) |
347 | + f2 = self.store.get(LibraryFileAlias, self.f2_id) |
348 | self.assertEqual(f1.content, f2.content) |
349 | |
350 | # Flag one of our LibraryFileAliases as being recently created |
351 | @@ -222,8 +221,8 @@ class TestLibrarianGarbageCollectionBase: |
352 | librariangc.delete_unreferenced_aliases(self.con) |
353 | |
354 | self.ztm.begin() |
355 | - LibraryFileAlias.get(self.f1_id) |
356 | - self.assertRaises(SQLObjectNotFound, LibraryFileAlias.get, self.f2_id) |
357 | + self.assertIsNotNone(self.store.get(LibraryFileAlias, self.f1_id)) |
358 | + self.assertIsNone(self.store.get(LibraryFileAlias, self.f2_id)) |
359 | |
360 | def test_DeleteUnreferencedAndWellExpiredAliases(self): |
361 | # LibraryFileAliases can be removed after they have expired |
362 | @@ -234,7 +233,7 @@ class TestLibrarianGarbageCollectionBase: |
363 | |
364 | # Flag one of our LibraryFileAliases with an expiry date in the past |
365 | self.ztm.begin() |
366 | - f1 = LibraryFileAlias.get(self.f1_id) |
367 | + f1 = self.store.get(LibraryFileAlias, self.f1_id) |
368 | f1.expires = self.ancient_past |
369 | del f1 |
370 | self.ztm.commit() |
371 | @@ -246,8 +245,8 @@ class TestLibrarianGarbageCollectionBase: |
372 | |
373 | # Make sure both our example files are gone |
374 | self.ztm.begin() |
375 | - self.assertRaises(SQLObjectNotFound, LibraryFileAlias.get, self.f1_id) |
376 | - self.assertRaises(SQLObjectNotFound, LibraryFileAlias.get, self.f2_id) |
377 | + self.assertIsNone(self.store.get(LibraryFileAlias, self.f1_id)) |
378 | + self.assertIsNone(self.store.get(LibraryFileAlias, self.f2_id)) |
379 | |
380 | def test_DoneDeleteUnreferencedButNotExpiredAliases(self): |
381 | # LibraryFileAliases can be removed only after they have expired. |
382 | @@ -261,7 +260,7 @@ class TestLibrarianGarbageCollectionBase: |
383 | # Flag one of our LibraryFileAliases with an expiry date in the |
384 | # recent past. |
385 | self.ztm.begin() |
386 | - f1 = LibraryFileAlias.get(self.f1_id) |
387 | + f1 = self.store.get(LibraryFileAlias, self.f1_id) |
388 | f1.expires = self.recent_past |
389 | del f1 |
390 | self.ztm.commit() |
391 | @@ -274,7 +273,7 @@ class TestLibrarianGarbageCollectionBase: |
392 | # Make sure both our example files are still there |
393 | self.ztm.begin() |
394 | # Our recently expired LibraryFileAlias is still available. |
395 | - LibraryFileAlias.get(self.f1_id) |
396 | + self.assertIsNotNone(self.store.get(LibraryFileAlias, self.f1_id)) |
397 | |
398 | def test_deleteWellExpiredAliases(self): |
399 | # LibraryFileAlias records that are expired are unlinked from their |
400 | @@ -282,7 +281,7 @@ class TestLibrarianGarbageCollectionBase: |
401 | |
402 | # Flag one of our LibraryFileAliases with an expiry date in the past |
403 | self.ztm.begin() |
404 | - f1 = LibraryFileAlias.get(self.f1_id) |
405 | + f1 = self.store.get(LibraryFileAlias, self.f1_id) |
406 | f1.expires = self.ancient_past |
407 | del f1 |
408 | self.ztm.commit() |
409 | @@ -292,10 +291,10 @@ class TestLibrarianGarbageCollectionBase: |
410 | |
411 | self.ztm.begin() |
412 | # Make sure the well expired f1 is still there, but has no content. |
413 | - f1 = LibraryFileAlias.get(self.f1_id) |
414 | + f1 = self.store.get(LibraryFileAlias, self.f1_id) |
415 | self.assertIsNone(f1.content) |
416 | # f2 should still have content, as it isn't flagged for expiry. |
417 | - f2 = LibraryFileAlias.get(self.f2_id) |
418 | + f2 = self.store.get(LibraryFileAlias, self.f2_id) |
419 | self.assertIsNotNone(f2.content) |
420 | |
421 | def test_ignoreRecentlyExpiredAliases(self): |
422 | @@ -305,7 +304,7 @@ class TestLibrarianGarbageCollectionBase: |
423 | # Flag one of our LibraryFileAliases with an expiry date in the |
424 | # recent past. |
425 | self.ztm.begin() |
426 | - f1 = LibraryFileAlias.get(self.f1_id) |
427 | + f1 = self.store.get(LibraryFileAlias, self.f1_id) |
428 | f1.expires = self.recent_past # Within stay of execution. |
429 | del f1 |
430 | self.ztm.commit() |
431 | @@ -316,10 +315,10 @@ class TestLibrarianGarbageCollectionBase: |
432 | self.ztm.begin() |
433 | # Make sure f1 is still there and has content. This ensures that |
434 | # our stay of execution is still working. |
435 | - f1 = LibraryFileAlias.get(self.f1_id) |
436 | + f1 = self.store.get(LibraryFileAlias, self.f1_id) |
437 | self.assertIsNotNone(f1.content) |
438 | # f2 should still have content, as it isn't flagged for expiry. |
439 | - f2 = LibraryFileAlias.get(self.f2_id) |
440 | + f2 = self.store.get(LibraryFileAlias, self.f2_id) |
441 | self.assertIsNotNone(f2.content) |
442 | |
443 | def test_DeleteUnreferencedContent(self): |
444 | @@ -583,11 +582,11 @@ class TestLibrarianGarbageCollectionBase: |
445 | |
446 | # Make sure that our example files have been garbage collected |
447 | self.ztm.begin() |
448 | - self.assertRaises(SQLObjectNotFound, LibraryFileAlias.get, self.f1_id) |
449 | - self.assertRaises(SQLObjectNotFound, LibraryFileAlias.get, self.f2_id) |
450 | + self.assertIsNone(self.store.get(LibraryFileAlias, self.f1_id)) |
451 | + self.assertIsNone(self.store.get(LibraryFileAlias, self.f2_id)) |
452 | |
453 | # And make sure stuff that *is* referenced remains |
454 | - LibraryFileAlias.get(2) |
455 | + self.assertIsNotNone(self.store.get(LibraryFileAlias, 2)) |
456 | cur = cursor() |
457 | cur.execute("SELECT count(*) FROM LibraryFileAlias") |
458 | count = cur.fetchone()[0] |
459 | @@ -625,19 +624,21 @@ class TestDiskLibrarianGarbageCollection( |
460 | # original file, ignoring the extension. |
461 | switch_dbuser("testadmin") |
462 | content = b"foo" |
463 | - lfa = LibraryFileAlias.get( |
464 | + lfa = self.store.get( |
465 | + LibraryFileAlias, |
466 | self.client.addFile( |
467 | "foo.txt", len(content), io.BytesIO(content), "text/plain" |
468 | - ) |
469 | + ), |
470 | ) |
471 | id_aborted = lfa.contentID |
472 | # Roll back the database changes, leaving the file on disk. |
473 | transaction.abort() |
474 | |
475 | - lfa = LibraryFileAlias.get( |
476 | + lfa = self.store.get( |
477 | + LibraryFileAlias, |
478 | self.client.addFile( |
479 | "bar.txt", len(content), io.BytesIO(content), "text/plain" |
480 | - ) |
481 | + ), |
482 | ) |
483 | transaction.commit() |
484 | id_committed = lfa.contentID |
485 | @@ -811,17 +812,19 @@ class TestSwiftLibrarianGarbageCollection( |
486 | # by a manifest. GC treats the segments like the original file. |
487 | switch_dbuser("testadmin") |
488 | content = b"uploading to swift bigly" |
489 | - big1_lfa = LibraryFileAlias.get( |
490 | + big1_lfa = self.store.get( |
491 | + LibraryFileAlias, |
492 | self.client.addFile( |
493 | "foo.txt", len(content), io.BytesIO(content), "text/plain" |
494 | - ) |
495 | + ), |
496 | ) |
497 | big1_id = big1_lfa.contentID |
498 | |
499 | - big2_lfa = LibraryFileAlias.get( |
500 | + big2_lfa = self.store.get( |
501 | + LibraryFileAlias, |
502 | self.client.addFile( |
503 | "bar.txt", len(content), io.BytesIO(content), "text/plain" |
504 | - ) |
505 | + ), |
506 | ) |
507 | big2_id = big2_lfa.contentID |
508 | transaction.commit() |
509 | @@ -872,17 +875,19 @@ class TestSwiftLibrarianGarbageCollection( |
510 | # suggest that it might happen. |
511 | switch_dbuser("testadmin") |
512 | content = b"uploading to swift" |
513 | - f1_lfa = LibraryFileAlias.get( |
514 | + f1_lfa = self.store.get( |
515 | + LibraryFileAlias, |
516 | self.client.addFile( |
517 | "foo.txt", len(content), io.BytesIO(content), "text/plain" |
518 | - ) |
519 | + ), |
520 | ) |
521 | f1_id = f1_lfa.contentID |
522 | |
523 | - f2_lfa = LibraryFileAlias.get( |
524 | + f2_lfa = self.store.get( |
525 | + LibraryFileAlias, |
526 | self.client.addFile( |
527 | "bar.txt", len(content), io.BytesIO(content), "text/plain" |
528 | - ) |
529 | + ), |
530 | ) |
531 | f2_id = f2_lfa.contentID |
532 | transaction.commit() |
533 | @@ -937,17 +942,19 @@ class TestSwiftLibrarianGarbageCollection( |
534 | # to delete it. It's not clear why this happens in practice. |
535 | switch_dbuser("testadmin") |
536 | content = b"uploading to swift" |
537 | - f1_lfa = LibraryFileAlias.get( |
538 | + f1_lfa = self.store.get( |
539 | + LibraryFileAlias, |
540 | self.client.addFile( |
541 | "foo.txt", len(content), io.BytesIO(content), "text/plain" |
542 | - ) |
543 | + ), |
544 | ) |
545 | f1_id = f1_lfa.contentID |
546 | |
547 | - f2_lfa = LibraryFileAlias.get( |
548 | + f2_lfa = self.store.get( |
549 | + LibraryFileAlias, |
550 | self.client.addFile( |
551 | "bar.txt", len(content), io.BytesIO(content), "text/plain" |
552 | - ) |
553 | + ), |
554 | ) |
555 | f2_id = f2_lfa.contentID |
556 | transaction.commit() |
557 | @@ -1017,10 +1024,11 @@ class TestTwoSwiftsLibrarianGarbageCollection( |
558 | switch_dbuser("testadmin") |
559 | content = b"foo" |
560 | lfas = [ |
561 | - LibraryFileAlias.get( |
562 | + self.store.get( |
563 | + LibraryFileAlias, |
564 | self.client.addFile( |
565 | "foo.txt", len(content), io.BytesIO(content), "text/plain" |
566 | - ) |
567 | + ), |
568 | ) |
569 | for _ in range(12) |
570 | ] |
571 | @@ -1103,10 +1111,11 @@ class TestTwoSwiftsLibrarianGarbageCollection( |
572 | switch_dbuser("testadmin") |
573 | content = b"foo" |
574 | lfas = [ |
575 | - LibraryFileAlias.get( |
576 | + self.store.get( |
577 | + LibraryFileAlias, |
578 | self.client.addFile( |
579 | "foo.txt", len(content), io.BytesIO(content), "text/plain" |
580 | - ) |
581 | + ), |
582 | ) |
583 | for _ in range(12) |
584 | ] |
585 | diff --git a/lib/lp/services/librarianserver/tests/test_storage.py b/lib/lp/services/librarianserver/tests/test_storage.py |
586 | index c95d4f8..f5100a1 100644 |
587 | --- a/lib/lp/services/librarianserver/tests/test_storage.py |
588 | +++ b/lib/lp/services/librarianserver/tests/test_storage.py |
589 | @@ -105,7 +105,7 @@ class LibrarianStorageTestCase(unittest.TestCase): |
590 | newfile = self.storage.startAddFile("file", len(data)) |
591 | newfile.append(data) |
592 | lfc_id, lfa_id = newfile.store() |
593 | - lfc = LibraryFileContent.get(lfc_id) |
594 | + lfc = self.store.get(LibraryFileContent, lfc_id) |
595 | self.assertEqual(md5, lfc.md5) |
596 | self.assertEqual(sha1, lfc.sha1) |
597 | self.assertEqual(sha256, lfc.sha256) |
598 | diff --git a/lib/lp/soyuz/browser/tests/distroseriesqueue-views.rst b/lib/lp/soyuz/browser/tests/distroseriesqueue-views.rst |
599 | index a9acb7b..753568a 100644 |
600 | --- a/lib/lp/soyuz/browser/tests/distroseriesqueue-views.rst |
601 | +++ b/lib/lp/soyuz/browser/tests/distroseriesqueue-views.rst |
602 | @@ -7,10 +7,11 @@ for IDistroSeries context (IDistroSeriesView) |
603 | Let's instantiate the view for +queue for anonymous access: |
604 | |
605 | >>> from zope.component import queryMultiAdapter |
606 | + >>> from lp.services.database.interfaces import IStore |
607 | >>> from lp.services.librarian.model import LibraryFileAlias |
608 | >>> from lp.services.webapp.servers import LaunchpadTestRequest |
609 | >>> from lp.registry.interfaces.distribution import IDistributionSet |
610 | - >>> fake_chroot = LibraryFileAlias.get(1) |
611 | + >>> fake_chroot = IStore(LibraryFileAlias).get(LibraryFileAlias, 1) |
612 | |
613 | >>> ubuntu = getUtility(IDistributionSet)["ubuntu"] |
614 | >>> breezy_autotest = ubuntu["breezy-autotest"] |
615 | diff --git a/lib/lp/soyuz/doc/package-diff.rst b/lib/lp/soyuz/doc/package-diff.rst |
616 | index 9591382..ac90cfe 100644 |
617 | --- a/lib/lp/soyuz/doc/package-diff.rst |
618 | +++ b/lib/lp/soyuz/doc/package-diff.rst |
619 | @@ -120,9 +120,10 @@ already requests a package diff against the immediate ancestry. |
620 | Before starting let's enable the universe component and add the i386 |
621 | chroot in hoary in order to be able to accept the NEW packages. |
622 | |
623 | - >>> from lp.soyuz.model.component import ComponentSelection |
624 | + >>> from lp.services.database.interfaces import IStore |
625 | >>> from lp.services.librarian.model import LibraryFileAlias |
626 | >>> from lp.soyuz.interfaces.component import IComponentSet |
627 | + >>> from lp.soyuz.model.component import ComponentSelection |
628 | |
629 | >>> hoary = ubuntu.getSeries("hoary") |
630 | >>> breezy_autotest = ubuntu.getSeries("breezy-autotest") |
631 | @@ -130,7 +131,7 @@ chroot in hoary in order to be able to accept the NEW packages. |
632 | >>> universe = getUtility(IComponentSet)["universe"] |
633 | >>> selection = ComponentSelection(distroseries=hoary, component=universe) |
634 | |
635 | - >>> fake_chroot = LibraryFileAlias.get(1) |
636 | + >>> fake_chroot = IStore(LibraryFileAlias).get(LibraryFileAlias, 1) |
637 | >>> hoary_i386 = hoary["i386"] |
638 | >>> unused = hoary_i386.addOrUpdateChroot(fake_chroot) |
639 | >>> breezy_autotest_i386 = breezy_autotest["i386"] |
640 | diff --git a/lib/lp/soyuz/doc/soyuz-set-of-uploads.rst b/lib/lp/soyuz/doc/soyuz-set-of-uploads.rst |
641 | index bb8e464..cc0e36d 100644 |
642 | --- a/lib/lp/soyuz/doc/soyuz-set-of-uploads.rst |
643 | +++ b/lib/lp/soyuz/doc/soyuz-set-of-uploads.rst |
644 | @@ -76,11 +76,11 @@ for the ubuntutest distribution. |
645 | |
646 | >>> from lp.registry.model.distribution import Distribution |
647 | >>> from lp.services.database.interfaces import IStore |
648 | + >>> from lp.services.librarian.model import LibraryFileAlias |
649 | >>> from lp.soyuz.enums import PackageUploadStatus |
650 | >>> from lp.soyuz.scripts.initialize_distroseries import ( |
651 | ... InitializeDistroSeries, |
652 | ... ) |
653 | - >>> from lp.services.librarian.model import LibraryFileAlias |
654 | >>> from lp.testing.factory import LaunchpadObjectFactory |
655 | >>> ubuntu = IStore(Distribution).find(Distribution, name="ubuntu").one() |
656 | >>> breezy_autotest = ubuntu["breezy-autotest"] |
657 | @@ -110,7 +110,7 @@ for the ubuntutest distribution. |
658 | INFO:...:Copying permissions from parents. |
659 | INFO:...:Creating DistroSeriesDifferences. |
660 | >>> breezy.changeslist = "breezy-changes@ubuntu.com" |
661 | - >>> fake_chroot = LibraryFileAlias.get(1) |
662 | + >>> fake_chroot = IStore(LibraryFileAlias).get(LibraryFileAlias, 1) |
663 | >>> unused = breezy["i386"].addOrUpdateChroot(fake_chroot) |
664 | |
665 | Add disk content for file inherited from ubuntu/breezy-autotest: |
LGTM!