Merge ~cjwatson/launchpad:hwdb-disable-submissions into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: c73b4dc00f4faa02db0b73c6808056bff0cbd228
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:hwdb-disable-submissions
Merge into: launchpad:master
Diff against target: 235 lines (+110/-1)
8 files modified
lib/lp/hardwaredb/browser/configure.zcml (+7/-1)
lib/lp/hardwaredb/browser/hwdb.py (+8/-0)
lib/lp/hardwaredb/interfaces/hwdb.py (+19/-0)
lib/lp/hardwaredb/model/hwdb.py (+6/-0)
lib/lp/hardwaredb/stories/hwdb/xx-hwdb.txt (+21/-0)
lib/lp/hardwaredb/templates/hwdb-submissions-disabled.pt (+19/-0)
lib/lp/hardwaredb/tests/test_hwdb.py (+29/-0)
lib/lp/services/webapp/error.py (+1/-0)
Reviewer Review Type Date Requested Status
Kristian Glass (community) Approve
Review via email: mp+383158@code.launchpad.net

Commit message

Add a feature flag to disable new hwdb submissions

Description of the change

Since Ubuntu xenial, checkbox no longer uses Launchpad's hardware database, and the only new submissions are coming from older systems; the certification teams no longer pay attention to it. Add a hardwaredb.submissions.disabled feature flag to refuse new submissions, with the intention of removing submission support in a month or two if no good reasons to the contrary turn up.

To post a comment you must log in.
Revision history for this message
Kristian Glass (doismellburning) wrote :

Looks good to me, thanks

One inline non-blocking query about your doctest though

review: Approve
c73b4dc... by Colin Watson

Convert hwdb feature flag test to unittest

Revision history for this message
Colin Watson (cjwatson) :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/hardwaredb/browser/configure.zcml b/lib/lp/hardwaredb/browser/configure.zcml
2index 2b5dfe0..4d06052 100644
3--- a/lib/lp/hardwaredb/browser/configure.zcml
4+++ b/lib/lp/hardwaredb/browser/configure.zcml
5@@ -18,6 +18,12 @@
6 permission="zope.Public"
7 name="+submit"
8 template="../templates/hwdb-submit-hardware-data.pt"/>
9+ <browser:page
10+ for="lp.hardwaredb.interfaces.hwdb.HWSubmissionsDisabledError"
11+ class="lp.hardwaredb.browser.hwdb.HWDBSubmissionsDisabledView"
12+ name="index.html"
13+ permission="zope.Public"
14+ template="../templates/hwdb-submissions-disabled.pt"/>
15 <browser:url
16 for="lp.hardwaredb.interfaces.hwdb.IHWSystemFingerprint"
17 path_expression="string:+fingerprint/${fingerprint}"
18@@ -68,4 +74,4 @@
19 for="lp.hardwaredb.interfaces.hwdb.IHWSubmissionDevice"
20 path_expression="string:+submissiondevice/${id}"
21 parent_utility="lp.hardwaredb.interfaces.hwdb.IHWDBApplication"/>
22-</configure>
23\ No newline at end of file
24+</configure>
25diff --git a/lib/lp/hardwaredb/browser/hwdb.py b/lib/lp/hardwaredb/browser/hwdb.py
26index cbd1801..bbd1ee6 100644
27--- a/lib/lp/hardwaredb/browser/hwdb.py
28+++ b/lib/lp/hardwaredb/browser/hwdb.py
29@@ -7,6 +7,7 @@ __all__ = [
30 'HWDBApplicationNavigation',
31 'HWDBFingerprintSetView',
32 'HWDBPersonSubmissionsView',
33+ 'HWDBSubmissionsDisabledView',
34 'HWDBSubmissionTextView',
35 'HWDBUploadView',
36 ]
37@@ -41,6 +42,7 @@ from lp.services.webapp import (
38 stepthrough,
39 )
40 from lp.services.webapp.batching import BatchNavigator
41+from lp.services.webapp.error import GoneView
42 from lp.services.webapp.interfaces import ILaunchBag
43
44
45@@ -156,6 +158,12 @@ class HWDBUploadView(LaunchpadFormView):
46 u'X-Launchpad-HWDB-Submission', value)
47
48
49+class HWDBSubmissionsDisabledView(GoneView):
50+ """View to indicate that new submissions are disabled."""
51+
52+ page_title = "Hardware database submissions disabled"
53+
54+
55 class HWDBPersonSubmissionsView(LaunchpadView):
56 """View class for preseting HWDB submissions by a person."""
57
58diff --git a/lib/lp/hardwaredb/interfaces/hwdb.py b/lib/lp/hardwaredb/interfaces/hwdb.py
59index 082c742..ca76b86 100644
60--- a/lib/lp/hardwaredb/interfaces/hwdb.py
61+++ b/lib/lp/hardwaredb/interfaces/hwdb.py
62@@ -7,9 +7,11 @@ __metaclass__ = type
63
64 __all__ = [
65 'HWBus',
66+ 'HWDB_SUBMISSIONS_DISABLED_FEATURE_FLAG',
67 'HWSubmissionFormat',
68 'HWSubmissionKeyNotUnique',
69 'HWSubmissionProcessingStatus',
70+ 'HWSubmissionsDisabledError',
71 'IHWDBApplication',
72 'IHWDevice',
73 'IHWDeviceClass',
74@@ -96,6 +98,23 @@ from lp.services.webservice.apihelpers import (
75 from lp.soyuz.interfaces.distroarchseries import IDistroArchSeries
76
77
78+HWDB_SUBMISSIONS_DISABLED_FEATURE_FLAG = 'hardwaredb.submissions.disabled'
79+
80+
81+@error_status(http_client.GONE)
82+class HWSubmissionsDisabledError(Exception):
83+ """An exception saying that hardware database submissions are disabled."""
84+
85+ def __init__(self, message=None):
86+ if message is None:
87+ message = (
88+ "Launchpad's hardware database is obsolete and is no longer "
89+ "accepting submissions. Please use "
90+ "https://answers.launchpad.net/launchpad/+addquestion to tell "
91+ "us about your requirements if you still need it.")
92+ super(HWSubmissionsDisabledError, self).__init__(message)
93+
94+
95 def validate_new_submission_key(submission_key):
96 """Check, if submission_key already exists in HWDBSubmission."""
97 if not valid_name(submission_key):
98diff --git a/lib/lp/hardwaredb/model/hwdb.py b/lib/lp/hardwaredb/model/hwdb.py
99index e1a4460..4e73474 100644
100--- a/lib/lp/hardwaredb/model/hwdb.py
101+++ b/lib/lp/hardwaredb/model/hwdb.py
102@@ -61,9 +61,11 @@ from lp.bugs.model.bug import (
103 from lp.bugs.model.bugsubscription import BugSubscription
104 from lp.hardwaredb.interfaces.hwdb import (
105 HWBus,
106+ HWDB_SUBMISSIONS_DISABLED_FEATURE_FLAG,
107 HWSubmissionFormat,
108 HWSubmissionKeyNotUnique,
109 HWSubmissionProcessingStatus,
110+ HWSubmissionsDisabledError,
111 IHWDevice,
112 IHWDeviceClass,
113 IHWDeviceClassSet,
114@@ -113,6 +115,7 @@ from lp.services.database.sqlbase import (
115 SQLBase,
116 sqlvalues,
117 )
118+from lp.services.features import getFeatureFlag
119 from lp.services.librarian.interfaces import ILibraryFileAliasSet
120 from lp.soyuz.interfaces.distroarchseries import IDistroArchSeries
121 from lp.soyuz.model.distroarchseries import DistroArchSeries
122@@ -161,6 +164,9 @@ class HWSubmissionSet:
123 raw_submission, filename, filesize,
124 system_fingerprint):
125 """See `IHWSubmissionSet`."""
126+ if getFeatureFlag(HWDB_SUBMISSIONS_DISABLED_FEATURE_FLAG):
127+ raise HWSubmissionsDisabledError()
128+
129 assert valid_name(submission_key), "Invalid key %s" % submission_key
130
131 submission_exists = HWSubmission.selectOneBy(
132diff --git a/lib/lp/hardwaredb/stories/hwdb/xx-hwdb.txt b/lib/lp/hardwaredb/stories/hwdb/xx-hwdb.txt
133index 98128d1..148f79b 100644
134--- a/lib/lp/hardwaredb/stories/hwdb/xx-hwdb.txt
135+++ b/lib/lp/hardwaredb/stories/hwdb/xx-hwdb.txt
136@@ -59,6 +59,27 @@ Human users get a message too.
137 ... print(tag)
138 <div class="informational message">Thank you for your submission.</div>
139
140+If the feature flag to disable new submissions is set, then we return an
141+appropriate HTTP error instead.
142+
143+ >>> from lp.hardwaredb.interfaces.hwdb import (
144+ ... HWDB_SUBMISSIONS_DISABLED_FEATURE_FLAG,
145+ ... )
146+ >>> from lp.services.features.testing import FeatureFixture
147+
148+ >>> submit_data['Unique Submission Key:'] = 'unique-id-disabled'
149+ >>> browser.handleErrors = True
150+ >>> with FeatureFixture({HWDB_SUBMISSIONS_DISABLED_FEATURE_FLAG: u'on'}):
151+ ... browser.open('http://launchpad.test/+hwdb/+submit')
152+ ... fill_form(
153+ ... browser, submit_data, submit_data_checkboxes, submit_file,
154+ ... 'test.txt')
155+ ... browser.getControl('Upload').click()
156+ Traceback (most recent call last):
157+ ...
158+ HTTPError: HTTP Error 410: Gone
159+ >>> browser.handleErrors = False
160+
161 If fields are not set, the response contains a header explaining this
162 error.
163
164diff --git a/lib/lp/hardwaredb/templates/hwdb-submissions-disabled.pt b/lib/lp/hardwaredb/templates/hwdb-submissions-disabled.pt
165new file mode 100644
166index 0000000..772f459
167--- /dev/null
168+++ b/lib/lp/hardwaredb/templates/hwdb-submissions-disabled.pt
169@@ -0,0 +1,19 @@
170+<html
171+ xmlns="http://www.w3.org/1999/xhtml"
172+ xmlns:tal="http://xml.zope.org/namespaces/tal"
173+ xmlns:metal="http://xml.zope.org/namespaces/metal"
174+ xmlns:i18n="http://xml.zope.org/namespaces/i18n"
175+ metal:use-macro="view/macro:page/main_only"
176+ i18n:domain="launchpad">
177+ <body>
178+ <div class="top-portlet" metal:fill-slot="main">
179+ <h1>Hardware database submissions disabled</h1>
180+
181+ <p>
182+ Launchpad's hardware database is obsolete and is no longer accepting
183+ submissions. Please <a href="/launchpad/+addquestion">tell us about
184+ your requirements</a> if you still need it.
185+ </p>
186+ </div>
187+ </body>
188+</html>
189diff --git a/lib/lp/hardwaredb/tests/test_hwdb.py b/lib/lp/hardwaredb/tests/test_hwdb.py
190new file mode 100644
191index 0000000..3ad2135
192--- /dev/null
193+++ b/lib/lp/hardwaredb/tests/test_hwdb.py
194@@ -0,0 +1,29 @@
195+# Copyright 2020 Canonical Ltd. This software is licensed under the
196+# GNU Affero General Public License version 3 (see the file LICENSE).
197+
198+"""Test the hardware database model."""
199+
200+from __future__ import absolute_import, print_function, unicode_literals
201+
202+__metaclass__ = type
203+__all__ = []
204+
205+from lp.hardwaredb.interfaces.hwdb import (
206+ HWDB_SUBMISSIONS_DISABLED_FEATURE_FLAG,
207+ HWSubmissionsDisabledError,
208+ )
209+from lp.services.features.testing import FeatureFixture
210+from lp.testing import TestCaseWithFactory
211+from lp.testing.layers import ZopelessDatabaseLayer
212+
213+
214+class TestHWDBFeatureFlag(TestCaseWithFactory):
215+
216+ layer = ZopelessDatabaseLayer
217+
218+ def test_feature_flag_disables_submissions(self):
219+ # Launchpad's hardware database is obsolescent. We have a feature
220+ # flag to stage the removal of support for new submissions.
221+ with FeatureFixture({HWDB_SUBMISSIONS_DISABLED_FEATURE_FLAG: "on"}):
222+ self.assertRaises(
223+ HWSubmissionsDisabledError, self.factory.makeHWSubmission)
224diff --git a/lib/lp/services/webapp/error.py b/lib/lp/services/webapp/error.py
225index dfb3067..1fbc2b2 100644
226--- a/lib/lp/services/webapp/error.py
227+++ b/lib/lp/services/webapp/error.py
228@@ -3,6 +3,7 @@
229
230 __metaclass__ = type
231 __all__ = [
232+ 'GoneView',
233 'InvalidBatchSizeView',
234 'NotFoundView',
235 'ProtocolErrorView',

Subscribers

People subscribed via source and target branches

to status/vote changes: