Merge lp:~cjwatson/launchpad/pocket-chroot-from-livefs-build into lp:launchpad

Proposed by Colin Watson
Status: Merged
Merged at revision: 18637
Proposed branch: lp:~cjwatson/launchpad/pocket-chroot-from-livefs-build
Merge into: lp:launchpad
Diff against target: 123 lines (+59/-3)
4 files modified
lib/lp/_schema_circular_imports.py (+3/-1)
lib/lp/soyuz/browser/tests/test_distroarchseries_webservice.py (+40/-0)
lib/lp/soyuz/interfaces/distroarchseries.py (+11/-1)
lib/lp/soyuz/model/distroarchseries.py (+5/-1)
To merge this branch: bzr merge lp:~cjwatson/launchpad/pocket-chroot-from-livefs-build
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+344912@code.launchpad.net

Commit message

Add DistroArchSeries.setChrootFromBuild, allowing setting a chroot from a file produced by a livefs build.

Description of the change

Ideally we'd make PocketChroot be a history table so that rolling back is easy; but that isn't precluded by this change, and can be done later. I wanted to have a quick and easy way to take advantage of the work in https://code.launchpad.net/~cjwatson/livecd-rootfs/buildd/+merge/344767.

To post a comment you must log in.
Revision history for this message
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/_schema_circular_imports.py'
2--- lib/lp/_schema_circular_imports.py 2017-01-09 17:53:16 +0000
3+++ lib/lp/_schema_circular_imports.py 2018-05-01 19:02:49 +0000
4@@ -1,4 +1,4 @@
5-# Copyright 2009-2017 Canonical Ltd. This software is licensed under the
6+# Copyright 2009-2018 Canonical Ltd. This software is licensed under the
7 # GNU Affero General Public License version 3 (see the file LICENSE).
8
9 """Update the interface schema values due to circular imports.
10@@ -489,6 +489,8 @@
11
12 # IDistroArchSeries
13 patch_reference_property(IDistroArchSeries, 'main_archive', IArchive)
14+patch_plain_parameter_type(
15+ IDistroArchSeries, 'setChrootFromBuild', 'livefsbuild', ILiveFSBuild)
16
17 # IGitRef
18 patch_reference_property(IGitRef, 'repository', IGitRepository)
19
20=== modified file 'lib/lp/soyuz/browser/tests/test_distroarchseries_webservice.py'
21--- lib/lp/soyuz/browser/tests/test_distroarchseries_webservice.py 2018-02-01 18:44:21 +0000
22+++ lib/lp/soyuz/browser/tests/test_distroarchseries_webservice.py 2018-05-01 19:02:49 +0000
23@@ -13,8 +13,12 @@
24 )
25 from zope.security.management import endInteraction
26
27+from lp.services.features.testing import FeatureFixture
28+from lp.soyuz.interfaces.livefs import LIVEFS_FEATURE_FLAG
29 from lp.testing import (
30+ api_url,
31 launchpadlib_for,
32+ login_as,
33 TestCaseWithFactory,
34 ws_object,
35 )
36@@ -118,3 +122,39 @@
37 self.assertTrue(ws_das.chroot_url.endswith(expected_file))
38 ws_das.removeChroot()
39 self.assertIsNone(ws_das.chroot_url)
40+
41+ def test_setChrootFromBuild(self):
42+ self.useFixture(FeatureFixture({LIVEFS_FEATURE_FLAG: "on"}))
43+ das = self.factory.makeDistroArchSeries()
44+ build = self.factory.makeLiveFSBuild()
45+ build_url = api_url(build)
46+ login_as(build.livefs.owner)
47+ lfas = []
48+ for filename in (
49+ "livecd.ubuntu-base.rootfs.tar.gz",
50+ "livecd.ubuntu-base.manifest"):
51+ lfa = self.factory.makeLibraryFileAlias(filename=filename)
52+ lfas.append(lfa)
53+ build.addFile(lfa)
54+ user = das.distroseries.distribution.main_archive.owner
55+ webservice = launchpadlib_for("testing", user)
56+ ws_das = ws_object(webservice, das)
57+ ws_das.setChrootFromBuild(
58+ livefsbuild=build_url, filename="livecd.ubuntu-base.rootfs.tar.gz")
59+ self.assertEqual(lfas[0], das.getChroot())
60+
61+ def test_setChrootFromBuild_random_user(self):
62+ # Random users are not allowed to set chroots from a livefs build.
63+ self.useFixture(FeatureFixture({LIVEFS_FEATURE_FLAG: "on"}))
64+ das = self.factory.makeDistroArchSeries()
65+ build = self.factory.makeLiveFSBuild()
66+ build_url = api_url(build)
67+ login_as(build.livefs.owner)
68+ build.addFile(self.factory.makeLibraryFileAlias(
69+ filename="livecd.ubuntu-base.rootfs.tar.gz"))
70+ user = self.factory.makePerson()
71+ webservice = launchpadlib_for("testing", user, version='devel')
72+ ws_das = ws_object(webservice, das)
73+ self.assertRaises(
74+ Unauthorized, ws_das.setChrootFromBuild,
75+ livefsbuild=build_url, filename="livecd.ubuntu-base.rootfs.tar.gz")
76
77=== modified file 'lib/lp/soyuz/interfaces/distroarchseries.py'
78--- lib/lp/soyuz/interfaces/distroarchseries.py 2015-05-13 09:37:29 +0000
79+++ lib/lp/soyuz/interfaces/distroarchseries.py 2018-05-01 19:02:49 +0000
80@@ -1,4 +1,4 @@
81-# Copyright 2009-2013 Canonical Ltd. This software is licensed under the
82+# Copyright 2009-2018 Canonical Ltd. This software is licensed under the
83 # GNU Affero General Public License version 3 (see the file LICENSE).
84
85 """Distribution architecture series interfaces."""
86@@ -186,6 +186,16 @@
87 The SHA-1 checksum must match the chroot file.
88 """
89
90+ @operation_parameters(
91+ # Really ILiveFSBuild, patched in _schema_circular_imports.py.
92+ livefsbuild=Reference(
93+ Interface, title=_("Live filesystem build"), required=True),
94+ filename=TextLine(title=_("Filename"), required=True))
95+ @export_write_operation()
96+ @operation_for_version("devel")
97+ def setChrootFromBuild(livefsbuild, filename):
98+ """Set the chroot tarball from a live filesystem build."""
99+
100 @export_write_operation()
101 @operation_for_version("devel")
102 def removeChroot():
103
104=== modified file 'lib/lp/soyuz/model/distroarchseries.py'
105--- lib/lp/soyuz/model/distroarchseries.py 2015-07-08 16:05:11 +0000
106+++ lib/lp/soyuz/model/distroarchseries.py 2018-05-01 19:02:49 +0000
107@@ -1,4 +1,4 @@
108-# Copyright 2009-2014 Canonical Ltd. This software is licensed under the
109+# Copyright 2009-2018 Canonical Ltd. This software is licensed under the
110 # GNU Affero General Public License version 3 (see the file LICENSE).
111
112 __metaclass__ = type
113@@ -194,6 +194,10 @@
114 raise InvalidChrootUploaded("Chroot upload checksums do not match")
115 self.addOrUpdateChroot(lfa)
116
117+ def setChrootFromBuild(self, livefsbuild, filename):
118+ """See `IDistroArchSeries`."""
119+ self.addOrUpdateChroot(livefsbuild.getFileByName(filename))
120+
121 def removeChroot(self):
122 """See `IDistroArchSeries`."""
123 self.addOrUpdateChroot(None)