← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:process-accepted-honour-publish into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:process-accepted-honour-publish into launchpad:master.

Commit message:
process-accepted: Skip archives with the publish flag disabled

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

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

This means that it can be run on copy archives without trying to process millions of queue entries that will never go anywhere useful.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:process-accepted-honour-publish into launchpad:master.
diff --git a/lib/lp/archivepublisher/scripts/processaccepted.py b/lib/lp/archivepublisher/scripts/processaccepted.py
index d5bc192..f61edcd 100644
--- a/lib/lp/archivepublisher/scripts/processaccepted.py
+++ b/lib/lp/archivepublisher/scripts/processaccepted.py
@@ -1,4 +1,4 @@
-# Copyright 2009-2014 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2021 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """Helper functions for the process-accepted.py script."""
@@ -110,6 +110,8 @@ class ProcessAccepted(PublisherScript):
         """
         processed_queue_ids = []
         for archive in self.getTargetArchives(distribution):
+            if not archive.can_be_published:
+                continue
             set_request_started(
                 request_statements=LimitedList(10000),
                 txn=self.txn, enable_timeout=False)
diff --git a/lib/lp/archivepublisher/tests/test_processaccepted.py b/lib/lp/archivepublisher/tests/test_processaccepted.py
index 6b7147f..f945212 100644
--- a/lib/lp/archivepublisher/tests/test_processaccepted.py
+++ b/lib/lp/archivepublisher/tests/test_processaccepted.py
@@ -1,4 +1,4 @@
-# Copyright 2010-2018 Canonical Ltd.  This software is licensed under the
+# Copyright 2010-2021 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """Test process-accepted.py"""
@@ -100,6 +100,7 @@ class TestProcessAccepted(TestCaseWithFactory):
         distroseries = self.factory.makeDistroSeries(distribution=self.distro)
         copy_archive = self.factory.makeArchive(
             distribution=self.distro, purpose=ArchivePurpose.COPY)
+        copy_archive.publish = True
         copy_source = self.createWaitingAcceptancePackage(
             archive=copy_archive, distroseries=distroseries)
         # Also upload some stuff in the main archive.
@@ -108,10 +109,7 @@ class TestProcessAccepted(TestCaseWithFactory):
         # Before accepting, the package should not be published at all.
         published_copy = copy_archive.getPublishedSources(
             name=self.test_package_name)
-        # Using .count() until Storm fixes __nonzero__ on SQLObj result
-        # sets, then we can use bool() which is far more efficient than
-        # counting.
-        self.assertEqual(published_copy.count(), 0)
+        self.assertTrue(published_copy.is_empty())
 
         # Accept the packages.
         script = self.getScript(['--copy-archives'])
@@ -121,7 +119,7 @@ class TestProcessAccepted(TestCaseWithFactory):
         # Packages in main archive should not be accepted and published.
         published_main = self.distro.main_archive.getPublishedSources(
             name=self.test_package_name)
-        self.assertEqual(published_main.count(), 0)
+        self.assertTrue(published_main.is_empty())
 
         # Check the copy archive source was accepted.
         published_copy = copy_archive.getPublishedSources(
@@ -130,6 +128,25 @@ class TestProcessAccepted(TestCaseWithFactory):
             published_copy.status, PackagePublishingStatus.PENDING)
         self.assertEqual(copy_source, published_copy.sourcepackagerelease)
 
+    def test_skips_non_publishing_copy_archives(self):
+        # The script skips copy archives that have the publish flag disabled.
+        distroseries = self.factory.makeDistroSeries(distribution=self.distro)
+        copy_archive = self.factory.makeArchive(
+            distribution=self.distro, purpose=ArchivePurpose.COPY)
+        self.createWaitingAcceptancePackage(
+            archive=copy_archive, distroseries=distroseries)
+        published_copy = copy_archive.getPublishedSources(
+            name=self.test_package_name)
+        self.assertTrue(published_copy.is_empty())
+
+        script = self.getScript(['--copy-archives'])
+        switch_dbuser(self.dbuser)
+        script.main()
+
+        published_copy = copy_archive.getPublishedSources(
+            name=self.test_package_name)
+        self.assertTrue(published_copy.is_empty())
+
     def test_commits_after_each_item(self):
         # Test that the script commits after each item, not just at the end.
         uploads = [