← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:diskpool-add-archive into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:diskpool-add-archive into launchpad:master.

Commit message:
Add Archive reference to DiskPool

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

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

In order to publish different package types, we need to know the repository format of the archive, and for that it's useful for the disk pool to have a reference to the archive.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:diskpool-add-archive into launchpad:master.
diff --git a/lib/lp/archivepublisher/artifactory.py b/lib/lp/archivepublisher/artifactory.py
index d348395..2873855 100644
--- a/lib/lp/archivepublisher/artifactory.py
+++ b/lib/lp/archivepublisher/artifactory.py
@@ -28,6 +28,7 @@ from lp.archivepublisher.diskpool import (
 from lp.services.config import config
 from lp.services.librarian.utils import copy_and_close
 from lp.soyuz.enums import ArchiveRepositoryFormat
+from lp.soyuz.interfaces.archive import IArchive
 from lp.soyuz.interfaces.files import (
     IBinaryPackageFile,
     IPackageReleaseFile,
@@ -42,8 +43,8 @@ from lp.soyuz.interfaces.publishing import (
 
 class ArtifactoryPoolEntry:
 
-    def __init__(self, rootpath: ArtifactoryPath, source: str, filename: str,
-                 logger: logging.Logger) -> None:
+    def __init__(self, archive: IArchive, rootpath: ArtifactoryPath,
+                 source: str, filename: str, logger: logging.Logger) -> None:
         self.rootpath = rootpath
         self.source = source
         self.filename = filename
@@ -224,7 +225,9 @@ class ArtifactoryPool:
 
     results = FileAddActionEnum
 
-    def __init__(self, rootpath, logger: logging.Logger) -> None:
+    def __init__(self, archive: IArchive, rootpath,
+                 logger: logging.Logger) -> None:
+        self.archive = archive
         if not isinstance(rootpath, ArtifactoryPath):
             rootpath = ArtifactoryPath(rootpath)
         rootpath.session = self._makeSession()
@@ -259,7 +262,7 @@ class ArtifactoryPool:
     def _getEntry(self, sourcename, file) -> ArtifactoryPoolEntry:
         """See `DiskPool._getEntry`."""
         return ArtifactoryPoolEntry(
-            self.rootpath, sourcename, file, self.logger)
+            self.archive, self.rootpath, sourcename, file, self.logger)
 
     def pathFor(self, comp: str, source: str,
                 file: Optional[str] = None) -> Path:
diff --git a/lib/lp/archivepublisher/config.py b/lib/lp/archivepublisher/config.py
index c5f9b44..55603dc 100644
--- a/lib/lp/archivepublisher/config.py
+++ b/lib/lp/archivepublisher/config.py
@@ -155,8 +155,8 @@ class Config:
             # Artifactory publishing doesn't need a temporary directory on
             # the same filesystem as the pool, since the pool is remote
             # anyway.
-            lambda rootpath, temppath, logger: ArtifactoryPool(
-                rootpath, logger)),
+            lambda archive, rootpath, temppath, logger: ArtifactoryPool(
+                archive, rootpath, logger)),
         }
 
     def __init__(self, archive):
@@ -201,7 +201,7 @@ class Config:
         if pool_root is None:
             pool_root = self.poolroot
         dp_factory = self.disk_pool_factory[self.archive.publishing_method]
-        dp = dp_factory(pool_root, self.temproot, dp_log)
+        dp = dp_factory(self.archive, pool_root, self.temproot, dp_log)
         # Set the diskpool's log level to INFO to suppress debug output.
         dp_log.setLevel(logging.INFO)
         return dp
diff --git a/lib/lp/archivepublisher/diskpool.py b/lib/lp/archivepublisher/diskpool.py
index 3f59826..620c728 100644
--- a/lib/lp/archivepublisher/diskpool.py
+++ b/lib/lp/archivepublisher/diskpool.py
@@ -25,6 +25,7 @@ from lp.services.librarian.utils import (
     sha1_from_path,
     )
 from lp.services.propertycache import cachedproperty
+from lp.soyuz.interfaces.archive import IArchive
 from lp.soyuz.interfaces.files import IPackageReleaseFile
 from lp.soyuz.interfaces.publishing import (
     MissingSymlinkInPool,
@@ -137,8 +138,9 @@ class DiskPoolEntry:
     Remaining files in the 'temppath' indicated installation failures and
     require manual removal after further investigation.
     """
-    def __init__(self, rootpath: Path, temppath: Path, source: str,
-                 filename: str, logger: logging.Logger) -> None:
+    def __init__(self, archive: IArchive, rootpath: Path, temppath: Path,
+                 source: str, filename: str, logger: logging.Logger) -> None:
+        self.archive = archive
         self.rootpath = rootpath
         self.temppath = temppath
         self.source = source
@@ -388,7 +390,9 @@ class DiskPool:
     """
     results = FileAddActionEnum
 
-    def __init__(self, rootpath, temppath, logger: logging.Logger) -> None:
+    def __init__(self, archive: IArchive, rootpath, temppath,
+                 logger: logging.Logger) -> None:
+        self.archive = archive
         self.rootpath = Path(rootpath)
         self.temppath = Path(temppath) if temppath is not None else None
         self.entries = {}
@@ -397,7 +401,8 @@ class DiskPool:
     def _getEntry(self, sourcename: str, file: str) -> DiskPoolEntry:
         """Return a new DiskPoolEntry for the given sourcename and file."""
         return DiskPoolEntry(
-            self.rootpath, self.temppath, sourcename, file, self.logger)
+            self.archive, self.rootpath, self.temppath, sourcename,
+            file, self.logger)
 
     def pathFor(self, comp: str, source: str,
                 file: Optional[str] = None) -> Path:
diff --git a/lib/lp/archivepublisher/tests/deathrow.txt b/lib/lp/archivepublisher/tests/deathrow.txt
index c46474d..92b0752 100644
--- a/lib/lp/archivepublisher/tests/deathrow.txt
+++ b/lib/lp/archivepublisher/tests/deathrow.txt
@@ -20,7 +20,8 @@ The no-operation use case, reflects the sampledata status.
     >>> from lp.archivepublisher.deathrow import DeathRow
     >>> from lp.archivepublisher.diskpool import DiskPool
 
-    >>> disk_pool = DiskPool(pool_path, temp_path, FakeLogger())
+    >>> disk_pool = DiskPool(
+    ...     ubuntu.main_archive, pool_path, temp_path, FakeLogger())
     >>> death_row = DeathRow(ubuntu.main_archive, disk_pool, FakeLogger())
     >>> death_row.reap(dry_run=True)
     DEBUG 0 Sources
@@ -196,7 +197,8 @@ Group the test publications according to their purpose:
 Publish files on disk and build a list of all created file paths
 
     >>> from lp.services.log.logger import BufferLogger
-    >>> quiet_disk_pool = DiskPool(pool_path, temp_path, BufferLogger())
+    >>> quiet_disk_pool = DiskPool(
+    ...     ubuntu.main_archive, pool_path, temp_path, BufferLogger())
 
     >>> unique_file_paths = set()
 
@@ -238,7 +240,8 @@ the temporary repository.
 
 Run DeathRow against the current 'removable' context.
 
-    >>> disk_pool = DiskPool(pool_path, temp_path, FakeLogger())
+    >>> disk_pool = DiskPool(
+    ...     ubuntu.main_archive, pool_path, temp_path, FakeLogger())
     >>> death_row = DeathRow(ubuntu.main_archive, disk_pool, FakeLogger())
     >>> death_row.reap()
     DEBUG 4 Sources
@@ -334,7 +337,8 @@ publications we have to remove any 'live' publications.
 
 Now DeathRow considers 'stuck-bin' publications.
 
-    >>> disk_pool = DiskPool(pool_path, temp_path, FakeLogger())
+    >>> disk_pool = DiskPool(
+    ...     ubuntu.main_archive, pool_path, temp_path, FakeLogger())
     >>> death_row = DeathRow(ubuntu.main_archive, disk_pool, FakeLogger())
     >>> death_row.reap()
     DEBUG 0 Sources
@@ -358,7 +362,8 @@ from the repository.
 That done, the publication and its files are free to be removed in a
 single pass.
 
-    >>> disk_pool = DiskPool(pool_path, temp_path, FakeLogger())
+    >>> disk_pool = DiskPool(
+    ...     ubuntu.main_archive, pool_path, temp_path, FakeLogger())
     >>> death_row = DeathRow(ubuntu.main_archive, disk_pool, FakeLogger())
     >>> death_row.reap()
     DEBUG 0 Sources
diff --git a/lib/lp/archivepublisher/tests/test_artifactory.py b/lib/lp/archivepublisher/tests/test_artifactory.py
index 31bfbb1..49f7ace 100644
--- a/lib/lp/archivepublisher/tests/test_artifactory.py
+++ b/lib/lp/archivepublisher/tests/test_artifactory.py
@@ -13,6 +13,7 @@ from lp.archivepublisher.tests.artifactory_fixture import (
     FakeArtifactoryFixture,
     )
 from lp.archivepublisher.tests.test_pool import (
+    FakeArchive,
     FakeReleaseType,
     PoolTestingFile,
     )
@@ -76,7 +77,7 @@ class TestArtifactoryPool(TestCase):
         self.artifactory = self.useFixture(
             FakeArtifactoryFixture(self.base_url, self.repository_name))
         root_url = "%s/%s/pool" % (self.base_url, self.repository_name)
-        self.pool = ArtifactoryPool(root_url, BufferLogger())
+        self.pool = ArtifactoryPool(FakeArchive(), root_url, BufferLogger())
 
     def test_addFile(self):
         foo = ArtifactoryPoolTestingFile(
@@ -187,15 +188,16 @@ class TestArtifactoryPoolFromLibrarian(TestCaseWithFactory):
         self.artifactory = self.useFixture(
             FakeArtifactoryFixture(self.base_url, self.repository_name))
         root_url = "%s/%s/pool" % (self.base_url, self.repository_name)
-        self.pool = ArtifactoryPool(root_url, BufferLogger())
+        self.archive = self.factory.makeArchive(purpose=ArchivePurpose.PPA)
+        self.pool = ArtifactoryPool(self.archive, root_url, BufferLogger())
 
     def test_updateProperties_debian_source(self):
-        archive = self.factory.makeArchive(purpose=ArchivePurpose.PPA)
         dses = [
-            self.factory.makeDistroSeries(distribution=archive.distribution)
+            self.factory.makeDistroSeries(
+                distribution=self.archive.distribution)
             for _ in range(2)]
         spph = self.factory.makeSourcePackagePublishingHistory(
-            archive=archive, distroseries=dses[0],
+            archive=self.archive, distroseries=dses[0],
             pocket=PackagePublishingPocket.RELEASE, component="main",
             sourcepackagename="foo")
         spr = spph.sourcepackagerelease
@@ -206,7 +208,7 @@ class TestArtifactoryPoolFromLibrarian(TestCaseWithFactory):
             filetype=SourcePackageFileType.DSC)
         spphs = [spph]
         spphs.append(spph.copyTo(
-            dses[1], PackagePublishingPocket.RELEASE, archive))
+            dses[1], PackagePublishingPocket.RELEASE, self.archive))
         transaction.commit()
         self.pool.addFile(None, spr.name, sprf.libraryfile.filename, sprf)
         path = self.pool.rootpath / "f" / "foo" / "foo_1.0.dsc"
@@ -229,9 +231,9 @@ class TestArtifactoryPoolFromLibrarian(TestCaseWithFactory):
             path.properties)
 
     def test_updateProperties_debian_binary_multiple_series(self):
-        archive = self.factory.makeArchive(purpose=ArchivePurpose.PPA)
         dses = [
-            self.factory.makeDistroSeries(distribution=archive.distribution)
+            self.factory.makeDistroSeries(
+                distribution=self.archive.distribution)
             for _ in range(2)]
         processor = self.factory.makeProcessor()
         dases = [
@@ -239,7 +241,7 @@ class TestArtifactoryPoolFromLibrarian(TestCaseWithFactory):
                 distroseries=ds, architecturetag=processor.name)
             for ds in dses]
         bpph = self.factory.makeBinaryPackagePublishingHistory(
-            archive=archive, distroarchseries=dases[0],
+            archive=self.archive, distroarchseries=dases[0],
             pocket=PackagePublishingPocket.RELEASE, component="main",
             sourcepackagename="foo", binarypackagename="foo",
             architecturespecific=True)
@@ -251,7 +253,7 @@ class TestArtifactoryPoolFromLibrarian(TestCaseWithFactory):
             filetype=BinaryPackageFileType.DEB)
         bpphs = [bpph]
         bpphs.append(bpph.copyTo(
-            dses[1], PackagePublishingPocket.RELEASE, archive)[0])
+            dses[1], PackagePublishingPocket.RELEASE, self.archive)[0])
         transaction.commit()
         self.pool.addFile(
             None, bpr.sourcepackagename, bpf.libraryfile.filename, bpf)
@@ -279,13 +281,13 @@ class TestArtifactoryPoolFromLibrarian(TestCaseWithFactory):
             path.properties)
 
     def test_updateProperties_debian_binary_multiple_architectures(self):
-        archive = self.factory.makeArchive(purpose=ArchivePurpose.PPA)
-        ds = self.factory.makeDistroSeries(distribution=archive.distribution)
+        ds = self.factory.makeDistroSeries(
+            distribution=self.archive.distribution)
         dases = [
             self.factory.makeDistroArchSeries(distroseries=ds)
             for _ in range(2)]
         bpb = self.factory.makeBinaryPackageBuild(
-            archive=archive, distroarchseries=dases[0],
+            archive=self.archive, distroarchseries=dases[0],
             pocket=PackagePublishingPocket.RELEASE, sourcepackagename="foo")
         bpr = self.factory.makeBinaryPackageRelease(
             binarypackagename="foo", build=bpb, component="main",
@@ -296,7 +298,7 @@ class TestArtifactoryPoolFromLibrarian(TestCaseWithFactory):
                 filename="foo_1.0_all.deb"),
             filetype=BinaryPackageFileType.DEB)
         bpphs = getUtility(IPublishingSet).publishBinaries(
-            archive, ds, PackagePublishingPocket.RELEASE,
+            self.archive, ds, PackagePublishingPocket.RELEASE,
             {bpr: (bpr.component, bpr.section, bpr.priority, None)})
         transaction.commit()
         self.pool.addFile(
@@ -326,11 +328,11 @@ class TestArtifactoryPoolFromLibrarian(TestCaseWithFactory):
     def test_updateProperties_preserves_externally_set_properties(self):
         # Artifactory sets some properties by itself as part of scanning
         # packages.  We leave those untouched.
-        archive = self.factory.makeArchive(purpose=ArchivePurpose.PPA)
-        ds = self.factory.makeDistroSeries(distribution=archive.distribution)
+        ds = self.factory.makeDistroSeries(
+            distribution=self.archive.distribution)
         das = self.factory.makeDistroArchSeries(distroseries=ds)
         bpb = self.factory.makeBinaryPackageBuild(
-            archive=archive, distroarchseries=das,
+            archive=self.archive, distroarchseries=das,
             pocket=PackagePublishingPocket.RELEASE, sourcepackagename="foo")
         bpr = self.factory.makeBinaryPackageRelease(
             binarypackagename="foo", build=bpb, component="main",
@@ -341,7 +343,7 @@ class TestArtifactoryPoolFromLibrarian(TestCaseWithFactory):
                 filename="foo_1.0_all.deb"),
             filetype=BinaryPackageFileType.DEB)
         bpphs = getUtility(IPublishingSet).publishBinaries(
-            archive, ds, PackagePublishingPocket.RELEASE,
+            self.archive, ds, PackagePublishingPocket.RELEASE,
             {bpr: (bpr.component, bpr.section, bpr.priority, None)})
         transaction.commit()
         self.pool.addFile(
diff --git a/lib/lp/archivepublisher/tests/test_deathrow.py b/lib/lp/archivepublisher/tests/test_deathrow.py
index 81bf3dd..10efb6f 100644
--- a/lib/lp/archivepublisher/tests/test_deathrow.py
+++ b/lib/lp/archivepublisher/tests/test_deathrow.py
@@ -45,7 +45,7 @@ class TestDeathRow(TestCase):
         self.addCleanup(clean_pool, pool_path, temp_path)
 
         logger = BufferLogger()
-        diskpool = DiskPool(pool_path, temp_path, logger)
+        diskpool = DiskPool(archive, pool_path, temp_path, logger)
         return DeathRow(archive, diskpool, logger)
 
     def getDiskPoolPath(self, pub, pub_file, diskpool):
diff --git a/lib/lp/archivepublisher/tests/test_ftparchive.py b/lib/lp/archivepublisher/tests/test_ftparchive.py
index efe3e63..9ea5778 100755
--- a/lib/lp/archivepublisher/tests/test_ftparchive.py
+++ b/lib/lp/archivepublisher/tests/test_ftparchive.py
@@ -103,7 +103,8 @@ class TestFTPArchive(TestCaseWithFactory):
         self._listdir = self._config.overrideroot
         self._tempdir = self._config.temproot
         self._logger = BufferLogger()
-        self._dp = DiskPool(self._pooldir, self._tempdir, self._logger)
+        self._dp = DiskPool(
+            self._archive, self._pooldir, self._tempdir, self._logger)
         self._publisher = SamplePublisher(self._archive)
 
     def tearDown(self):
diff --git a/lib/lp/archivepublisher/tests/test_pool.py b/lib/lp/archivepublisher/tests/test_pool.py
index 6863bbc..4beeea5 100644
--- a/lib/lp/archivepublisher/tests/test_pool.py
+++ b/lib/lp/archivepublisher/tests/test_pool.py
@@ -23,6 +23,7 @@ from lp.archivepublisher.diskpool import (
     poolify,
     )
 from lp.services.log.logger import BufferLogger
+from lp.soyuz.enums import ArchiveRepositoryFormat
 from lp.soyuz.interfaces.files import (
     IBinaryPackageFile,
     IPackageReleaseFile,
@@ -30,6 +31,12 @@ from lp.soyuz.interfaces.files import (
     )
 
 
+class FakeArchive:
+
+    def __init__(self, repository_format=ArchiveRepositoryFormat.DEBIAN):
+        self.repository_format = repository_format
+
+
 class FakeLibraryFileContent:
 
     def __init__(self, contents):
@@ -124,7 +131,8 @@ class TestPool(unittest.TestCase):
     def setUp(self):
         self.pool_path = mkdtemp()
         self.temp_path = mkdtemp()
-        self.pool = DiskPool(self.pool_path, self.temp_path, BufferLogger())
+        self.pool = DiskPool(
+            FakeArchive(), self.pool_path, self.temp_path, BufferLogger())
 
     def tearDown(self):
         shutil.rmtree(self.pool_path)
diff --git a/lib/lp/archivepublisher/tests/test_publisher.py b/lib/lp/archivepublisher/tests/test_publisher.py
index af62d58..f247242 100644
--- a/lib/lp/archivepublisher/tests/test_publisher.py
+++ b/lib/lp/archivepublisher/tests/test_publisher.py
@@ -921,7 +921,7 @@ class TestPublisher(TestPublisherBase):
         pub_config = getPubConfig(archive)
         pub_config.setupArchiveDirs()
         disk_pool = DiskPool(
-            pub_config.poolroot, pub_config.temproot, self.logger)
+            archive, pub_config.poolroot, pub_config.temproot, self.logger)
         publisher = Publisher(
             self.logger, pub_config, disk_pool, archive)
         self.getPubSource(archive=archive, filecontent=b"I am partner")
@@ -963,7 +963,7 @@ class TestPublisher(TestPublisherBase):
         pub_config = getPubConfig(archive)
         pub_config.setupArchiveDirs()
         disk_pool = DiskPool(
-            pub_config.poolroot, pub_config.temproot, self.logger)
+            archive, pub_config.poolroot, pub_config.temproot, self.logger)
         publisher = Publisher(self.logger, pub_config, disk_pool, archive)
         self.getPubSource(
             archive=archive, filecontent=b"I am partner",
@@ -1125,7 +1125,8 @@ class TestPublisher(TestPublisherBase):
 
         test_pool_dir = tempfile.mkdtemp()
         test_temp_dir = tempfile.mkdtemp()
-        test_disk_pool = DiskPool(test_pool_dir, test_temp_dir, self.logger)
+        test_disk_pool = DiskPool(
+            test_archive, test_pool_dir, test_temp_dir, self.logger)
 
         publisher = Publisher(
             self.logger, self.config, test_disk_pool,
diff --git a/lib/lp/soyuz/tests/test_publishing.py b/lib/lp/soyuz/tests/test_publishing.py
index 7d91f43..51fa9f7 100644
--- a/lib/lp/soyuz/tests/test_publishing.py
+++ b/lib/lp/soyuz/tests/test_publishing.py
@@ -626,7 +626,8 @@ class TestNativePublishingBase(TestCaseWithFactory, SoyuzTestPublisher):
         self.pool_dir = self.config.poolroot
         self.temp_dir = self.config.temproot
         self.logger = DevNullLogger()
-        self.disk_pool = DiskPool(self.pool_dir, self.temp_dir, self.logger)
+        self.disk_pool = self.config.getDiskPool(self.logger)
+        self.disk_pool.logger = self.logger
 
     def tearDown(self):
         """Tear down blows the pool dirs away."""
@@ -858,7 +859,8 @@ class TestNativePublishing(TestNativePublishingBase):
         cprov = getUtility(IPersonSet).getByName('cprov')
         test_pool_dir = tempfile.mkdtemp()
         test_temp_dir = tempfile.mkdtemp()
-        test_disk_pool = DiskPool(test_pool_dir, test_temp_dir, self.logger)
+        test_disk_pool = DiskPool(
+            cprov.archive, test_pool_dir, test_temp_dir, self.logger)
 
         pub_source = self.getPubSource(
             sourcename="foo", filecontent=b'Am I a PPA Record ?',