← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:publish-single-archive-option into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:publish-single-archive-option into launchpad:master.

Commit message:
publish-distro: Add an --archive option

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

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

This fixes an annoyance when performing QA: `publish-distro` already had `--ppas` options and similar to tell it to run over all archives of a particular kind, but previously the only way to get it to run over a single archive was to hack the `is_ppa_public` etc. functions in place.  This option should make publisher QA a little more convenient in future.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:publish-single-archive-option into launchpad:master.
diff --git a/lib/lp/archivepublisher/scripts/publishdistro.py b/lib/lp/archivepublisher/scripts/publishdistro.py
index 85511be..6c93a6e 100644
--- a/lib/lp/archivepublisher/scripts/publishdistro.py
+++ b/lib/lp/archivepublisher/scripts/publishdistro.py
@@ -202,6 +202,13 @@ class PublishDistro(PublisherScript):
             help="Only run over the copy archives.",
         )
 
+        self.parser.add_option(
+            "--archive",
+            dest="archive",
+            metavar="REFERENCE",
+            help="Only run over the archive identified by this reference.",
+        )
+
     def isCareful(self, option):
         """Is the given "carefulness" option enabled?
 
@@ -243,6 +250,7 @@ class PublishDistro(PublisherScript):
             self.options.ppa,
             self.options.private_ppa,
             self.options.copy_archive,
+            self.options.archive,
         ]
         return len(list(filter(None, exclusive_options)))
 
@@ -271,7 +279,7 @@ class PublishDistro(PublisherScript):
         if self.countExclusiveOptions() > 1:
             raise OptionValueError(
                 "Can only specify one of partner, ppa, private-ppa, "
-                "copy-archive."
+                "copy-archive, archive."
             )
 
         if self.options.all_derived and self.options.distribution is not None:
@@ -342,7 +350,15 @@ class PublishDistro(PublisherScript):
 
     def getTargetArchives(self, distribution):
         """Find the archive(s) selected by the script's options."""
-        if self.options.partner:
+        if self.options.archive:
+            archive = getUtility(IArchiveSet).getByReference(
+                self.options.archive
+            )
+            if archive.distribution == distribution:
+                return [archive]
+            else:
+                return []
+        elif self.options.partner:
             return [distribution.getArchiveByComponent("partner")]
         elif self.options.ppa:
             return filter(is_ppa_public, self.getPPAs(distribution))
diff --git a/lib/lp/archivepublisher/tests/test_publishdistro.py b/lib/lp/archivepublisher/tests/test_publishdistro.py
index 96ade8e..f99ee6e 100644
--- a/lib/lp/archivepublisher/tests/test_publishdistro.py
+++ b/lib/lp/archivepublisher/tests/test_publishdistro.py
@@ -445,6 +445,72 @@ class TestPublishDistro(TestNativePublishingBase):
         pool_path = os.path.join(repo_path, "pool/main/b/baz/baz_666.dsc")
         self.assertExists(pool_path)
 
+    @defer.inlineCallbacks
+    def testForSingleArchive(self):
+        """Run publish-distro over a single archive specified by reference."""
+        ubuntutest = getUtility(IDistributionSet)["ubuntutest"]
+        name16 = getUtility(IPersonSet).getByName("name16")
+        archives = [
+            getUtility(IArchiveSet).new(
+                purpose=ArchivePurpose.PPA,
+                owner=name16,
+                name=name,
+                distribution=ubuntutest,
+            )
+            for name in (
+                self.factory.getUniqueUnicode(),
+                self.factory.getUniqueUnicode(),
+            )
+        ]
+        archive_references = [archive.reference for archive in archives]
+        pub_source_ids = [
+            self.getPubSource(archive=archive).id for archive in archives
+        ]
+
+        self.setUpRequireSigningKeys()
+        yield self.useFixture(InProcessKeyServerFixture()).start()
+        key_path = os.path.join(gpgkeysdir, "ppa-sample@xxxxxxxxxxxxxxxxx")
+        for archive in archives:
+            yield IArchiveGPGSigningKey(archive).setSigningKey(
+                key_path, async_keyserver=True
+            )
+
+        self.layer.txn.commit()
+
+        self.assertEqual(
+            [PackagePublishingStatus.PENDING, PackagePublishingStatus.PENDING],
+            [
+                self.loadPubSource(pub_source_id).status
+                for pub_source_id in pub_source_ids
+            ],
+        )
+
+        self.runPublishDistro(["--archive", archive_references[0]])
+
+        self.assertEqual(
+            [
+                PackagePublishingStatus.PUBLISHED,
+                PackagePublishingStatus.PENDING,
+            ],
+            [
+                self.loadPubSource(pub_source_id).status
+                for pub_source_id in pub_source_ids
+            ],
+        )
+
+        self.runPublishDistro(["--archive", archive_references[1]])
+
+        self.assertEqual(
+            [
+                PackagePublishingStatus.PUBLISHED,
+                PackagePublishingStatus.PUBLISHED,
+            ],
+            [
+                self.loadPubSource(pub_source_id).status
+                for pub_source_id in pub_source_ids
+            ],
+        )
+
     def testPublishToArtifactory(self):
         """Publishing to Artifactory doesn't require generated signing keys."""
         self.setUpRequireSigningKeys()