Merge ~twom/launchpad:buildd-sha-export into launchpad:master

Proposed by Tom Wardill
Status: Merged
Approved by: Tom Wardill
Approved revision: 945c06d897edea303fa11b99d982cf8f23982c8e
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~twom/launchpad:buildd-sha-export
Merge into: launchpad:master
Diff against target: 69 lines (+29/-0)
3 files modified
lib/lp/soyuz/browser/tests/test_distroarchseries_webservice.py (+14/-0)
lib/lp/soyuz/interfaces/distroarchseries.py (+8/-0)
lib/lp/soyuz/model/distroarchseries.py (+7/-0)
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Review via email: mp+391360@code.launchpad.net

Commit message

Add retrieval of the sha256 for a chroot in a DAS

Description of the change

We set the chroot for a PocketChroot via the DistroArchSeries using it's SHA1, but this is basically write-only without downloading the whole chroot file and recalculating it.
Add an equivalent getChrootHash alongside getChrootURL that returns the sha256 from the librarian file.

Sample API call:
https://api.launchpad.test/devel/ubuntu/bionic/amd64?ws.op=getChrootHash&image_type=Chroot%20tarball&pocket=Release

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

This broadly looks good, but I'd like some small API adjustments.

review: Needs Fixing
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
diff --git a/lib/lp/soyuz/browser/tests/test_distroarchseries_webservice.py b/lib/lp/soyuz/browser/tests/test_distroarchseries_webservice.py
index 32cd64e..c9e6db4 100644
--- a/lib/lp/soyuz/browser/tests/test_distroarchseries_webservice.py
+++ b/lib/lp/soyuz/browser/tests/test_distroarchseries_webservice.py
@@ -14,6 +14,7 @@ from lazr.restfulclient.errors import (
14from testtools.matchers import (14from testtools.matchers import (
15 EndsWith,15 EndsWith,
16 Equals,16 Equals,
17 MatchesDict,
17 MatchesStructure,18 MatchesStructure,
18 )19 )
19from zope.security.management import endInteraction20from zope.security.management import endInteraction
@@ -120,6 +121,19 @@ class TestDistroArchSeriesWebservice(TestCaseWithFactory):
120 data=b'foo\r', sha1sum='95e0c0e09be59e04eb0e312e5daa11a2a830e526')121 data=b'foo\r', sha1sum='95e0c0e09be59e04eb0e312e5daa11a2a830e526')
121 self.assertEqual(sha1, das.getChroot().content.sha1)122 self.assertEqual(sha1, das.getChroot().content.sha1)
122123
124 def test_getChrootHash(self):
125 das = self.factory.makeDistroArchSeries()
126 user = das.distroseries.distribution.main_archive.owner
127 webservice = launchpadlib_for("testing", user)
128 ws_das = ws_object(webservice, das)
129 sha1 = hashlib.sha1('abcxyz').hexdigest()
130 sha256 = hashlib.sha256('abcxyz').hexdigest()
131 ws_das.setChroot(data=b'abcxyz', sha1sum=sha1)
132 self.assertThat(
133 das.getChrootHash(
134 PackagePublishingPocket.RELEASE, BuildBaseImageType.CHROOT),
135 MatchesDict({'sha256': Equals(sha256)}))
136
123 def test_setChroot_removeChroot(self):137 def test_setChroot_removeChroot(self):
124 das = self.factory.makeDistroArchSeries()138 das = self.factory.makeDistroArchSeries()
125 user = das.distroseries.distribution.main_archive.owner139 user = das.distroseries.distribution.main_archive.owner
diff --git a/lib/lp/soyuz/interfaces/distroarchseries.py b/lib/lp/soyuz/interfaces/distroarchseries.py
index d287840..4f70996 100644
--- a/lib/lp/soyuz/interfaces/distroarchseries.py
+++ b/lib/lp/soyuz/interfaces/distroarchseries.py
@@ -214,6 +214,14 @@ class IDistroArchSeriesPublic(IHasBuildRecords, IHasOwner):
214 tarball".214 tarball".
215 """215 """
216216
217 @operation_parameters(
218 pocket=Choice(vocabulary=PackagePublishingPocket, required=True),
219 image_type=Choice(vocabulary=BuildBaseImageType, required=True))
220 @export_read_operation()
221 @operation_for_version("devel")
222 def getChrootHash(pocket, image_type):
223 """Return the sha1sum of the current chroot for the given pocket."""
224
217 def addOrUpdateChroot(chroot, pocket=None, image_type=None):225 def addOrUpdateChroot(chroot, pocket=None, image_type=None):
218 """Return the just added or modified PocketChroot.226 """Return the just added or modified PocketChroot.
219227
diff --git a/lib/lp/soyuz/model/distroarchseries.py b/lib/lp/soyuz/model/distroarchseries.py
index aedbe7c..ea8d5ee 100644
--- a/lib/lp/soyuz/model/distroarchseries.py
+++ b/lib/lp/soyuz/model/distroarchseries.py
@@ -175,6 +175,13 @@ class DistroArchSeries(SQLBase):
175 return None175 return None
176 return chroot.http_url176 return chroot.http_url
177177
178 def getChrootHash(self, pocket, image_type):
179 """See `IDistroArchSeries`."""
180 chroot = self.getChroot(pocket=pocket, image_type=image_type)
181 if chroot is None:
182 return None
183 return {"sha256": chroot.content.sha256}
184
178 @property185 @property
179 def chroot_url(self):186 def chroot_url(self):
180 """See `IDistroArchSeries`."""187 """See `IDistroArchSeries`."""

Subscribers

People subscribed via source and target branches

to status/vote changes: