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
1diff --git a/lib/lp/soyuz/browser/tests/test_distroarchseries_webservice.py b/lib/lp/soyuz/browser/tests/test_distroarchseries_webservice.py
2index 32cd64e..c9e6db4 100644
3--- a/lib/lp/soyuz/browser/tests/test_distroarchseries_webservice.py
4+++ b/lib/lp/soyuz/browser/tests/test_distroarchseries_webservice.py
5@@ -14,6 +14,7 @@ from lazr.restfulclient.errors import (
6 from testtools.matchers import (
7 EndsWith,
8 Equals,
9+ MatchesDict,
10 MatchesStructure,
11 )
12 from zope.security.management import endInteraction
13@@ -120,6 +121,19 @@ class TestDistroArchSeriesWebservice(TestCaseWithFactory):
14 data=b'foo\r', sha1sum='95e0c0e09be59e04eb0e312e5daa11a2a830e526')
15 self.assertEqual(sha1, das.getChroot().content.sha1)
16
17+ def test_getChrootHash(self):
18+ das = self.factory.makeDistroArchSeries()
19+ user = das.distroseries.distribution.main_archive.owner
20+ webservice = launchpadlib_for("testing", user)
21+ ws_das = ws_object(webservice, das)
22+ sha1 = hashlib.sha1('abcxyz').hexdigest()
23+ sha256 = hashlib.sha256('abcxyz').hexdigest()
24+ ws_das.setChroot(data=b'abcxyz', sha1sum=sha1)
25+ self.assertThat(
26+ das.getChrootHash(
27+ PackagePublishingPocket.RELEASE, BuildBaseImageType.CHROOT),
28+ MatchesDict({'sha256': Equals(sha256)}))
29+
30 def test_setChroot_removeChroot(self):
31 das = self.factory.makeDistroArchSeries()
32 user = das.distroseries.distribution.main_archive.owner
33diff --git a/lib/lp/soyuz/interfaces/distroarchseries.py b/lib/lp/soyuz/interfaces/distroarchseries.py
34index d287840..4f70996 100644
35--- a/lib/lp/soyuz/interfaces/distroarchseries.py
36+++ b/lib/lp/soyuz/interfaces/distroarchseries.py
37@@ -214,6 +214,14 @@ class IDistroArchSeriesPublic(IHasBuildRecords, IHasOwner):
38 tarball".
39 """
40
41+ @operation_parameters(
42+ pocket=Choice(vocabulary=PackagePublishingPocket, required=True),
43+ image_type=Choice(vocabulary=BuildBaseImageType, required=True))
44+ @export_read_operation()
45+ @operation_for_version("devel")
46+ def getChrootHash(pocket, image_type):
47+ """Return the sha1sum of the current chroot for the given pocket."""
48+
49 def addOrUpdateChroot(chroot, pocket=None, image_type=None):
50 """Return the just added or modified PocketChroot.
51
52diff --git a/lib/lp/soyuz/model/distroarchseries.py b/lib/lp/soyuz/model/distroarchseries.py
53index aedbe7c..ea8d5ee 100644
54--- a/lib/lp/soyuz/model/distroarchseries.py
55+++ b/lib/lp/soyuz/model/distroarchseries.py
56@@ -175,6 +175,13 @@ class DistroArchSeries(SQLBase):
57 return None
58 return chroot.http_url
59
60+ def getChrootHash(self, pocket, image_type):
61+ """See `IDistroArchSeries`."""
62+ chroot = self.getChroot(pocket=pocket, image_type=image_type)
63+ if chroot is None:
64+ return None
65+ return {"sha256": chroot.content.sha256}
66+
67 @property
68 def chroot_url(self):
69 """See `IDistroArchSeries`."""

Subscribers

People subscribed via source and target branches

to status/vote changes: