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
diff --git a/lib/lp/hardwaredb/browser/configure.zcml b/lib/lp/hardwaredb/browser/configure.zcml
index 2b5dfe0..4d06052 100644
--- a/lib/lp/hardwaredb/browser/configure.zcml
+++ b/lib/lp/hardwaredb/browser/configure.zcml
@@ -18,6 +18,12 @@
18 permission="zope.Public"18 permission="zope.Public"
19 name="+submit"19 name="+submit"
20 template="../templates/hwdb-submit-hardware-data.pt"/>20 template="../templates/hwdb-submit-hardware-data.pt"/>
21 <browser:page
22 for="lp.hardwaredb.interfaces.hwdb.HWSubmissionsDisabledError"
23 class="lp.hardwaredb.browser.hwdb.HWDBSubmissionsDisabledView"
24 name="index.html"
25 permission="zope.Public"
26 template="../templates/hwdb-submissions-disabled.pt"/>
21 <browser:url27 <browser:url
22 for="lp.hardwaredb.interfaces.hwdb.IHWSystemFingerprint"28 for="lp.hardwaredb.interfaces.hwdb.IHWSystemFingerprint"
23 path_expression="string:+fingerprint/${fingerprint}"29 path_expression="string:+fingerprint/${fingerprint}"
@@ -68,4 +74,4 @@
68 for="lp.hardwaredb.interfaces.hwdb.IHWSubmissionDevice"74 for="lp.hardwaredb.interfaces.hwdb.IHWSubmissionDevice"
69 path_expression="string:+submissiondevice/${id}"75 path_expression="string:+submissiondevice/${id}"
70 parent_utility="lp.hardwaredb.interfaces.hwdb.IHWDBApplication"/>76 parent_utility="lp.hardwaredb.interfaces.hwdb.IHWDBApplication"/>
71</configure>
72\ No newline at end of file77\ No newline at end of file
78</configure>
diff --git a/lib/lp/hardwaredb/browser/hwdb.py b/lib/lp/hardwaredb/browser/hwdb.py
index cbd1801..bbd1ee6 100644
--- a/lib/lp/hardwaredb/browser/hwdb.py
+++ b/lib/lp/hardwaredb/browser/hwdb.py
@@ -7,6 +7,7 @@ __all__ = [
7 'HWDBApplicationNavigation',7 'HWDBApplicationNavigation',
8 'HWDBFingerprintSetView',8 'HWDBFingerprintSetView',
9 'HWDBPersonSubmissionsView',9 'HWDBPersonSubmissionsView',
10 'HWDBSubmissionsDisabledView',
10 'HWDBSubmissionTextView',11 'HWDBSubmissionTextView',
11 'HWDBUploadView',12 'HWDBUploadView',
12 ]13 ]
@@ -41,6 +42,7 @@ from lp.services.webapp import (
41 stepthrough,42 stepthrough,
42 )43 )
43from lp.services.webapp.batching import BatchNavigator44from lp.services.webapp.batching import BatchNavigator
45from lp.services.webapp.error import GoneView
44from lp.services.webapp.interfaces import ILaunchBag46from lp.services.webapp.interfaces import ILaunchBag
4547
4648
@@ -156,6 +158,12 @@ class HWDBUploadView(LaunchpadFormView):
156 u'X-Launchpad-HWDB-Submission', value)158 u'X-Launchpad-HWDB-Submission', value)
157159
158160
161class HWDBSubmissionsDisabledView(GoneView):
162 """View to indicate that new submissions are disabled."""
163
164 page_title = "Hardware database submissions disabled"
165
166
159class HWDBPersonSubmissionsView(LaunchpadView):167class HWDBPersonSubmissionsView(LaunchpadView):
160 """View class for preseting HWDB submissions by a person."""168 """View class for preseting HWDB submissions by a person."""
161169
diff --git a/lib/lp/hardwaredb/interfaces/hwdb.py b/lib/lp/hardwaredb/interfaces/hwdb.py
index 082c742..ca76b86 100644
--- a/lib/lp/hardwaredb/interfaces/hwdb.py
+++ b/lib/lp/hardwaredb/interfaces/hwdb.py
@@ -7,9 +7,11 @@ __metaclass__ = type
77
8__all__ = [8__all__ = [
9 'HWBus',9 'HWBus',
10 'HWDB_SUBMISSIONS_DISABLED_FEATURE_FLAG',
10 'HWSubmissionFormat',11 'HWSubmissionFormat',
11 'HWSubmissionKeyNotUnique',12 'HWSubmissionKeyNotUnique',
12 'HWSubmissionProcessingStatus',13 'HWSubmissionProcessingStatus',
14 'HWSubmissionsDisabledError',
13 'IHWDBApplication',15 'IHWDBApplication',
14 'IHWDevice',16 'IHWDevice',
15 'IHWDeviceClass',17 'IHWDeviceClass',
@@ -96,6 +98,23 @@ from lp.services.webservice.apihelpers import (
96from lp.soyuz.interfaces.distroarchseries import IDistroArchSeries98from lp.soyuz.interfaces.distroarchseries import IDistroArchSeries
9799
98100
101HWDB_SUBMISSIONS_DISABLED_FEATURE_FLAG = 'hardwaredb.submissions.disabled'
102
103
104@error_status(http_client.GONE)
105class HWSubmissionsDisabledError(Exception):
106 """An exception saying that hardware database submissions are disabled."""
107
108 def __init__(self, message=None):
109 if message is None:
110 message = (
111 "Launchpad's hardware database is obsolete and is no longer "
112 "accepting submissions. Please use "
113 "https://answers.launchpad.net/launchpad/+addquestion to tell "
114 "us about your requirements if you still need it.")
115 super(HWSubmissionsDisabledError, self).__init__(message)
116
117
99def validate_new_submission_key(submission_key):118def validate_new_submission_key(submission_key):
100 """Check, if submission_key already exists in HWDBSubmission."""119 """Check, if submission_key already exists in HWDBSubmission."""
101 if not valid_name(submission_key):120 if not valid_name(submission_key):
diff --git a/lib/lp/hardwaredb/model/hwdb.py b/lib/lp/hardwaredb/model/hwdb.py
index e1a4460..4e73474 100644
--- a/lib/lp/hardwaredb/model/hwdb.py
+++ b/lib/lp/hardwaredb/model/hwdb.py
@@ -61,9 +61,11 @@ from lp.bugs.model.bug import (
61from lp.bugs.model.bugsubscription import BugSubscription61from lp.bugs.model.bugsubscription import BugSubscription
62from lp.hardwaredb.interfaces.hwdb import (62from lp.hardwaredb.interfaces.hwdb import (
63 HWBus,63 HWBus,
64 HWDB_SUBMISSIONS_DISABLED_FEATURE_FLAG,
64 HWSubmissionFormat,65 HWSubmissionFormat,
65 HWSubmissionKeyNotUnique,66 HWSubmissionKeyNotUnique,
66 HWSubmissionProcessingStatus,67 HWSubmissionProcessingStatus,
68 HWSubmissionsDisabledError,
67 IHWDevice,69 IHWDevice,
68 IHWDeviceClass,70 IHWDeviceClass,
69 IHWDeviceClassSet,71 IHWDeviceClassSet,
@@ -113,6 +115,7 @@ from lp.services.database.sqlbase import (
113 SQLBase,115 SQLBase,
114 sqlvalues,116 sqlvalues,
115 )117 )
118from lp.services.features import getFeatureFlag
116from lp.services.librarian.interfaces import ILibraryFileAliasSet119from lp.services.librarian.interfaces import ILibraryFileAliasSet
117from lp.soyuz.interfaces.distroarchseries import IDistroArchSeries120from lp.soyuz.interfaces.distroarchseries import IDistroArchSeries
118from lp.soyuz.model.distroarchseries import DistroArchSeries121from lp.soyuz.model.distroarchseries import DistroArchSeries
@@ -161,6 +164,9 @@ class HWSubmissionSet:
161 raw_submission, filename, filesize,164 raw_submission, filename, filesize,
162 system_fingerprint):165 system_fingerprint):
163 """See `IHWSubmissionSet`."""166 """See `IHWSubmissionSet`."""
167 if getFeatureFlag(HWDB_SUBMISSIONS_DISABLED_FEATURE_FLAG):
168 raise HWSubmissionsDisabledError()
169
164 assert valid_name(submission_key), "Invalid key %s" % submission_key170 assert valid_name(submission_key), "Invalid key %s" % submission_key
165171
166 submission_exists = HWSubmission.selectOneBy(172 submission_exists = HWSubmission.selectOneBy(
diff --git a/lib/lp/hardwaredb/stories/hwdb/xx-hwdb.txt b/lib/lp/hardwaredb/stories/hwdb/xx-hwdb.txt
index 98128d1..148f79b 100644
--- a/lib/lp/hardwaredb/stories/hwdb/xx-hwdb.txt
+++ b/lib/lp/hardwaredb/stories/hwdb/xx-hwdb.txt
@@ -59,6 +59,27 @@ Human users get a message too.
59 ... print(tag)59 ... print(tag)
60 <div class="informational message">Thank you for your submission.</div>60 <div class="informational message">Thank you for your submission.</div>
6161
62If the feature flag to disable new submissions is set, then we return an
63appropriate HTTP error instead.
64
65 >>> from lp.hardwaredb.interfaces.hwdb import (
66 ... HWDB_SUBMISSIONS_DISABLED_FEATURE_FLAG,
67 ... )
68 >>> from lp.services.features.testing import FeatureFixture
69
70 >>> submit_data['Unique Submission Key:'] = 'unique-id-disabled'
71 >>> browser.handleErrors = True
72 >>> with FeatureFixture({HWDB_SUBMISSIONS_DISABLED_FEATURE_FLAG: u'on'}):
73 ... browser.open('http://launchpad.test/+hwdb/+submit')
74 ... fill_form(
75 ... browser, submit_data, submit_data_checkboxes, submit_file,
76 ... 'test.txt')
77 ... browser.getControl('Upload').click()
78 Traceback (most recent call last):
79 ...
80 HTTPError: HTTP Error 410: Gone
81 >>> browser.handleErrors = False
82
62If fields are not set, the response contains a header explaining this83If fields are not set, the response contains a header explaining this
63error.84error.
6485
diff --git a/lib/lp/hardwaredb/templates/hwdb-submissions-disabled.pt b/lib/lp/hardwaredb/templates/hwdb-submissions-disabled.pt
65new file mode 10064486new file mode 100644
index 0000000..772f459
--- /dev/null
+++ b/lib/lp/hardwaredb/templates/hwdb-submissions-disabled.pt
@@ -0,0 +1,19 @@
1<html
2 xmlns="http://www.w3.org/1999/xhtml"
3 xmlns:tal="http://xml.zope.org/namespaces/tal"
4 xmlns:metal="http://xml.zope.org/namespaces/metal"
5 xmlns:i18n="http://xml.zope.org/namespaces/i18n"
6 metal:use-macro="view/macro:page/main_only"
7 i18n:domain="launchpad">
8 <body>
9 <div class="top-portlet" metal:fill-slot="main">
10 <h1>Hardware database submissions disabled</h1>
11
12 <p>
13 Launchpad's hardware database is obsolete and is no longer accepting
14 submissions. Please <a href="/launchpad/+addquestion">tell us about
15 your requirements</a> if you still need it.
16 </p>
17 </div>
18 </body>
19</html>
diff --git a/lib/lp/hardwaredb/tests/test_hwdb.py b/lib/lp/hardwaredb/tests/test_hwdb.py
0new file mode 10064420new file mode 100644
index 0000000..3ad2135
--- /dev/null
+++ b/lib/lp/hardwaredb/tests/test_hwdb.py
@@ -0,0 +1,29 @@
1# Copyright 2020 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).
3
4"""Test the hardware database model."""
5
6from __future__ import absolute_import, print_function, unicode_literals
7
8__metaclass__ = type
9__all__ = []
10
11from lp.hardwaredb.interfaces.hwdb import (
12 HWDB_SUBMISSIONS_DISABLED_FEATURE_FLAG,
13 HWSubmissionsDisabledError,
14 )
15from lp.services.features.testing import FeatureFixture
16from lp.testing import TestCaseWithFactory
17from lp.testing.layers import ZopelessDatabaseLayer
18
19
20class TestHWDBFeatureFlag(TestCaseWithFactory):
21
22 layer = ZopelessDatabaseLayer
23
24 def test_feature_flag_disables_submissions(self):
25 # Launchpad's hardware database is obsolescent. We have a feature
26 # flag to stage the removal of support for new submissions.
27 with FeatureFixture({HWDB_SUBMISSIONS_DISABLED_FEATURE_FLAG: "on"}):
28 self.assertRaises(
29 HWSubmissionsDisabledError, self.factory.makeHWSubmission)
diff --git a/lib/lp/services/webapp/error.py b/lib/lp/services/webapp/error.py
index dfb3067..1fbc2b2 100644
--- a/lib/lp/services/webapp/error.py
+++ b/lib/lp/services/webapp/error.py
@@ -3,6 +3,7 @@
33
4__metaclass__ = type4__metaclass__ = type
5__all__ = [5__all__ = [
6 'GoneView',
6 'InvalidBatchSizeView',7 'InvalidBatchSizeView',
7 'NotFoundView',8 'NotFoundView',
8 'ProtocolErrorView',9 'ProtocolErrorView',

Subscribers

People subscribed via source and target branches

to status/vote changes: