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
=== modified file 'lib/lp/_schema_circular_imports.py'
--- lib/lp/_schema_circular_imports.py 2017-01-09 17:53:16 +0000
+++ lib/lp/_schema_circular_imports.py 2018-05-01 19:02:49 +0000
@@ -1,4 +1,4 @@
1# Copyright 2009-2017 Canonical Ltd. This software is licensed under the1# Copyright 2009-2018 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).2# GNU Affero General Public License version 3 (see the file LICENSE).
33
4"""Update the interface schema values due to circular imports.4"""Update the interface schema values due to circular imports.
@@ -489,6 +489,8 @@
489489
490# IDistroArchSeries490# IDistroArchSeries
491patch_reference_property(IDistroArchSeries, 'main_archive', IArchive)491patch_reference_property(IDistroArchSeries, 'main_archive', IArchive)
492patch_plain_parameter_type(
493 IDistroArchSeries, 'setChrootFromBuild', 'livefsbuild', ILiveFSBuild)
492494
493# IGitRef495# IGitRef
494patch_reference_property(IGitRef, 'repository', IGitRepository)496patch_reference_property(IGitRef, 'repository', IGitRepository)
495497
=== modified file 'lib/lp/soyuz/browser/tests/test_distroarchseries_webservice.py'
--- lib/lp/soyuz/browser/tests/test_distroarchseries_webservice.py 2018-02-01 18:44:21 +0000
+++ lib/lp/soyuz/browser/tests/test_distroarchseries_webservice.py 2018-05-01 19:02:49 +0000
@@ -13,8 +13,12 @@
13 )13 )
14from zope.security.management import endInteraction14from zope.security.management import endInteraction
1515
16from lp.services.features.testing import FeatureFixture
17from lp.soyuz.interfaces.livefs import LIVEFS_FEATURE_FLAG
16from lp.testing import (18from lp.testing import (
19 api_url,
17 launchpadlib_for,20 launchpadlib_for,
21 login_as,
18 TestCaseWithFactory,22 TestCaseWithFactory,
19 ws_object,23 ws_object,
20 )24 )
@@ -118,3 +122,39 @@
118 self.assertTrue(ws_das.chroot_url.endswith(expected_file))122 self.assertTrue(ws_das.chroot_url.endswith(expected_file))
119 ws_das.removeChroot()123 ws_das.removeChroot()
120 self.assertIsNone(ws_das.chroot_url)124 self.assertIsNone(ws_das.chroot_url)
125
126 def test_setChrootFromBuild(self):
127 self.useFixture(FeatureFixture({LIVEFS_FEATURE_FLAG: "on"}))
128 das = self.factory.makeDistroArchSeries()
129 build = self.factory.makeLiveFSBuild()
130 build_url = api_url(build)
131 login_as(build.livefs.owner)
132 lfas = []
133 for filename in (
134 "livecd.ubuntu-base.rootfs.tar.gz",
135 "livecd.ubuntu-base.manifest"):
136 lfa = self.factory.makeLibraryFileAlias(filename=filename)
137 lfas.append(lfa)
138 build.addFile(lfa)
139 user = das.distroseries.distribution.main_archive.owner
140 webservice = launchpadlib_for("testing", user)
141 ws_das = ws_object(webservice, das)
142 ws_das.setChrootFromBuild(
143 livefsbuild=build_url, filename="livecd.ubuntu-base.rootfs.tar.gz")
144 self.assertEqual(lfas[0], das.getChroot())
145
146 def test_setChrootFromBuild_random_user(self):
147 # Random users are not allowed to set chroots from a livefs build.
148 self.useFixture(FeatureFixture({LIVEFS_FEATURE_FLAG: "on"}))
149 das = self.factory.makeDistroArchSeries()
150 build = self.factory.makeLiveFSBuild()
151 build_url = api_url(build)
152 login_as(build.livefs.owner)
153 build.addFile(self.factory.makeLibraryFileAlias(
154 filename="livecd.ubuntu-base.rootfs.tar.gz"))
155 user = self.factory.makePerson()
156 webservice = launchpadlib_for("testing", user, version='devel')
157 ws_das = ws_object(webservice, das)
158 self.assertRaises(
159 Unauthorized, ws_das.setChrootFromBuild,
160 livefsbuild=build_url, filename="livecd.ubuntu-base.rootfs.tar.gz")
121161
=== modified file 'lib/lp/soyuz/interfaces/distroarchseries.py'
--- lib/lp/soyuz/interfaces/distroarchseries.py 2015-05-13 09:37:29 +0000
+++ lib/lp/soyuz/interfaces/distroarchseries.py 2018-05-01 19:02:49 +0000
@@ -1,4 +1,4 @@
1# Copyright 2009-2013 Canonical Ltd. This software is licensed under the1# Copyright 2009-2018 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).2# GNU Affero General Public License version 3 (see the file LICENSE).
33
4"""Distribution architecture series interfaces."""4"""Distribution architecture series interfaces."""
@@ -186,6 +186,16 @@
186 The SHA-1 checksum must match the chroot file.186 The SHA-1 checksum must match the chroot file.
187 """187 """
188188
189 @operation_parameters(
190 # Really ILiveFSBuild, patched in _schema_circular_imports.py.
191 livefsbuild=Reference(
192 Interface, title=_("Live filesystem build"), required=True),
193 filename=TextLine(title=_("Filename"), required=True))
194 @export_write_operation()
195 @operation_for_version("devel")
196 def setChrootFromBuild(livefsbuild, filename):
197 """Set the chroot tarball from a live filesystem build."""
198
189 @export_write_operation()199 @export_write_operation()
190 @operation_for_version("devel")200 @operation_for_version("devel")
191 def removeChroot():201 def removeChroot():
192202
=== modified file 'lib/lp/soyuz/model/distroarchseries.py'
--- lib/lp/soyuz/model/distroarchseries.py 2015-07-08 16:05:11 +0000
+++ lib/lp/soyuz/model/distroarchseries.py 2018-05-01 19:02:49 +0000
@@ -1,4 +1,4 @@
1# Copyright 2009-2014 Canonical Ltd. This software is licensed under the1# Copyright 2009-2018 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).2# GNU Affero General Public License version 3 (see the file LICENSE).
33
4__metaclass__ = type4__metaclass__ = type
@@ -194,6 +194,10 @@
194 raise InvalidChrootUploaded("Chroot upload checksums do not match")194 raise InvalidChrootUploaded("Chroot upload checksums do not match")
195 self.addOrUpdateChroot(lfa)195 self.addOrUpdateChroot(lfa)
196196
197 def setChrootFromBuild(self, livefsbuild, filename):
198 """See `IDistroArchSeries`."""
199 self.addOrUpdateChroot(livefsbuild.getFileByName(filename))
200
197 def removeChroot(self):201 def removeChroot(self):
198 """See `IDistroArchSeries`."""202 """See `IDistroArchSeries`."""
199 self.addOrUpdateChroot(None)203 self.addOrUpdateChroot(None)