← Back to team overview

launchpad-reviewers team mailing list archive

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

 

Tom Wardill has proposed merging ~twom/launchpad:buildd-sha-export into launchpad:master.

Commit message:
Add retrieval of the SHA1 for a chroot in a DAS

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #1838770 in Launchpad itself: "API to get hash of build base images in production"
  https://bugs.launchpad.net/launchpad/+bug/1838770

For more details, see:
https://code.launchpad.net/~twom/launchpad/+git/launchpad/+merge/391360

We set the chroot for a PocketChroot via the DistroArchSeries, but this is basically write-only without downloading the whole chroot file and recalculating it.
Add an equivalent getChrootSHA alongside getChrootURL that returns the sha1 from the librarian file.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~twom/launchpad:buildd-sha-export into launchpad:master.
diff --git a/lib/lp/soyuz/browser/tests/test_distroarchseries_webservice.py b/lib/lp/soyuz/browser/tests/test_distroarchseries_webservice.py
index 32cd64e..bdc5374 100644
--- a/lib/lp/soyuz/browser/tests/test_distroarchseries_webservice.py
+++ b/lib/lp/soyuz/browser/tests/test_distroarchseries_webservice.py
@@ -120,6 +120,18 @@ class TestDistroArchSeriesWebservice(TestCaseWithFactory):
             data=b'foo\r', sha1sum='95e0c0e09be59e04eb0e312e5daa11a2a830e526')
         self.assertEqual(sha1, das.getChroot().content.sha1)
 
+    def test_getChrootSHA(self):
+        das = self.factory.makeDistroArchSeries()
+        user = das.distroseries.distribution.main_archive.owner
+        expected_file = 'chroot-%s-%s-%s.tar.gz' % (
+            das.distroseries.distribution.name, das.distroseries.name,
+            das.architecturetag)
+        webservice = launchpadlib_for("testing", user)
+        ws_das = ws_object(webservice, das)
+        sha1 = hashlib.sha1('abcxyz').hexdigest()
+        ws_das.setChroot(data=b'abcxyz', sha1sum=sha1)
+        self.assertEqual(sha1, ws_das.getChrootSHA())
+
     def test_setChroot_removeChroot(self):
         das = self.factory.makeDistroArchSeries()
         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..f4c168c 100644
--- a/lib/lp/soyuz/interfaces/distroarchseries.py
+++ b/lib/lp/soyuz/interfaces/distroarchseries.py
@@ -214,6 +214,18 @@ class IDistroArchSeriesPublic(IHasBuildRecords, IHasOwner):
         tarball".
         """
 
+    @operation_parameters(
+        pocket=Choice(vocabulary=PackagePublishingPocket, required=False),
+        image_type=Choice(vocabulary=BuildBaseImageType, required=False))
+    @export_read_operation()
+    @operation_for_version("devel")
+    def getChrootSHA(pocket=None, image_type=None):
+        """Return the sha1sum of the current chroot for the given pocket.
+
+        The pocket defaults to "Release"; the image type defaults to "Chroot
+        tarball".
+        """
+
     def addOrUpdateChroot(chroot, pocket=None, image_type=None):
         """Return the just added or modified PocketChroot.
 
diff --git a/lib/lp/soyuz/model/distroarchseries.py b/lib/lp/soyuz/model/distroarchseries.py
index aedbe7c..08f8cfc 100644
--- a/lib/lp/soyuz/model/distroarchseries.py
+++ b/lib/lp/soyuz/model/distroarchseries.py
@@ -175,6 +175,13 @@ class DistroArchSeries(SQLBase):
             return None
         return chroot.http_url
 
+    def getChrootSHA(self, pocket=None, image_type=None):
+        """See `IDistroArchSeries`."""
+        chroot = self.getChroot(pocket=pocket, image_type=image_type)
+        if chroot is None:
+            return None
+        return chroot.content.sha1
+
     @property
     def chroot_url(self):
         """See `IDistroArchSeries`."""

Follow ups