]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blob - src/allmydata/test/test_runner.py
setup: fix test_runner to assert that lines which are output to stderr must end with...
[tahoe-lafs/tahoe-lafs.git] / src / allmydata / test / test_runner.py
1
2 from twisted.trial import unittest
3
4 from cStringIO import StringIO
5 from twisted.python import runtime
6 from twisted.internet import utils
7 import os.path, re
8 from allmydata.scripts import runner
9 from allmydata.util import fileutil, pollmixin
10
11 from allmydata.test import common_util
12 import allmydata
13
14 bintahoe = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(allmydata.__file__))), 'bin', 'tahoe')
15
16 class TheRightCode(unittest.TestCase, common_util.SignalMixin):
17     def test_path(self):
18         if not os.path.exists(bintahoe):
19             raise unittest.SkipTest("The bin/tahoe script isn't to be found in the expected location, and I don't want to test a 'tahoe' executable that I find somewhere else, in case it isn't the right executable for this version of tahoe.")
20         d = utils.getProcessOutputAndValue(bintahoe, args=["--version-and-path"], env=os.environ)
21         def _cb(res):
22             out, err, rc_or_sig = res
23             self.failUnlessEqual(rc_or_sig, 0)
24
25             # Fail unless the allmydata-tahoe package is *this* version *and* was loaded from *this* source directory.
26             required_ver_and_path = "allmydata-tahoe: %s (%s)" % (allmydata.__version__, os.path.dirname(os.path.dirname(allmydata.__file__)))
27             self.failUnless(out.startswith(required_ver_and_path), (out, err, rc_or_sig))
28         d.addCallback(_cb)
29         return d
30
31 class CreateNode(unittest.TestCase, common_util.SignalMixin):
32     def workdir(self, name):
33         basedir = os.path.join("test_runner", "CreateNode", name)
34         fileutil.make_dirs(basedir)
35         return basedir
36
37     def test_client(self):
38         if not os.path.exists(bintahoe):
39             raise unittest.SkipTest("The bin/tahoe script isn't to be found in the expected location, and I don't want to test a 'tahoe' executable that I find somewhere else, in case it isn't the right executable for this version of tahoe.")
40         basedir = self.workdir("test_client")
41         c1 = os.path.join(basedir, "c1")
42         d = utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "create-client", "--basedir", c1], env=os.environ)
43         def _cb(res):
44             out, err, rc_or_sig = res
45             # self.failUnlessEqual(err, "", errstr) # See test_client_no_noise -- for now we ignore noise.
46             self.failUnlessEqual(out, "")
47             self.failUnlessEqual(rc_or_sig, 0)
48             self.failUnless(os.path.exists(c1))
49             self.failUnless(os.path.exists(os.path.join(c1, "tahoe-client.tac")))
50         d.addCallback(_cb)
51
52         def _then_try_again(unused=None):
53             return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "create-client", "--basedir", c1], env=os.environ)
54         d.addCallback(_then_try_again)
55
56         def _cb2(res):
57             out, err, rc_or_sig = res
58             # creating the client a second time should throw an exception
59             self.failIfEqual(rc_or_sig, 0, str((out, err, rc_or_sig)))
60             self.failUnlessEqual(out, "")
61             self.failUnless("is not empty." in err)
62
63             # Fail if there is a non-empty line that doesn't end with a PUNCTUATION MARK.
64             for line in err.splitlines():
65                 self.failIf(re.search("[\S][^\.!?]$", line), (line,))
66         d.addCallback(_cb2)
67
68         c2 = os.path.join(basedir, "c2")
69         def _then_try_new_dir(unused=None):
70             return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "create-client", c2], env=os.environ)
71         d.addCallback(_then_try_new_dir)
72
73         def _cb3(res):
74             out, err, rc_or_sig = res
75             self.failUnless(os.path.exists(c2))
76             self.failUnless(os.path.exists(os.path.join(c2, "tahoe-client.tac")))
77         d.addCallback(_cb3)
78
79         def _then_try_badarg(unused=None):
80             return utils.getProcessOutputAndValue(bintahoe, args=["create-client", "basedir", "extraarg"], env=os.environ)
81         d.addCallback(_then_try_badarg)
82
83         def _cb4(res):
84             out, err, rc_or_sig = res
85             self.failUnlessEqual(rc_or_sig, 1)
86             self.failUnless(out.startswith("Usage"), out)
87         d.addCallback(_cb4)
88         return d
89
90     def test_introducer(self):
91         if not os.path.exists(bintahoe):
92             raise unittest.SkipTest("The bin/tahoe script isn't to be found in the expected location, and I don't want to test a 'tahoe' executable that I find somewhere else, in case it isn't the right executable for this version of tahoe.")
93         basedir = self.workdir("test_introducer")
94         c1 = os.path.join(basedir, "c1")
95         d = utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "create-introducer", "--basedir", c1], env=os.environ)
96         def _cb(res):
97             out, err, rc_or_sig = res
98             # self.failUnlessEqual(err, "", errstr) # See test_client_no_noise -- for now we ignore noise.
99             self.failUnlessEqual(out, "")
100             self.failUnlessEqual(rc_or_sig, 0)
101             self.failUnless(os.path.exists(c1))
102             self.failUnless(os.path.exists(os.path.join(c1,
103                                                         "tahoe-introducer.tac")))
104         d.addCallback(_cb)
105
106         def _then_try_again(unused=None):
107             return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "create-introducer", "--basedir", c1], env=os.environ)
108         d.addCallback(_then_try_again)
109
110         def _cb2(res):
111             out, err, rc_or_sig = res
112             # creating the introducer a second time should throw an exception
113             self.failIfEqual(rc_or_sig, 0)
114             self.failUnlessEqual(out, "")
115             self.failUnless("is not empty" in err)
116
117             # Fail if there is a non-empty line that doesn't end with a PUNCTUATION MARK.
118             for line in err.splitlines():
119                 self.failIf(re.search("[\S][^\.!?]$", line), (line,))
120         d.addCallback(_cb2)
121
122         c2 = os.path.join(basedir, "c2")
123         def _then_try_new_dir(unused=None):
124             return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "create-introducer", c2], env=os.environ)
125         d.addCallback(_then_try_new_dir)
126
127         def _cb3(res):
128             out, err, rc_or_sig = res
129             self.failUnless(os.path.exists(c2))
130             self.failUnless(os.path.exists(os.path.join(c2,
131                                                         "tahoe-introducer.tac")))
132         d.addCallback(_cb3)
133
134         def _then_try_badarg(unused=None):
135             return utils.getProcessOutputAndValue(bintahoe, args=["create-introducer", "basedir", "extraarg"], env=os.environ)
136         d.addCallback(_then_try_badarg)
137
138         def _cb4(res):
139             out, err, rc_or_sig = res
140             self.failUnlessEqual(rc_or_sig, 1)
141             self.failUnless(out.startswith("Usage"), out)
142         d.addCallback(_cb4)
143
144         def _then_try_badarg_again(unused=None):
145             return utils.getProcessOutputAndValue(bintahoe, args=["create-introducer"], env=os.environ)
146         d.addCallback(_then_try_badarg_again)
147
148         def _cb5(res):
149             out, err, rc_or_sig = res
150             self.failUnlessEqual(rc_or_sig, 1)
151             self.failUnless(out.startswith("Usage"), out)
152         d.addCallback(_cb5)
153         return d
154
155 class RunNode(unittest.TestCase, pollmixin.PollMixin, common_util.SignalMixin):
156     def workdir(self, name):
157         basedir = os.path.join("test_runner", "RunNode", name)
158         fileutil.make_dirs(basedir)
159         return basedir
160
161     def test_introducer(self):
162         if not os.path.exists(bintahoe):
163             raise unittest.SkipTest("The bin/tahoe script isn't to be found in the expected location, and I don't want to test a 'tahoe' executable that I find somewhere else, in case it isn't the right executable for this version of tahoe.")
164         if runtime.platformType == "win32":
165             # twistd on windows doesn't daemonize. cygwin works normally.
166             raise unittest.SkipTest("twistd does not fork under windows")
167         basedir = self.workdir("test_introducer")
168         c1 = os.path.join(basedir, "c1")
169         HOTLINE_FILE = os.path.join(c1, "suicide_prevention_hotline")
170         TWISTD_PID_FILE = os.path.join(c1, "twistd.pid")
171         INTRODUCER_FURL_FILE = os.path.join(c1, "introducer.furl")
172
173         d = utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "create-introducer", "--basedir", c1], env=os.environ)
174         def _cb(res):
175             out, err, rc_or_sig = res
176             self.failUnlessEqual(rc_or_sig, 0)
177             # by writing this file, we get ten seconds before the node will
178             # exit. This insures that even if the test fails (and the 'stop'
179             # command doesn't work), the client should still terminate.
180             open(HOTLINE_FILE, "w").write("")
181             # now it's safe to start the node
182         d.addCallback(_cb)
183
184         def _then_start_the_node(res):
185             return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "start", c1], env=os.environ)
186         d.addCallback(_then_start_the_node)
187
188         def _cb2(res):
189             out, err, rc_or_sig = res
190
191             open(HOTLINE_FILE, "w").write("")
192             errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
193             self.failUnlessEqual(rc_or_sig, 0, errstr)
194             self.failUnlessEqual(out, "", errstr)
195             # self.failUnlessEqual(err, "", errstr) # See test_client_no_noise -- for now we ignore noise.
196
197             # the parent (twistd) has exited. However, twistd writes the pid
198             # from the child, not the parent, so we can't expect twistd.pid
199             # to exist quite yet.
200
201             # the node is running, but it might not have made it past the
202             # first reactor turn yet, and if we kill it too early, it won't
203             # remove the twistd.pid file. So wait until it does something
204             # that we know it won't do until after the first turn.
205         d.addCallback(_cb2)
206
207         def _node_has_started():
208             return os.path.exists(INTRODUCER_FURL_FILE)
209         d.addCallback(lambda res: self.poll(_node_has_started))
210
211         def _started(res):
212             open(HOTLINE_FILE, "w").write("")
213             self.failUnless(os.path.exists(TWISTD_PID_FILE))
214             # rm this so we can detect when the second incarnation is ready
215             os.unlink(INTRODUCER_FURL_FILE)
216             return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "restart", c1], env=os.environ)
217         d.addCallback(_started)
218
219         def _then(res):
220             out, err, rc_or_sig = res
221             open(HOTLINE_FILE, "w").write("")
222             errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
223             self.failUnlessEqual(rc_or_sig, 0, errstr)
224             self.failUnlessEqual(out, "", errstr)
225             # self.failUnlessEqual(err, "", errstr) # See test_client_no_noise -- for now we ignore noise.
226         d.addCallback(_then)
227
228         # again, the second incarnation of the node might not be ready yet,
229         # so poll until it is
230         d.addCallback(lambda res: self.poll(_node_has_started))
231
232         # now we can kill it. TODO: On a slow machine, the node might kill
233         # itself before we get a chance too, especially if spawning the
234         # 'tahoe stop' command takes a while.
235         def _stop(res):
236             open(HOTLINE_FILE, "w").write("")
237             self.failUnless(os.path.exists(TWISTD_PID_FILE))
238
239             return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "stop", c1], env=os.environ)
240         d.addCallback(_stop)
241
242         def _after_stopping(res):
243             out, err, rc_or_sig = res
244             open(HOTLINE_FILE, "w").write("")
245             # the parent has exited by now
246             errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
247             self.failUnlessEqual(rc_or_sig, 0, errstr)
248             self.failUnlessEqual(out, "", errstr)
249             # self.failUnlessEqual(err, "", errstr) # See test_client_no_noise -- for now we ignore noise.
250             # the parent was supposed to poll and wait until it sees
251             # twistd.pid go away before it exits, so twistd.pid should be
252             # gone by now.
253             self.failIf(os.path.exists(TWISTD_PID_FILE))
254         d.addCallback(_after_stopping)
255
256         def _remove_hotline(res):
257             os.unlink(HOTLINE_FILE)
258             return res
259         d.addBoth(_remove_hotline)
260         return d
261
262     def test_client_no_noise(self):
263         if not os.path.exists(bintahoe):
264             raise unittest.SkipTest("The bin/tahoe script isn't to be found in the expected location, and I don't want to test a 'tahoe' executable that I find somewhere else, in case it isn't the right executable for this version of tahoe.")
265         basedir = self.workdir("test_client_no_noise")
266         c1 = os.path.join(basedir, "c1")
267         HOTLINE_FILE = os.path.join(c1, "suicide_prevention_hotline")
268         TWISTD_PID_FILE = os.path.join(c1, "twistd.pid")
269         PORTNUMFILE = os.path.join(c1, "client.port")
270
271         d = utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "create-client", "--basedir", c1, "--webport", "0"], env=os.environ)
272         def _cb(res):
273             out, err, rc_or_sig = res
274             errstr = "cc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
275             assert rc_or_sig == 0, errstr
276             self.failUnlessEqual(rc_or_sig, 0)
277             # By writing this file, we get forty seconds before the client will exit. This insures
278             # that even if the 'stop' command doesn't work (and the test fails), the client should
279             # still terminate.
280             open(HOTLINE_FILE, "w").write("")
281             open(os.path.join(c1, "introducer.furl"), "w").write("pb://xrndsskn2zuuian5ltnxrte7lnuqdrkz@127.0.0.1:55617/introducer\n")
282             # now it's safe to start the node
283         d.addCallback(_cb)
284
285         def _start(res):
286             return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "start", c1], env=os.environ)
287         d.addCallback(_start)
288
289         def _cb2(res):
290             out, err, rc_or_sig = res
291             errstr = "cc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
292             open(HOTLINE_FILE, "w").write("")
293             self.failUnlessEqual(rc_or_sig, 0, errstr)
294             self.failUnlessEqual(out, "", errstr) # If you emit noise, you fail this test.
295             self.failUnlessEqual(err, "", errstr)
296
297             # the parent (twistd) has exited. However, twistd writes the pid
298             # from the child, not the parent, so we can't expect twistd.pid
299             # to exist quite yet.
300
301             # the node is running, but it might not have made it past the
302             # first reactor turn yet, and if we kill it too early, it won't
303             # remove the twistd.pid file. So wait until it does something
304             # that we know it won't do until after the first turn.
305         d.addCallback(_cb2)
306
307         def _node_has_started():
308             return os.path.exists(PORTNUMFILE)
309         d.addCallback(lambda res: self.poll(_node_has_started))
310
311         # now we can kill it. TODO: On a slow machine, the node might kill
312         # itself before we get a chance too, especially if spawning the
313         # 'tahoe stop' command takes a while.
314         def _stop(res):
315             self.failUnless(os.path.exists(TWISTD_PID_FILE), (TWISTD_PID_FILE, os.listdir(os.path.dirname(TWISTD_PID_FILE))))
316             return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "stop", c1], env=os.environ)
317         d.addCallback(_stop)
318         return d
319     test_client_no_noise.todo = "We submitted a patch to Nevow to silence this warning: http://divmod.org/trac/ticket/2830"
320
321     def test_client(self):
322         if not os.path.exists(bintahoe):
323             raise unittest.SkipTest("The bin/tahoe script isn't to be found in the expected location, and I don't want to test a 'tahoe' executable that I find somewhere else, in case it isn't the right executable for this version of tahoe.")
324         if runtime.platformType == "win32":
325             # twistd on windows doesn't daemonize. cygwin works normally.
326             raise unittest.SkipTest("twistd does not fork under windows")
327         basedir = self.workdir("test_client")
328         c1 = os.path.join(basedir, "c1")
329         HOTLINE_FILE = os.path.join(c1, "suicide_prevention_hotline")
330         TWISTD_PID_FILE = os.path.join(c1, "twistd.pid")
331         PORTNUMFILE = os.path.join(c1, "client.port")
332
333         d = utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "create-client", "--basedir", c1, "--webport", "0"], env=os.environ)
334         def _cb(res):
335             out, err, rc_or_sig = res
336             self.failUnlessEqual(rc_or_sig, 0)
337             # By writing this file, we get forty seconds before the client will exit. This insures
338             # that even if the 'stop' command doesn't work (and the test fails), the client should
339             # still terminate.
340             open(HOTLINE_FILE, "w").write("")
341             open(os.path.join(c1, "introducer.furl"), "w").write("pb://xrndsskn2zuuian5ltnxrte7lnuqdrkz@127.0.0.1:55617/introducer\n")
342             # now it's safe to start the node
343         d.addCallback(_cb)
344
345         def _start(res):
346             return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "start", c1], env=os.environ)
347         d.addCallback(_start)
348
349         def _cb2(res):
350             out, err, rc_or_sig = res
351             open(HOTLINE_FILE, "w").write("")
352             errstr = "cc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
353             self.failUnlessEqual(rc_or_sig, 0, errstr)
354             self.failUnlessEqual(out, "", errstr)
355             # self.failUnlessEqual(err, "", errstr) # See test_client_no_noise -- for now we ignore noise.
356
357             # the parent (twistd) has exited. However, twistd writes the pid
358             # from the child, not the parent, so we can't expect twistd.pid
359             # to exist quite yet.
360
361             # the node is running, but it might not have made it past the
362             # first reactor turn yet, and if we kill it too early, it won't
363             # remove the twistd.pid file. So wait until it does something
364             # that we know it won't do until after the first turn.
365         d.addCallback(_cb2)
366
367         def _node_has_started():
368             return os.path.exists(PORTNUMFILE)
369         d.addCallback(lambda res: self.poll(_node_has_started))
370
371         def _started(res):
372             open(HOTLINE_FILE, "w").write("")
373             self.failUnless(os.path.exists(TWISTD_PID_FILE))
374             # rm this so we can detect when the second incarnation is ready
375             os.unlink(PORTNUMFILE)
376
377             return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "restart", c1], env=os.environ)
378         d.addCallback(_started)
379
380         def _cb3(res):
381             out, err, rc_or_sig = res
382
383             open(HOTLINE_FILE, "w").write("")
384             errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
385             self.failUnlessEqual(rc_or_sig, 0, errstr)
386             self.failUnlessEqual(out, "", errstr)
387             # self.failUnlessEqual(err, "", errstr) # See test_client_no_noise -- for now we ignore noise.
388         d.addCallback(_cb3)
389
390         # again, the second incarnation of the node might not be ready yet,
391         # so poll until it is
392         d.addCallback(lambda res: self.poll(_node_has_started))
393
394         # now we can kill it. TODO: On a slow machine, the node might kill
395         # itself before we get a chance too, especially if spawning the
396         # 'tahoe stop' command takes a while.
397         def _stop(res):
398             open(HOTLINE_FILE, "w").write("")
399             self.failUnless(os.path.exists(TWISTD_PID_FILE), (TWISTD_PID_FILE, os.listdir(os.path.dirname(TWISTD_PID_FILE))))
400             return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "stop", c1], env=os.environ)
401         d.addCallback(_stop)
402
403         def _cb4(res):
404             out, err, rc_or_sig = res
405
406             open(HOTLINE_FILE, "w").write("")
407             # the parent has exited by now
408             errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
409             self.failUnlessEqual(rc_or_sig, 0, errstr)
410             self.failUnlessEqual(out, "", errstr)
411             # self.failUnlessEqual(err, "", errstr) # See test_client_no_noise -- for now we ignore noise.
412             # the parent was supposed to poll and wait until it sees
413             # twistd.pid go away before it exits, so twistd.pid should be
414             # gone by now.
415             self.failIf(os.path.exists(TWISTD_PID_FILE))
416         d.addCallback(_cb4)
417         def _remove_hotline(res):
418             os.unlink(HOTLINE_FILE)
419             return res
420         d.addBoth(_remove_hotline)
421         return d
422
423     def test_baddir(self):
424         if not os.path.exists(bintahoe):
425             raise unittest.SkipTest("The bin/tahoe script isn't to be found in the expected location, and I don't want to test a 'tahoe' executable that I find somewhere else, in case it isn't the right executable for this version of tahoe.")
426         basedir = self.workdir("test_baddir")
427         fileutil.make_dirs(basedir)
428
429         d = utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "start", "--basedir", basedir], env=os.environ)
430         def _cb(res):
431             out, err, rc_or_sig = res
432             self.failUnlessEqual(rc_or_sig, 1)
433             self.failUnless("does not look like a node directory" in err)
434         d.addCallback(_cb)
435
436         def _then_stop_it(res):
437             return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "stop", "--basedir", basedir], env=os.environ)
438         d.addCallback(_then_stop_it)
439
440         def _cb2(res):
441             out, err, rc_or_sig = res
442             self.failUnlessEqual(rc_or_sig, 2)
443             self.failUnless("does not look like a running node directory" in err)
444         d.addCallback(_cb2)
445
446         def _then_start_in_bogus_basedir(res):
447             not_a_dir = os.path.join(basedir, "bogus")
448             return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "start", "--basedir", not_a_dir], env=os.environ)
449         d.addCallback(_then_start_in_bogus_basedir)
450
451         def _cb3(res):
452             out, err, rc_or_sig = res
453             self.failUnlessEqual(rc_or_sig, 1)
454             self.failUnless("does not look like a directory at all" in err, err)
455         d.addCallback(_cb3)
456         return d
457
458     def test_keygen(self):
459         if not os.path.exists(bintahoe):
460             raise unittest.SkipTest("The bin/tahoe script isn't to be found in the expected location, and I don't want to test a 'tahoe' executable that I find somewhere else, in case it isn't the right executable for this version of tahoe.")
461         if runtime.platformType == "win32":
462             # twistd on windows doesn't daemonize. cygwin works normally.
463             raise unittest.SkipTest("twistd does not fork under windows")
464         basedir = self.workdir("test_keygen")
465         c1 = os.path.join(basedir, "c1")
466         TWISTD_PID_FILE = os.path.join(c1, "twistd.pid")
467         KEYGEN_FURL_FILE = os.path.join(c1, "key_generator.furl")
468
469         d = utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "create-key-generator", "--basedir", c1], env=os.environ)
470         def _cb(res):
471             out, err, rc_or_sig = res
472             self.failUnlessEqual(rc_or_sig, 0)
473         d.addCallback(_cb)
474
475         def _start(res):
476             return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "start", c1], env=os.environ)
477         d.addCallback(_start)
478
479         def _cb2(res):
480             out, err, rc_or_sig = res
481             errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
482             self.failUnlessEqual(rc_or_sig, 0, errstr)
483             self.failUnlessEqual(out, "", errstr)
484             # self.failUnlessEqual(err, "", errstr) # See test_client_no_noise -- for now we ignore noise.
485
486             # the parent (twistd) has exited. However, twistd writes the pid
487             # from the child, not the parent, so we can't expect twistd.pid
488             # to exist quite yet.
489
490             # the node is running, but it might not have made it past the
491             # first reactor turn yet, and if we kill it too early, it won't
492             # remove the twistd.pid file. So wait until it does something
493             # that we know it won't do until after the first turn.
494         d.addCallback(_cb2)
495
496         def _node_has_started():
497             return os.path.exists(KEYGEN_FURL_FILE)
498         d.addCallback(lambda res: self.poll(_node_has_started))
499
500         def _started(res):
501             self.failUnless(os.path.exists(TWISTD_PID_FILE))
502             # rm this so we can detect when the second incarnation is ready
503             os.unlink(KEYGEN_FURL_FILE)
504             return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "restart", c1], env=os.environ)
505         d.addCallback(_started)
506
507         def _cb3(res):
508             out, err, rc_or_sig = res
509             errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
510             self.failUnlessEqual(rc_or_sig, 0, errstr)
511             self.failUnlessEqual(out, "", errstr)
512             # self.failUnlessEqual(err, "", errstr) # See test_client_no_noise -- for now we ignore noise.
513         d.addCallback(_cb3)
514
515         # again, the second incarnation of the node might not be ready yet,
516         # so poll until it is
517         d.addCallback(lambda res: self.poll(_node_has_started))
518
519         # now we can kill it. TODO: On a slow machine, the node might kill
520         # itself before we get a chance too, especially if spawning the
521         # 'tahoe stop' command takes a while.
522         def _stop(res):
523             self.failUnless(os.path.exists(TWISTD_PID_FILE))
524             return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "stop", c1], env=os.environ)
525         d.addCallback(_stop)
526
527         def _cb4(res):
528             out, err, rc_or_sig = res
529             # the parent has exited by now
530             errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
531             self.failUnlessEqual(rc_or_sig, 0, errstr)
532             self.failUnlessEqual(out, "", errstr)
533             # self.failUnlessEqual(err, "", errstr) # See test_client_no_noise -- for now we ignore noise.
534             # the parent was supposed to poll and wait until it sees
535             # twistd.pid go away before it exits, so twistd.pid should be
536             # gone by now.
537             self.failIf(os.path.exists(TWISTD_PID_FILE))
538         d.addCallback(_cb4)
539         return d