Merge ~cjwatson/launchpad:close-account-decouple-hwdb into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: c07c11a1f4eaa1221df3bba988f5fb35688d08f8
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:close-account-decouple-hwdb
Merge into: launchpad:master
Diff against target: 178 lines (+105/-27)
2 files modified
lib/lp/registry/scripts/closeaccount.py (+4/-2)
lib/lp/registry/scripts/tests/test_closeaccount.py (+101/-25)
Reviewer Review Type Date Requested Status
Ioana Lasc (community) Approve
Review via email: mp+389976@code.launchpad.net

Commit message

Decouple close-account from the hardware DB model

Description of the change

lp.hardwaredb is in the process of being removed, but close-account will still need to be able to cope with closing accounts that have hardware submissions attached. Rewrite that code using raw SQL so that it no longer requires the corresponding Storm models to exist.

To post a comment you must log in.
Revision history for this message
Ioana Lasc (ilasc) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/registry/scripts/closeaccount.py b/lib/lp/registry/scripts/closeaccount.py
2index faf5056..b85acc5 100644
3--- a/lib/lp/registry/scripts/closeaccount.py
4+++ b/lib/lp/registry/scripts/closeaccount.py
5@@ -19,7 +19,6 @@ from lp.answers.enums import QuestionStatus
6 from lp.answers.model.question import Question
7 from lp.app.interfaces.launchpad import ILaunchpadCelebrities
8 from lp.bugs.model.bugtask import BugTask
9-from lp.hardwaredb.model.hwdb import HWSubmission
10 from lp.registry.interfaces.person import PersonCreationRationale
11 from lp.registry.model.person import (
12 Person,
13@@ -370,7 +369,10 @@ def close_account(username, log):
14 AND owner = ?
15 """, (person.id,))
16 table_notification('HWSubmission')
17- store.find(HWSubmission, HWSubmission.ownerID == person.id).remove()
18+ store.execute("""
19+ DELETE FROM HWSubmission
20+ WHERE HWSubmission.owner = ?
21+ """, (person.id,))
22
23 # Purge deleted PPAs. This is safe because the archive can only be in
24 # the DELETED status if the publisher has removed it from disk and set
25diff --git a/lib/lp/registry/scripts/tests/test_closeaccount.py b/lib/lp/registry/scripts/tests/test_closeaccount.py
26index 883fad0..cee0fce 100644
27--- a/lib/lp/registry/scripts/tests/test_closeaccount.py
28+++ b/lib/lp/registry/scripts/tests/test_closeaccount.py
29@@ -27,11 +27,6 @@ from lp.archivepublisher.publishing import Publisher
30 from lp.bugs.model.bugsummary import BugSummary
31 from lp.code.enums import TargetRevisionControlSystems
32 from lp.code.tests.helpers import GitHostingFixture
33-from lp.hardwaredb.interfaces.hwdb import (
34- HWBus,
35- IHWDeviceSet,
36- IHWSubmissionSet,
37- )
38 from lp.registry.interfaces.person import IPersonSet
39 from lp.registry.scripts.closeaccount import CloseAccountScript
40 from lp.scripts.garbo import PopulateLatestPersonSourcePackageReleaseCache
41@@ -405,36 +400,117 @@ class TestCloseAccount(TestCaseWithFactory):
42 self.assertIsNotNone(ppa.getAuthToken(person))
43
44 def test_handles_hardware_submissions(self):
45+ # Launchpad used to support hardware submissions. This is in the
46+ # process of being removed after a long period of relative disuse,
47+ # but close-account still needs to cope with old accounts that have
48+ # them, so we resort to raw SQL to set things up.
49 person = self.factory.makePerson()
50- submission = self.factory.makeHWSubmission(
51- emailaddress=person.preferredemail.email)
52- other_submission = self.factory.makeHWSubmission()
53- device = getUtility(IHWDeviceSet).getByDeviceID(
54- HWBus.PCI, '0x10de', '0x0455')
55+ store = Store.of(person)
56+ date_created = get_transaction_timestamp(store)
57+ keys = [
58+ self.factory.getUniqueUnicode('submission-key') for _ in range(2)]
59+ raw_submissions = [
60+ self.factory.makeLibraryFileAlias(db_only=True) for _ in range(2)]
61+ systems = [
62+ self.factory.getUniqueUnicode('system-fingerprint')
63+ for _ in range(2)]
64+ system_fingerprint_ids = [
65+ row[0] for row in store.execute("""
66+ INSERT INTO HWSystemFingerprint (fingerprint)
67+ VALUES (?), (?)
68+ RETURNING id
69+ """, systems)]
70+ submission_ids = [
71+ row[0] for row in store.execute("""
72+ INSERT INTO HWSubmission
73+ (date_created, format, private, contactable,
74+ submission_key, owner, raw_submission,
75+ system_fingerprint)
76+ VALUES
77+ (?, 1, FALSE, FALSE, ?, ?, ?, ?),
78+ (?, 1, FALSE, FALSE, ?, ?, ?, ?)
79+ RETURNING id
80+ """,
81+ (date_created, keys[0], person.id,
82+ raw_submissions[0].id, system_fingerprint_ids[0],
83+ date_created, keys[1], self.factory.makePerson().id,
84+ raw_submissions[1].id, system_fingerprint_ids[1]))]
85 with dbuser('hwdb-submission-processor'):
86- parent_submission_device = self.factory.makeHWSubmissionDevice(
87- submission, device, None, None, 1)
88- self.factory.makeHWSubmissionDevice(
89- submission, device, None, parent_submission_device, 2)
90- other_submission_device = self.factory.makeHWSubmissionDevice(
91- other_submission, device, None, None, 1)
92- key = submission.submission_key
93- other_key = other_submission.submission_key
94- hw_submission_set = getUtility(IHWSubmissionSet)
95- self.assertNotEqual([], list(hw_submission_set.getByOwner(person)))
96- self.assertEqual(submission, hw_submission_set.getBySubmissionKey(key))
97+ device_driver_link_id = store.execute("""
98+ SELECT HWDeviceDriverLink.id
99+ FROM HWDeviceDriverLink, HWDevice, HWVendorID
100+ WHERE
101+ HWVendorID.bus = 1
102+ AND HWVendorID.vendor_id_for_bus = '0x10de'
103+ AND HWDevice.bus_vendor_id = HWVendorID.id
104+ AND HWDevice.bus_product_id = '0x0455'
105+ AND HWDevice.variant IS NULL
106+ AND HWDeviceDriverLink.device = HWDevice.id
107+ AND HWDeviceDriverLink.driver IS NULL
108+ """).get_one()[0]
109+ parent_submission_device_id = store.execute("""
110+ INSERT INTO HWSubmissionDevice
111+ (device_driver_link, submission, parent, hal_device_id)
112+ VALUES (?, ?, NULL, 1)
113+ RETURNING id
114+ """,
115+ (device_driver_link_id, submission_ids[0])).get_one()[0]
116+ store.execute("""
117+ INSERT INTO HWSubmissionDevice
118+ (device_driver_link, submission, parent, hal_device_id)
119+ VALUES (?, ?, ?, 2)
120+ """,
121+ (device_driver_link_id, submission_ids[0],
122+ parent_submission_device_id))
123+ other_submission_device_id = store.execute("""
124+ INSERT INTO HWSubmissionDevice
125+ (device_driver_link, submission, hal_device_id)
126+ VALUES (?, ?, 1)
127+ RETURNING id
128+ """,
129+ (device_driver_link_id, submission_ids[1])).get_one()[0]
130+
131+ def get_submissions_by_owner(person):
132+ return [
133+ row[0] for row in store.execute("""
134+ SELECT HWSubmission.id
135+ FROM HWSubmission, HWSystemFingerprint
136+ WHERE
137+ HWSubmission.owner = ?
138+ AND HWSystemFingerprint.id =
139+ HWSubmission.system_fingerprint
140+ """, (person.id,))]
141+
142+ def get_submission_by_submission_key(submission_key):
143+ result = store.execute("""
144+ SELECT id FROM HWSubmission WHERE submission_key = ?
145+ """, (submission_key,))
146+ row = result.get_one()
147+ self.assertIsNone(result.get_one())
148+ return row[0] if row else None
149+
150+ def get_devices_by_submission(submission_id):
151+ return [
152+ row[0] for row in store.execute("""
153+ SELECT id FROM HWSubmissionDevice WHERE submission = ?
154+ """, (submission_id,))]
155+
156+ self.assertNotEqual([], get_submissions_by_owner(person))
157+ self.assertEqual(
158+ submission_ids[0], get_submission_by_submission_key(keys[0]))
159 person_id = person.id
160 account_id = person.account.id
161 script = self.makeScript([six.ensure_str(person.name)])
162 with dbuser('launchpad'):
163 self.runScript(script)
164 self.assertRemoved(account_id, person_id)
165- self.assertEqual([], list(hw_submission_set.getByOwner(person)))
166- self.assertIsNone(hw_submission_set.getBySubmissionKey(key))
167+ self.assertEqual([], get_submissions_by_owner(person))
168+ self.assertIsNone(get_submission_by_submission_key(keys[0]))
169 self.assertEqual(
170- other_submission, hw_submission_set.getBySubmissionKey(other_key))
171+ submission_ids[1], get_submission_by_submission_key(keys[1]))
172 self.assertEqual(
173- [other_submission_device], list(other_submission.devices))
174+ [other_submission_device_id],
175+ get_devices_by_submission(submission_ids[1]))
176
177 def test_skips_bug_summary(self):
178 person = self.factory.makePerson()

Subscribers

People subscribed via source and target branches

to status/vote changes: