Merge lp:~lifeless/launchpad/bug-663828 into lp:launchpad

Proposed by Robert Collins
Status: Merged
Approved by: Edwin Grubbs
Approved revision: no longer in the source branch.
Merged at revision: 11772
Proposed branch: lp:~lifeless/launchpad/bug-663828
Merge into: lp:launchpad
Diff against target: 331 lines (+60/-41)
12 files modified
daemons/buildd-manager.tac (+2/-2)
daemons/buildd-slave.tac (+2/-2)
daemons/distributionmirror_http_server.tac (+2/-2)
daemons/librarian.tac (+2/-2)
daemons/poppy-sftp.tac (+2/-2)
daemons/sftp.tac (+2/-2)
daemons/zeca.tac (+2/-2)
lib/canonical/buildd/debian/rules (+2/-2)
lib/canonical/database/ftests/portforward-to-postgres.tac (+1/-1)
lib/canonical/launchpad/daemons/readyservice.py (+29/-0)
lib/canonical/launchpad/daemons/tachandler.py (+12/-22)
lib/canonical/launchpad/daemons/tests/cannotlisten.tac (+2/-2)
To merge this branch: bzr merge lp:~lifeless/launchpad/bug-663828
Reviewer Review Type Date Requested Status
Edwin Grubbs (community) code Approve
Review via email: mp+38967@code.launchpad.net

Commit message

Split ReadyService into its own file for easier maintenance of TacTestSetup.

Description of the change

tachandler.py serves two masters: testing and production use; but TacTestSetup and ReadyService are only slightly related (they both want LOG_MAGIC); this moves ReadyService to its own file which makes it easier to maintain TacTestSetup, and fixes the (currently broken) buildd-slave packages by not needing a third party module I had depended on.

To post a comment you must log in.
Revision history for this message
Edwin Grubbs (edwin-grubbs) wrote :

This branch looks good.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'daemons/buildd-manager.tac'
2--- daemons/buildd-manager.tac 2010-07-27 10:54:18 +0000
3+++ daemons/buildd-manager.tac 2010-10-20 18:47:46 +0000
4@@ -11,7 +11,7 @@
5 from lp.buildmaster.manager import BuilddManager
6 from lp.services.twistedsupport.loggingsupport import RotatableFileLogObserver
7 from canonical.config import config
8-from canonical.launchpad.daemons import tachandler
9+from canonical.launchpad.daemons import readyservice
10 from canonical.launchpad.scripts import execute_zcml_for_scripts
11 from canonical.lp import initZopeless
12
13@@ -26,7 +26,7 @@
14 RotatableFileLogObserver(options.get('logfile')), ignoreClass=1)
15
16 # Service that announces when the daemon is ready.
17-tachandler.ReadyService().setServiceParent(application)
18+readyservice.ReadyService().setServiceParent(application)
19
20 # Service for scanning buildd slaves.
21 service = BuilddManager()
22
23=== modified file 'daemons/buildd-slave.tac'
24--- daemons/buildd-slave.tac 2010-07-26 13:54:19 +0000
25+++ daemons/buildd-slave.tac 2010-10-20 18:47:46 +0000
26@@ -13,7 +13,7 @@
27 from canonical.buildd.sourcepackagerecipe import (
28 SourcePackageRecipeBuildManager)
29 from canonical.buildd.translationtemplates import TranslationTemplatesBuildManager
30-from canonical.launchpad.daemons import tachandler
31+from canonical.launchpad.daemons import readyservice
32
33 from twisted.web import server, resource, static
34 from ConfigParser import SafeConfigParser
35@@ -36,7 +36,7 @@
36 builddslaveService = service.IServiceCollection(application)
37
38 # Service that announces when the daemon is ready
39-tachandler.ReadyService().setServiceParent(builddslaveService)
40+readyservice.ReadyService().setServiceParent(builddslaveService)
41
42 root = resource.Resource()
43 root.putChild('rpc', slave)
44
45=== modified file 'daemons/distributionmirror_http_server.tac'
46--- daemons/distributionmirror_http_server.tac 2009-06-24 20:55:31 +0000
47+++ daemons/distributionmirror_http_server.tac 2010-10-20 18:47:46 +0000
48@@ -9,7 +9,7 @@
49 from twisted.application import service, internet, strports
50 from twisted.web import server
51
52-from canonical.launchpad.daemons import tachandler
53+from canonical.launchpad.daemons import readyservice
54 from lp.registry.tests.distributionmirror_http_server import (
55 DistributionMirrorTestHTTPServer)
56
57@@ -18,7 +18,7 @@
58 httpserverService = service.IServiceCollection(application)
59
60 # Service that announces when the daemon is ready
61-tachandler.ReadyService().setServiceParent(httpserverService)
62+readyservice.ReadyService().setServiceParent(httpserverService)
63
64 root = DistributionMirrorTestHTTPServer()
65 site = server.Site(root)
66
67=== modified file 'daemons/librarian.tac'
68--- daemons/librarian.tac 2010-07-25 05:16:58 +0000
69+++ daemons/librarian.tac 2010-10-20 18:47:46 +0000
70@@ -12,7 +12,7 @@
71 from twisted.web import server
72
73 from canonical.config import config, dbconfig
74-from canonical.launchpad.daemons import tachandler
75+from canonical.launchpad.daemons import readyservice
76 from canonical.launchpad.scripts import execute_zcml_for_scripts
77
78 from canonical.librarian.interfaces import DUMP_FILE, SIGDUMPMEM
79@@ -38,7 +38,7 @@
80 librarianService = service.IServiceCollection(application)
81
82 # Service that announces when the daemon is ready
83-tachandler.ReadyService().setServiceParent(librarianService)
84+readyservice.ReadyService().setServiceParent(librarianService)
85
86 def setUpListener(uploadPort, webPort, restricted):
87 """Set up a librarian listener on the given ports.
88
89=== modified file 'daemons/poppy-sftp.tac'
90--- daemons/poppy-sftp.tac 2010-06-25 17:01:36 +0000
91+++ daemons/poppy-sftp.tac 2010-10-20 18:47:46 +0000
92@@ -17,7 +17,7 @@
93 from zope.interface import implements
94
95 from canonical.config import config
96-from canonical.launchpad.daemons import tachandler
97+from canonical.launchpad.daemons import readyservice
98
99 from lp.poppy.twistedsftp import SFTPServer
100 from lp.services.sshserver.auth import (
101@@ -100,4 +100,4 @@
102 svc.setServiceParent(application)
103
104 # Service that announces when the daemon is ready
105-tachandler.ReadyService().setServiceParent(application)
106+readyservice.ReadyService().setServiceParent(application)
107
108=== modified file 'daemons/sftp.tac'
109--- daemons/sftp.tac 2010-04-16 18:58:24 +0000
110+++ daemons/sftp.tac 2010-10-20 18:47:46 +0000
111@@ -8,7 +8,7 @@
112 from twisted.application import service
113
114 from canonical.config import config
115-from canonical.launchpad.daemons import tachandler
116+from canonical.launchpad.daemons import readyservice
117
118 from lp.codehosting.sshserver.daemon import (
119 ACCESS_LOG_NAME, get_key_path, LOG_NAME, make_portal, OOPS_CONFIG_SECTION,
120@@ -32,4 +32,4 @@
121 svc.setServiceParent(application)
122
123 # Service that announces when the daemon is ready
124-tachandler.ReadyService().setServiceParent(application)
125+readyservice.ReadyService().setServiceParent(application)
126
127=== modified file 'daemons/zeca.tac'
128--- daemons/zeca.tac 2009-06-24 20:55:31 +0000
129+++ daemons/zeca.tac 2010-10-20 18:47:46 +0000
130@@ -8,7 +8,7 @@
131 from twisted.web import server
132
133 from canonical.config import config
134-from canonical.launchpad.daemons import tachandler
135+from canonical.launchpad.daemons import readyservice
136 from canonical.launchpad.scripts import execute_zcml_for_scripts
137 from canonical.zeca import Zeca, KeyServer, LookUp, SubmitKey
138
139@@ -21,7 +21,7 @@
140 zecaService = service.IServiceCollection(application)
141
142 # Service that announces when the daemon is ready
143-tachandler.ReadyService().setServiceParent(zecaService)
144+readyservice.ReadyService().setServiceParent(zecaService)
145
146 zeca = Zeca()
147 keyserver = KeyServer()
148
149=== modified file 'lib/canonical/buildd/debian/rules'
150--- lib/canonical/buildd/debian/rules 2010-07-26 13:54:19 +0000
151+++ lib/canonical/buildd/debian/rules 2010-10-20 18:47:46 +0000
152@@ -45,7 +45,7 @@
153 # Do installs here
154 touch $(pytarget)/../launchpad/__init__.py
155 touch $(pytarget)/../launchpad/daemons/__init__.py
156- cp launchpad-files/tachandler.py $(pytarget)/../launchpad/daemons/
157+ cp launchpad-files/readyservice.py $(pytarget)/../launchpad/daemons/
158 install -m644 launchpad-files/buildd-slave.tac $(targetshare)/buildd-slave.tac
159 cp -r pottery $(pytarget)
160 for pyfile in $(pyfiles); do \
161@@ -91,7 +91,7 @@
162
163 prepare:
164 install -m644 $(daemons)/buildd-slave.tac launchpad-files/buildd-slave.tac
165- cp ../launchpad/daemons/tachandler.py launchpad-files/tachandler.py
166+ cp ../launchpad/daemons/readyservice.py launchpad-files/readyservice.py
167
168 package: prepare
169 debuild -uc -us -S
170
171=== modified file 'lib/canonical/database/ftests/portforward-to-postgres.tac'
172--- lib/canonical/database/ftests/portforward-to-postgres.tac 2009-06-30 21:06:27 +0000
173+++ lib/canonical/database/ftests/portforward-to-postgres.tac 2010-10-20 18:47:46 +0000
174@@ -10,7 +10,7 @@
175 from twisted.application.internet import TCPServer
176
177 import canonical.lp
178-from canonical.launchpad.daemons.tachandler import ReadyService
179+from canonical.launchpad.daemons.readyservice import ReadyService
180
181 application = service.Application('portforward_to_postgres')
182
183
184=== added file 'lib/canonical/launchpad/daemons/readyservice.py'
185--- lib/canonical/launchpad/daemons/readyservice.py 1970-01-01 00:00:00 +0000
186+++ lib/canonical/launchpad/daemons/readyservice.py 2010-10-20 18:47:46 +0000
187@@ -0,0 +1,29 @@
188+# Copyright 2009-2010 Canonical Ltd. This software is licensed under the
189+# GNU Affero General Public License version 3 (see the file LICENSE).
190+
191+"""Add logging for when twistd services start up.
192+
193+Used externally to launchpad (by launchpad-buildd) - must not import
194+any Launchpad code, and any new external dependencies need coordination
195+with the launchpad-buildd deployment.
196+"""
197+
198+__metaclass__ = type
199+
200+__all__ = [
201+ 'ReadyService',
202+ ]
203+
204+from twisted.application import service
205+from twisted.python import log
206+
207+LOG_MAGIC = 'daemon ready!'
208+
209+
210+class ReadyService(service.Service):
211+ """Service that logs a 'ready!' message once the reactor has started."""
212+
213+ def startService(self):
214+ from twisted.internet import reactor
215+ reactor.addSystemEventTrigger('after', 'startup', log.msg, LOG_MAGIC)
216+ service.Service.startService(self)
217
218=== modified file 'lib/canonical/launchpad/daemons/tachandler.py'
219--- lib/canonical/launchpad/daemons/tachandler.py 2010-09-28 22:33:42 +0000
220+++ lib/canonical/launchpad/daemons/tachandler.py 2010-10-20 18:47:46 +0000
221@@ -9,7 +9,6 @@
222
223 __all__ = [
224 'TacTestSetup',
225- 'ReadyService',
226 'TacException',
227 'kill_by_pidfile',
228 'remove_if_exists',
229@@ -32,8 +31,8 @@
230 from twisted.application import service
231 from twisted.python import log
232
233-# This file is used by launchpad-buildd, so it cannot import any
234-# Launchpad code!
235+from canonical.launchpad.daemons import readyservice
236+
237
238 def _kill_may_race(pid, signal_number):
239 """Kill a pid accepting that it may not exist."""
240@@ -46,6 +45,7 @@
241 # Some other issue (e.g. different user owns it)
242 raise
243
244+
245 def two_stage_kill(pid, poll_interval=0.1, num_polls=50):
246 """Kill process 'pid' with SIGTERM. If it doesn't die, SIGKILL it.
247
248@@ -117,8 +117,6 @@
249 os.path.dirname(__file__),
250 os.pardir, os.pardir, os.pardir, os.pardir, 'bin', 'twistd'))
251
252-LOG_MAGIC = 'daemon ready!'
253-
254
255 class TacException(Exception):
256 """Error raised by TacTestSetup."""
257@@ -147,9 +145,10 @@
258 "Could not kill stale process %s." % (self.pidfile,))
259
260 # setUp() watches the logfile to determine when the daemon has fully
261- # started. If it sees an old logfile, then it will find the LOG_MAGIC
262- # string and return immediately, provoking hard-to-diagnose race
263- # conditions. Delete the logfile to make sure this does not happen.
264+ # started. If it sees an old logfile, then it will find the
265+ # readyservice.LOG_MAGIC string and return immediately, provoking
266+ # hard-to-diagnose race conditions. Delete the logfile to make sure
267+ # this does not happen.
268 remove_if_exists(self.logfile)
269
270 self.setUpRoot()
271@@ -186,12 +185,12 @@
272 def _hasDaemonStarted(self):
273 """Has the daemon started?
274
275- Startup is recognized by the appearance of LOG_MAGIC in the log
276- file.
277+ Startup is recognized by the appearance of readyservice.LOG_MAGIC in
278+ the log file.
279 """
280 if os.path.exists(self.logfile):
281 with open(self.logfile, 'r') as logfile:
282- return LOG_MAGIC in logfile.read()
283+ return readyservice.LOG_MAGIC in logfile.read()
284 else:
285 return False
286
287@@ -203,8 +202,8 @@
288
289 :raises TacException: Timeout.
290 """
291- # Watch the log file for LOG_MAGIC to signal that startup has
292- # completed.
293+ # Watch the log file for readyservice.LOG_MAGIC to signal that startup
294+ # has completed.
295 now = time.time()
296 deadline = now + 20
297 while now < deadline and not self._hasDaemonStarted():
298@@ -255,12 +254,3 @@
299 @property
300 def logfile(self):
301 raise NotImplementedError
302-
303-
304-class ReadyService(service.Service):
305- """Service that logs a 'ready!' message once the reactor has started."""
306-
307- def startService(self):
308- from twisted.internet import reactor
309- reactor.addSystemEventTrigger('after', 'startup', log.msg, LOG_MAGIC)
310- service.Service.startService(self)
311
312=== modified file 'lib/canonical/launchpad/daemons/tests/cannotlisten.tac'
313--- lib/canonical/launchpad/daemons/tests/cannotlisten.tac 2009-06-30 21:06:27 +0000
314+++ lib/canonical/launchpad/daemons/tests/cannotlisten.tac 2010-10-20 18:47:46 +0000
315@@ -11,14 +11,14 @@
316 from twisted.application import service, internet, strports
317 from twisted.internet import protocol
318
319-from canonical.launchpad.daemons import tachandler
320+from canonical.launchpad.daemons import readyservice
321
322
323 application = service.Application('CannotListen')
324 serviceCollection = service.IServiceCollection(application)
325
326 # Service that announces when the daemon is ready
327-tachandler.ReadyService().setServiceParent(serviceCollection)
328+readyservice.ReadyService().setServiceParent(serviceCollection)
329
330 # We almost certainly can't listen on port 1 (usually it requires root
331 # permissions), so this should fail.