Merge ~lgp171188/launchpad:allow-reporting-bugs-arbitrary-packages-distros-without-publishing into launchpad:master

Proposed by Guruprasad
Status: Merged
Approved by: Guruprasad
Approved revision: 8a392e95e45bda810cd4ef6cced5dc5ebf3ce5e4
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~lgp171188/launchpad:allow-reporting-bugs-arbitrary-packages-distros-without-publishing
Merge into: launchpad:master
Diff against target: 236 lines (+139/-24)
3 files modified
lib/lp/bugs/model/bugtask.py (+4/-2)
lib/lp/bugs/model/tests/test_bugtask.py (+47/-13)
lib/lp/bugs/scripts/tests/test_uct.py (+88/-9)
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Review via email: mp+432250@code.launchpad.net

Commit message

Allow bugtasks against any package in a distroseries without published sources

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/bugs/model/bugtask.py b/lib/lp/bugs/model/bugtask.py
2index 33d3647..c006618 100644
3--- a/lib/lp/bugs/model/bugtask.py
4+++ b/lib/lp/bugs/model/bugtask.py
5@@ -357,11 +357,13 @@ def validate_target(
6 if IDistributionSourcePackage.providedBy(
7 target
8 ) or ISourcePackage.providedBy(target):
9- # If the distribution has at least one series, check that the
10- # source package has been published in the distribution.
11+ # If the distribution has at least one series and has published
12+ # sources, check that the source package has been published in
13+ # the distribution.
14 if (
15 check_source_package
16 and target.sourcepackagename is not None
17+ and target.distribution.has_published_sources
18 and len(target.distribution.series) > 0
19 ):
20 try:
21diff --git a/lib/lp/bugs/model/tests/test_bugtask.py b/lib/lp/bugs/model/tests/test_bugtask.py
22index 598a27a..c3eb248 100644
23--- a/lib/lp/bugs/model/tests/test_bugtask.py
24+++ b/lib/lp/bugs/model/tests/test_bugtask.py
25@@ -70,7 +70,7 @@ from lp.services.database.sqlbase import (
26 from lp.services.features.testing import FeatureFixture
27 from lp.services.job.tests import block_on_job
28 from lp.services.log.logger import DevNullLogger
29-from lp.services.propertycache import get_property_cache
30+from lp.services.propertycache import clear_property_cache, get_property_cache
31 from lp.services.searchbuilder import any
32 from lp.services.webapp.authorization import check_permission
33 from lp.services.webapp.interfaces import ILaunchBag, OAuthPermission
34@@ -3461,27 +3461,52 @@ class TestValidateTarget(TestCaseWithFactory, ValidateTargetMixin):
35 )
36
37 def test_dsp_without_publications_disallowed(self):
38- # If a distribution has series, a DistributionSourcePackage task
39- # can only be created if the package is published in a distro
40- # archive.
41+ # If a distribution has series and has published sources,
42+ # a DistributionSourcePackage task can only be created if
43+ # the package is published in a distro archive.
44 series = self.factory.makeDistroSeries()
45+ self.assertFalse(series.distribution.has_published_sources)
46 dsp = self.factory.makeDistributionSourcePackage(
47 distribution=series.distribution
48 )
49+ self.factory.makeSourcePackagePublishingHistory(
50+ distroseries=series,
51+ sourcepackagename=dsp.sourcepackagename,
52+ archive=series.main_archive,
53+ )
54+ clear_property_cache(series.distribution)
55+ self.assertTrue(series.distribution.has_published_sources)
56+ another_dsp = self.factory.makeDistributionSourcePackage(
57+ distribution=series.distribution
58+ )
59 task = self.factory.makeBugTask()
60 self.assertRaisesWithContent(
61 IllegalTarget,
62- "Package %s not published in %s"
63- % (dsp.sourcepackagename.name, dsp.distribution.displayname),
64+ "Package {} not published in {}".format(
65+ another_dsp.sourcepackagename.name,
66+ another_dsp.distribution.displayname,
67+ ),
68 validate_target,
69 task.bug,
70- dsp,
71+ another_dsp,
72+ )
73+
74+ def test_dsp_with_distribution_has_published_sources_false(self):
75+ # If a distribution has one or more series and does not have
76+ # published sources, a bug task can be created against any existing
77+ # DistributionSourcePackage instance.
78+ series = self.factory.makeDistroSeries()
79+ self.assertFalse(series.distribution.has_published_sources)
80+ dsp = self.factory.makeDistributionSourcePackage(
81+ distribution=series.distribution
82 )
83+ task = self.factory.makeBugTask()
84+ validate_target(task.bug, dsp)
85
86 def test_dsp_with_publications_allowed(self):
87- # If a distribution has series, a DistributionSourcePackage task
88- # can only be created if the package is published in a distro
89- # archive.
90+ # If a distribution has one or more series and has published sources,
91+ # a DistributionSourcePackage task can only be created if the package
92+ # is published in a distro archive.
93 series = self.factory.makeDistroSeries()
94 dsp = self.factory.makeDistributionSourcePackage(
95 distribution=series.distribution
96@@ -3495,13 +3520,22 @@ class TestValidateTarget(TestCaseWithFactory, ValidateTargetMixin):
97 validate_target(task.bug, dsp)
98
99 def test_dsp_with_only_ppa_publications_disallowed(self):
100- # If a distribution has series, a DistributionSourcePackage task
101- # can only be created if the package is published in a distro
102- # archive. PPA publications don't count.
103+ # If a distribution has one or more series and has published sources,
104+ # a DistributionSourcePackage task can only be created if the package
105+ # is published in a distro archive. PPA publications don't count.
106 series = self.factory.makeDistroSeries()
107 dsp = self.factory.makeDistributionSourcePackage(
108 distribution=series.distribution
109 )
110+ another_dsp = self.factory.makeDistributionSourcePackage(
111+ distribution=series.distribution
112+ )
113+ self.factory.makeSourcePackagePublishingHistory(
114+ distroseries=series,
115+ sourcepackagename=another_dsp.sourcepackagename,
116+ archive=series.main_archive,
117+ )
118+ self.assertTrue(series.distribution.has_published_sources)
119 task = self.factory.makeBugTask()
120 self.factory.makeSourcePackagePublishingHistory(
121 distroseries=series,
122diff --git a/lib/lp/bugs/scripts/tests/test_uct.py b/lib/lp/bugs/scripts/tests/test_uct.py
123index 20ae931..9813d86 100644
124--- a/lib/lp/bugs/scripts/tests/test_uct.py
125+++ b/lib/lp/bugs/scripts/tests/test_uct.py
126@@ -575,15 +575,8 @@ class TestUCTImporterExporter(TestCaseWithFactory):
127 sourcepackagename=self.ubuntu_package.sourcepackagename,
128 ),
129 )
130-
131- for series in (self.esm_current_series, self.esm_supported_series):
132- self.factory.makeSourcePackagePublishingHistory(
133- distroseries=series,
134- sourcepackagerelease=self.factory.makeSourcePackageRelease(
135- distroseries=series,
136- sourcepackagename=self.esm_package.sourcepackagename,
137- ),
138- )
139+ # Note: The ubuntu-esm distribution does not have any source packages
140+ # published.
141
142 self.lp_cve = self.factory.makeCVE("2022-23222")
143 self.cve = CVE(
144@@ -894,6 +887,92 @@ class TestUCTImporterExporter(TestCaseWithFactory):
145 "UCT CVE entry CVE-2022-23222", import_bug_activity.message
146 )
147
148+ def test_create_bug_distribution_has_published_sources_false(self):
149+ distribution = self.factory.makeDistribution(
150+ name="no-published-sources"
151+ )
152+ self.assertFalse(distribution.has_published_sources)
153+ supported_series = self.factory.makeDistroSeries(
154+ distribution=distribution,
155+ status=SeriesStatus.SUPPORTED,
156+ name="supported-series",
157+ )
158+ current_series = self.factory.makeDistroSeries(
159+ distribution=distribution,
160+ status=SeriesStatus.CURRENT,
161+ name="current-series",
162+ )
163+ affected_package = self.factory.makeDistributionSourcePackage(
164+ distribution=distribution
165+ )
166+ cve = CVE(
167+ sequence="CVE-2022-1234",
168+ date_made_public=datetime.datetime(
169+ 2022, 1, 1, 8, 15, tzinfo=datetime.timezone.utc
170+ ),
171+ date_notice_issued=datetime.datetime(
172+ 2021, 1, 1, 8, 15, tzinfo=datetime.timezone.utc
173+ ),
174+ date_coordinated_release=datetime.datetime(
175+ 2020, 1, 1, 8, 15, tzinfo=datetime.timezone.utc
176+ ),
177+ distro_packages=[
178+ CVE.DistroPackage(
179+ target=affected_package,
180+ importance=BugTaskImportance.LOW,
181+ package_name=affected_package.sourcepackagename,
182+ ),
183+ ],
184+ series_packages=[
185+ CVE.SeriesPackage(
186+ target=SourcePackage(
187+ sourcepackagename=affected_package.sourcepackagename,
188+ distroseries=supported_series,
189+ ),
190+ package_name=affected_package.sourcepackagename,
191+ importance=BugTaskImportance.HIGH,
192+ status=BugTaskStatus.FIXRELEASED,
193+ status_explanation="released",
194+ ),
195+ CVE.SeriesPackage(
196+ target=SourcePackage(
197+ sourcepackagename=affected_package.sourcepackagename,
198+ distroseries=current_series,
199+ ),
200+ package_name=affected_package.sourcepackagename,
201+ importance=None,
202+ status=BugTaskStatus.DOESNOTEXIST,
203+ status_explanation="does not exist",
204+ ),
205+ ],
206+ upstream_packages=[],
207+ importance=BugTaskImportance.MEDIUM,
208+ status=VulnerabilityStatus.ACTIVE,
209+ assignee=self.factory.makePerson(),
210+ discovered_by="tr3e wang",
211+ description="description",
212+ ubuntu_description="ubuntu-description",
213+ bug_urls=["https://github.com/mm2/Little-CMS/issues/29"],
214+ references=["https://ubuntu.com/security/notices/USN-5368-1"],
215+ notes="author> text",
216+ mitigation="mitigation",
217+ cvss=[
218+ CVSS(
219+ authority="nvd",
220+ vector_string=(
221+ "CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H "
222+ "[7.8 HIGH]"
223+ ),
224+ ),
225+ ],
226+ patch_urls=[],
227+ )
228+ lp_cve = self.factory.makeCVE(sequence="2022-1234")
229+ bug = self.importer.create_bug(cve, lp_cve)
230+ self.checkBug(bug, cve)
231+ self.checkBugTasks(bug, cve)
232+ self.assertEqual([lp_cve], bug.cves)
233+
234 def test_find_existing_bug(self):
235 self.assertIsNone(
236 self.importer._find_existing_bug(self.cve, self.lp_cve)

Subscribers

People subscribed via source and target branches

to status/vote changes: