Merge ~cjwatson/launchpad:refactor-get-disk-pool into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: 21a25e87277ab4fa9b1efa89c86bf7e741623e9d
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:refactor-get-disk-pool
Merge into: launchpad:master
Diff against target: 176 lines (+43/-32)
4 files modified
lib/lp/archivepublisher/config.py (+22/-0)
lib/lp/archivepublisher/deathrow.py (+3/-14)
lib/lp/archivepublisher/publishing.py (+1/-18)
lib/lp/archivepublisher/tests/test_config.py (+17/-0)
Reviewer Review Type Date Requested Status
Ioana Lasc (community) Approve
Review via email: mp+416113@code.launchpad.net

Commit message

Push DiskPool construction down to Config.getDiskPool

Description of the change

This eliminates some largely-duplicated code, and will potentially also make it a little easier to substitute alternative implementations of `DiskPool` for some archives.

To post a comment you must log in.
Revision history for this message
Ioana Lasc (ilasc) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/archivepublisher/config.py b/lib/lp/archivepublisher/config.py
2index de45925..92c3917 100644
3--- a/lib/lp/archivepublisher/config.py
4+++ b/lib/lp/archivepublisher/config.py
5@@ -6,10 +6,12 @@
6 # to managing the archive publisher's configuration as stored in the
7 # distribution and distroseries tables
8
9+import logging
10 import os
11
12 from zope.component import getUtility
13
14+from lp.archivepublisher.diskpool import DiskPool
15 from lp.archivepublisher.interfaces.publisherconfig import IPublisherConfigSet
16 from lp.registry.interfaces.distribution import IDistributionSet
17 from lp.services.config import config
18@@ -150,3 +152,23 @@ class Config:
19 continue
20 if not os.path.exists(directory):
21 os.makedirs(directory, 0o755)
22+
23+ def getDiskPool(self, log, pool_root_override=None):
24+ """Return a DiskPool instance for this publisher configuration.
25+
26+ It ensures the given archive location matches the minimal structure
27+ required.
28+
29+ :param log: A logger.
30+ :param pool_root_override: Use this pool root for the archive
31+ instead of the one provided by the publishing configuration.
32+ """
33+ log.debug("Preparing on-disk pool representation.")
34+ dp_log = logging.getLogger("DiskPool")
35+ pool_root = pool_root_override
36+ if pool_root is None:
37+ pool_root = self.poolroot
38+ dp = DiskPool(pool_root, self.temproot, dp_log)
39+ # Set the diskpool's log level to INFO to suppress debug output.
40+ dp_log.setLevel(logging.INFO)
41+ return dp
42diff --git a/lib/lp/archivepublisher/deathrow.py b/lib/lp/archivepublisher/deathrow.py
43index 87722a3..b540c80 100644
44--- a/lib/lp/archivepublisher/deathrow.py
45+++ b/lib/lp/archivepublisher/deathrow.py
46@@ -6,7 +6,6 @@ Processes removals of packages that are scheduled for deletion.
47 """
48
49 import datetime
50-import logging
51 import os
52
53 import pytz
54@@ -19,7 +18,6 @@ from storm.locals import (
55 )
56
57 from lp.archivepublisher.config import getPubConfig
58-from lp.archivepublisher.diskpool import DiskPool
59 from lp.services.database.constants import UTC_NOW
60 from lp.services.database.interfaces import IStore
61 from lp.services.librarian.model import (
62@@ -57,19 +55,10 @@ def getDeathRow(archive, log, pool_root_override):
63 log.debug("Grab publisher config.")
64 pubconf = getPubConfig(archive)
65
66- if (pool_root_override is not None and
67- archive.purpose == ArchivePurpose.PRIMARY):
68- pool_root = pool_root_override
69- else:
70- pool_root = pubconf.poolroot
71+ if archive.purpose != ArchivePurpose.PRIMARY:
72+ pool_root_override = None
73
74- log.debug("Preparing on-disk pool representation.")
75-
76- diskpool_log = logging.getLogger("DiskPool")
77- # Set the diskpool's log level to INFO to suppress debug output
78- diskpool_log.setLevel(20)
79-
80- dp = DiskPool(pool_root, pubconf.temproot, diskpool_log)
81+ dp = pubconf.getDiskPool(log, pool_root_override=pool_root_override)
82
83 log.debug("Preparing death row.")
84 return DeathRow(archive, dp, log)
85diff --git a/lib/lp/archivepublisher/publishing.py b/lib/lp/archivepublisher/publishing.py
86index a5a0cc4..9204a7a 100644
87--- a/lib/lp/archivepublisher/publishing.py
88+++ b/lib/lp/archivepublisher/publishing.py
89@@ -24,7 +24,6 @@ from itertools import (
90 chain,
91 groupby,
92 )
93-import logging
94 import lzma
95 from operator import attrgetter
96 import os
97@@ -45,7 +44,6 @@ from zope.interface import (
98 from lp.app.interfaces.launchpad import ILaunchpadCelebrities
99 from lp.archivepublisher import HARDCODED_COMPONENT_ORDER
100 from lp.archivepublisher.config import getPubConfig
101-from lp.archivepublisher.diskpool import DiskPool
102 from lp.archivepublisher.domination import Dominator
103 from lp.archivepublisher.indices import (
104 build_binary_stanza_fields,
105@@ -145,21 +143,6 @@ def get_suffixed_indices(path):
106 return {path + suffix for suffix in ('', '.gz', '.bz2', '.xz')}
107
108
109-def _getDiskPool(pubconf, log):
110- """Return a DiskPool instance for a given PubConf.
111-
112- It ensures the given archive location matches the minimal structure
113- required.
114- """
115- log.debug("Preparing on-disk pool representation.")
116- dp = DiskPool(pubconf.poolroot, pubconf.temproot,
117- logging.getLogger("DiskPool"))
118- # Set the diskpool's log level to INFO to suppress debug output
119- dp.logger.setLevel(logging.INFO)
120-
121- return dp
122-
123-
124 def getPublisher(archive, allowed_suites, log, distsroot=None):
125 """Return an initialized Publisher instance for the given context.
126
127@@ -174,7 +157,7 @@ def getPublisher(archive, allowed_suites, log, distsroot=None):
128 % archive.owner.name)
129 pubconf = getPubConfig(archive)
130
131- disk_pool = _getDiskPool(pubconf, log)
132+ disk_pool = pubconf.getDiskPool(log)
133
134 if distsroot is not None:
135 log.debug("Overriding dists root with %s." % distsroot)
136diff --git a/lib/lp/archivepublisher/tests/test_config.py b/lib/lp/archivepublisher/tests/test_config.py
137index 37a57dc..ec11bfa 100644
138--- a/lib/lp/archivepublisher/tests/test_config.py
139+++ b/lib/lp/archivepublisher/tests/test_config.py
140@@ -6,6 +6,7 @@
141 Publisher configuration provides archive-dependent filesystem paths.
142 """
143
144+import logging
145 import os
146
147 from zope.component import getUtility
148@@ -13,6 +14,7 @@ from zope.component import getUtility
149 from lp.archivepublisher.config import getPubConfig
150 from lp.registry.interfaces.distribution import IDistributionSet
151 from lp.services.config import config
152+from lp.services.log.logger import BufferLogger
153 from lp.soyuz.enums import ArchivePurpose
154 from lp.soyuz.interfaces.archive import IArchiveSet
155 from lp.testing import TestCaseWithFactory
156@@ -106,6 +108,21 @@ class TestGetPubConfig(TestCaseWithFactory):
157 self.assertIs(None, copy_config.metaroot)
158 self.assertIs(None, copy_config.stagingroot)
159
160+ def test_getDiskPool(self):
161+ primary_config = getPubConfig(self.ubuntutest.main_archive)
162+ disk_pool = primary_config.getDiskPool(BufferLogger())
163+ self.assertEqual(self.root + "/ubuntutest/pool/", disk_pool.rootpath)
164+ self.assertEqual(self.root + "/ubuntutest-temp/", disk_pool.temppath)
165+ self.assertEqual(logging.INFO, disk_pool.logger.level)
166+
167+ def test_getDiskPool_pool_root_override(self):
168+ primary_config = getPubConfig(self.ubuntutest.main_archive)
169+ disk_pool = primary_config.getDiskPool(
170+ BufferLogger(), pool_root_override="/path/to/pool")
171+ self.assertEqual("/path/to/pool/", disk_pool.rootpath)
172+ self.assertEqual(self.root + "/ubuntutest-temp/", disk_pool.temppath)
173+ self.assertEqual(logging.INFO, disk_pool.logger.level)
174+
175
176 class TestGetPubConfigPPA(TestCaseWithFactory):
177

Subscribers

People subscribed via source and target branches

to status/vote changes: