1 from twisted.trial import unittest
3 from twisted.python import usage, runtime
4 from twisted.internet import utils
5 import os.path, re, sys
6 from cStringIO import StringIO
7 from allmydata.util import fileutil, pollmixin
8 from allmydata.scripts import runner
10 from allmydata.test import common_util
13 bintahoe = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(allmydata.__file__))), 'bin', 'tahoe')
14 if sys.platform == "win32":
17 class SkipOnCygwinMixin:
18 def skip_on_cygwin(self):
19 if "cygwin" in sys.platform.lower():
20 raise unittest.SkipTest("We don't know how to make this test work on cygwin: spawnProcess seems to hang forever. We don't know if 'bin/tahoe start' can be run on cygwin.")
22 class TheRightCode(common_util.SignalMixin, unittest.TestCase,
26 if not os.path.exists(bintahoe):
27 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.")
28 d = utils.getProcessOutputAndValue(bintahoe, args=["--version-and-path"], env=os.environ)
30 out, err, rc_or_sig = res
31 self.failUnlessEqual(rc_or_sig, 0)
33 # Fail unless the allmydata-tahoe package is *this* version *and* was loaded from *this* source directory.
34 required_ver_and_path = "allmydata-tahoe: %s (%s)" % (allmydata.__version__, os.path.dirname(os.path.dirname(allmydata.__file__)))
35 self.failUnless(out.startswith(required_ver_and_path), (out, err, rc_or_sig, required_ver_and_path))
39 class CreateNode(unittest.TestCase):
40 # exercise "tahoe create-client", create-introducer,
41 # create-key-generator, and create-stats-gatherer, by calling the
42 # corresponding code as a subroutine.
44 def workdir(self, name):
45 basedir = os.path.join("test_runner", "CreateNode", name)
46 fileutil.make_dirs(basedir)
49 def run_tahoe(self, argv):
50 out,err = StringIO(), StringIO()
51 rc = runner.runner(argv, stdout=out, stderr=err)
52 return rc, out.getvalue(), err.getvalue()
54 def test_client(self):
55 basedir = self.workdir("test_client")
56 c1 = os.path.join(basedir, "c1")
57 argv = ["--quiet", "create-client", "--basedir", c1]
58 rc, out, err = self.run_tahoe(argv)
59 self.failUnlessEqual(err, "")
60 self.failUnlessEqual(out, "")
61 self.failUnlessEqual(rc, 0)
62 self.failUnless(os.path.exists(c1))
63 self.failUnless(os.path.exists(os.path.join(c1, "tahoe-client.tac")))
65 # creating the client a second time should be rejected
66 rc, out, err = self.run_tahoe(argv)
67 self.failIfEqual(rc, 0, str((out, err, rc)))
68 self.failUnlessEqual(out, "")
69 self.failUnless("is not empty." in err)
71 # Fail if there is a non-empty line that doesn't end with a
73 for line in err.splitlines():
74 self.failIf(re.search("[\S][^\.!?]$", line), (line,))
76 # test that the non --basedir form works too
77 c2 = os.path.join(basedir, "c2")
78 argv = ["--quiet", "create-client", c2]
79 rc, out, err = self.run_tahoe(argv)
80 self.failUnless(os.path.exists(c2))
81 self.failUnless(os.path.exists(os.path.join(c2, "tahoe-client.tac")))
83 # make sure it rejects too many arguments
84 argv = ["create-client", "basedir", "extraarg"]
85 self.failUnlessRaises(usage.UsageError,
89 def test_introducer(self):
90 basedir = self.workdir("test_introducer")
91 c1 = os.path.join(basedir, "c1")
92 argv = ["--quiet", "create-introducer", "--basedir", c1]
93 rc, out, err = self.run_tahoe(argv)
94 self.failUnlessEqual(err, "", err)
95 self.failUnlessEqual(out, "")
96 self.failUnlessEqual(rc, 0)
97 self.failUnless(os.path.exists(c1))
98 self.failUnless(os.path.exists(os.path.join(c1,"tahoe-introducer.tac")))
100 # creating the introducer a second time should be rejected
101 rc, out, err = self.run_tahoe(argv)
102 self.failIfEqual(rc, 0)
103 self.failUnlessEqual(out, "")
104 self.failUnless("is not empty" in err)
106 # Fail if there is a non-empty line that doesn't end with a
108 for line in err.splitlines():
109 self.failIf(re.search("[\S][^\.!?]$", line), (line,))
111 # test the non --basedir form
112 c2 = os.path.join(basedir, "c2")
113 argv = ["--quiet", "create-introducer", c2]
114 rc, out, err = self.run_tahoe(argv)
115 self.failUnlessEqual(err, "", err)
116 self.failUnlessEqual(out, "")
117 self.failUnlessEqual(rc, 0)
118 self.failUnless(os.path.exists(c2))
119 self.failUnless(os.path.exists(os.path.join(c2,"tahoe-introducer.tac")))
121 # reject extra arguments
122 argv = ["create-introducer", "basedir", "extraarg"]
123 self.failUnlessRaises(usage.UsageError,
126 # and require basedir to be provided in some form
127 argv = ["create-introducer"]
128 self.failUnlessRaises(usage.UsageError,
132 def test_key_generator(self):
133 basedir = self.workdir("test_key_generator")
134 kg1 = os.path.join(basedir, "kg1")
135 argv = ["--quiet", "create-key-generator", "--basedir", kg1]
136 rc, out, err = self.run_tahoe(argv)
137 self.failUnlessEqual(err, "")
138 self.failUnlessEqual(out, "")
139 self.failUnlessEqual(rc, 0)
140 self.failUnless(os.path.exists(kg1))
141 self.failUnless(os.path.exists(os.path.join(kg1, "tahoe-key-generator.tac")))
143 # creating it a second time should be rejected
144 rc, out, err = self.run_tahoe(argv)
145 self.failIfEqual(rc, 0, str((out, err, rc)))
146 self.failUnlessEqual(out, "")
147 self.failUnless("is not empty." in err)
149 # make sure it rejects too many arguments
150 argv = ["create-key-generator", "basedir", "extraarg"]
151 self.failUnlessRaises(usage.UsageError,
155 # make sure it rejects a missing basedir specification
156 argv = ["create-key-generator"]
157 rc, out, err = self.run_tahoe(argv)
158 self.failIfEqual(rc, 0, str((out, err, rc)))
159 self.failUnlessEqual(out, "")
160 self.failUnless("a basedir was not provided" in err)
162 def test_stats_gatherer(self):
163 basedir = self.workdir("test_stats_gatherer")
164 sg1 = os.path.join(basedir, "sg1")
165 argv = ["--quiet", "create-stats-gatherer", "--basedir", sg1]
166 rc, out, err = self.run_tahoe(argv)
167 self.failUnlessEqual(err, "")
168 self.failUnlessEqual(out, "")
169 self.failUnlessEqual(rc, 0)
170 self.failUnless(os.path.exists(sg1))
171 self.failUnless(os.path.exists(os.path.join(sg1, "tahoe-stats-gatherer.tac")))
173 # creating it a second time should be rejected
174 rc, out, err = self.run_tahoe(argv)
175 self.failIfEqual(rc, 0, str((out, err, rc)))
176 self.failUnlessEqual(out, "")
177 self.failUnless("is not empty." in err)
179 # test the non --basedir form
180 kg2 = os.path.join(basedir, "kg2")
181 argv = ["--quiet", "create-stats-gatherer", kg2]
182 rc, out, err = self.run_tahoe(argv)
183 self.failUnlessEqual(err, "", err)
184 self.failUnlessEqual(out, "")
185 self.failUnlessEqual(rc, 0)
186 self.failUnless(os.path.exists(kg2))
187 self.failUnless(os.path.exists(os.path.join(kg2,"tahoe-stats-gatherer.tac")))
189 # make sure it rejects too many arguments
190 argv = ["create-stats-gatherer", "basedir", "extraarg"]
191 self.failUnlessRaises(usage.UsageError,
195 # make sure it rejects a missing basedir specification
196 argv = ["create-stats-gatherer"]
197 rc, out, err = self.run_tahoe(argv)
198 self.failIfEqual(rc, 0, str((out, err, rc)))
199 self.failUnlessEqual(out, "")
200 self.failUnless("a basedir was not provided" in err)
202 def test_subcommands(self):
203 # no arguments should trigger a command listing, via UsageError
204 self.failUnlessRaises(usage.UsageError,
210 class RunNode(common_util.SignalMixin, unittest.TestCase, pollmixin.PollMixin,
212 # exercise "tahoe start", for both introducer, client node, and
213 # key-generator, by spawning "tahoe start" as a subprocess. This doesn't
214 # get us figleaf-based line-level coverage, but it does a better job of
215 # confirming that the user can actually run "./bin/tahoe start" and
216 # expect it to work. This verifies that bin/tahoe sets up PYTHONPATH and
217 # the like correctly.
219 # This doesn't work on cygwin (it hangs forever), so we skip this test
220 # when we're on cygwin. It is likely that "tahoe start" itself doesn't
221 # work on cygwin: twisted seems unable to provide a version of
222 # spawnProcess which really works there.
224 def workdir(self, name):
225 basedir = os.path.join("test_runner", "RunNode", name)
226 fileutil.make_dirs(basedir)
229 def test_introducer(self):
230 self.skip_on_cygwin()
231 if not os.path.exists(bintahoe):
232 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.")
233 if runtime.platformType == "win32":
234 # twistd on windows doesn't daemonize. cygwin works normally.
235 raise unittest.SkipTest("twistd does not fork under windows")
236 basedir = self.workdir("test_introducer")
237 c1 = os.path.join(basedir, "c1")
238 HOTLINE_FILE = os.path.join(c1, "suicide_prevention_hotline")
239 TWISTD_PID_FILE = os.path.join(c1, "twistd.pid")
240 INTRODUCER_FURL_FILE = os.path.join(c1, "introducer.furl")
242 d = utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "create-introducer", "--basedir", c1], env=os.environ)
244 out, err, rc_or_sig = res
245 self.failUnlessEqual(rc_or_sig, 0)
246 # by writing this file, we get ten seconds before the node will
247 # exit. This insures that even if the test fails (and the 'stop'
248 # command doesn't work), the client should still terminate.
249 open(HOTLINE_FILE, "w").write("")
250 # now it's safe to start the node
253 def _then_start_the_node(res):
254 return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "start", c1], env=os.environ)
255 d.addCallback(_then_start_the_node)
258 out, err, rc_or_sig = res
260 open(HOTLINE_FILE, "w").write("")
261 errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
262 self.failUnlessEqual(rc_or_sig, 0, errstr)
263 self.failUnlessEqual(out, "", errstr)
264 # self.failUnlessEqual(err, "", errstr) # See test_client_no_noise -- for now we ignore noise.
266 # the parent (twistd) has exited. However, twistd writes the pid
267 # from the child, not the parent, so we can't expect twistd.pid
268 # to exist quite yet.
270 # the node is running, but it might not have made it past the
271 # first reactor turn yet, and if we kill it too early, it won't
272 # remove the twistd.pid file. So wait until it does something
273 # that we know it won't do until after the first turn.
276 def _node_has_started():
277 return os.path.exists(INTRODUCER_FURL_FILE)
278 d.addCallback(lambda res: self.poll(_node_has_started))
281 open(HOTLINE_FILE, "w").write("")
282 self.failUnless(os.path.exists(TWISTD_PID_FILE))
283 # rm this so we can detect when the second incarnation is ready
284 os.unlink(INTRODUCER_FURL_FILE)
285 return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "restart", c1], env=os.environ)
286 d.addCallback(_started)
289 out, err, rc_or_sig = res
290 open(HOTLINE_FILE, "w").write("")
291 errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
292 self.failUnlessEqual(rc_or_sig, 0, errstr)
293 self.failUnlessEqual(out, "", errstr)
294 # self.failUnlessEqual(err, "", errstr) # See test_client_no_noise -- for now we ignore noise.
297 # again, the second incarnation of the node might not be ready yet,
298 # so poll until it is
299 d.addCallback(lambda res: self.poll(_node_has_started))
301 # now we can kill it. TODO: On a slow machine, the node might kill
302 # itself before we get a chance too, especially if spawning the
303 # 'tahoe stop' command takes a while.
305 open(HOTLINE_FILE, "w").write("")
306 self.failUnless(os.path.exists(TWISTD_PID_FILE))
308 return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "stop", c1], env=os.environ)
311 def _after_stopping(res):
312 out, err, rc_or_sig = res
313 open(HOTLINE_FILE, "w").write("")
314 # the parent has exited by now
315 errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
316 self.failUnlessEqual(rc_or_sig, 0, errstr)
317 self.failUnlessEqual(out, "", errstr)
318 # self.failUnlessEqual(err, "", errstr) # See test_client_no_noise -- for now we ignore noise.
319 # the parent was supposed to poll and wait until it sees
320 # twistd.pid go away before it exits, so twistd.pid should be
322 self.failIf(os.path.exists(TWISTD_PID_FILE))
323 d.addCallback(_after_stopping)
325 def _remove_hotline(res):
326 os.unlink(HOTLINE_FILE)
328 d.addBoth(_remove_hotline)
330 test_introducer.timeout = 240 # This hit the 120-second timeout on "François Lenny-armv5tel"
332 def test_client_no_noise(self):
333 self.skip_on_cygwin()
334 if not os.path.exists(bintahoe):
335 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.")
336 basedir = self.workdir("test_client_no_noise")
337 c1 = os.path.join(basedir, "c1")
338 HOTLINE_FILE = os.path.join(c1, "suicide_prevention_hotline")
339 TWISTD_PID_FILE = os.path.join(c1, "twistd.pid")
340 PORTNUMFILE = os.path.join(c1, "client.port")
342 d = utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "create-client", "--basedir", c1, "--webport", "0"], env=os.environ)
344 out, err, rc_or_sig = res
345 errstr = "cc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
346 assert rc_or_sig == 0, errstr
347 self.failUnlessEqual(rc_or_sig, 0)
348 # By writing this file, we get forty seconds before the client will exit. This insures
349 # that even if the 'stop' command doesn't work (and the test fails), the client should
351 open(HOTLINE_FILE, "w").write("")
352 open(os.path.join(c1, "introducer.furl"), "w").write("pb://xrndsskn2zuuian5ltnxrte7lnuqdrkz@127.0.0.1:55617/introducer\n")
353 # now it's safe to start the node
357 return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "start", c1], env=os.environ)
358 d.addCallback(_start)
361 out, err, rc_or_sig = res
362 errstr = "cc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
363 open(HOTLINE_FILE, "w").write("")
364 self.failUnlessEqual(rc_or_sig, 0, errstr)
365 self.failUnlessEqual(out, "", errstr) # If you emit noise, you fail this test.
366 self.failUnlessEqual(err, "", errstr)
368 # the parent (twistd) has exited. However, twistd writes the pid
369 # from the child, not the parent, so we can't expect twistd.pid
370 # to exist quite yet.
372 # the node is running, but it might not have made it past the
373 # first reactor turn yet, and if we kill it too early, it won't
374 # remove the twistd.pid file. So wait until it does something
375 # that we know it won't do until after the first turn.
378 def _node_has_started():
379 return os.path.exists(PORTNUMFILE)
380 d.addCallback(lambda res: self.poll(_node_has_started))
382 # now we can kill it. TODO: On a slow machine, the node might kill
383 # itself before we get a chance too, especially if spawning the
384 # 'tahoe stop' command takes a while.
386 self.failUnless(os.path.exists(TWISTD_PID_FILE), (TWISTD_PID_FILE, os.listdir(os.path.dirname(TWISTD_PID_FILE))))
387 return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "stop", c1], env=os.environ)
390 test_client_no_noise.todo = "We submitted a patch to Nevow to silence this warning: http://divmod.org/trac/ticket/2830"
392 def test_client(self):
393 self.skip_on_cygwin()
394 if not os.path.exists(bintahoe):
395 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.")
396 if runtime.platformType == "win32":
397 # twistd on windows doesn't daemonize. cygwin works normally.
398 raise unittest.SkipTest("twistd does not fork under windows")
399 basedir = self.workdir("test_client")
400 c1 = os.path.join(basedir, "c1")
401 HOTLINE_FILE = os.path.join(c1, "suicide_prevention_hotline")
402 TWISTD_PID_FILE = os.path.join(c1, "twistd.pid")
403 PORTNUMFILE = os.path.join(c1, "client.port")
405 d = utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "create-client", "--basedir", c1, "--webport", "0"], env=os.environ)
407 out, err, rc_or_sig = res
408 self.failUnlessEqual(rc_or_sig, 0)
409 # By writing this file, we get sixty seconds before the client will exit. This insures
410 # that even if the 'stop' command doesn't work (and the test fails), the client should
412 open(HOTLINE_FILE, "w").write("")
413 open(os.path.join(c1, "introducer.furl"), "w").write("pb://xrndsskn2zuuian5ltnxrte7lnuqdrkz@127.0.0.1:55617/introducer\n")
414 # now it's safe to start the node
418 return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "start", c1], env=os.environ)
419 d.addCallback(_start)
422 out, err, rc_or_sig = res
423 open(HOTLINE_FILE, "w").write("")
424 errstr = "cc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
425 self.failUnlessEqual(rc_or_sig, 0, errstr)
426 self.failUnlessEqual(out, "", errstr)
427 # self.failUnlessEqual(err, "", errstr) # See test_client_no_noise -- for now we ignore noise.
429 # the parent (twistd) has exited. However, twistd writes the pid
430 # from the child, not the parent, so we can't expect twistd.pid
431 # to exist quite yet.
433 # the node is running, but it might not have made it past the
434 # first reactor turn yet, and if we kill it too early, it won't
435 # remove the twistd.pid file. So wait until it does something
436 # that we know it won't do until after the first turn.
439 def _node_has_started():
440 return os.path.exists(PORTNUMFILE)
441 d.addCallback(lambda res: self.poll(_node_has_started))
444 open(HOTLINE_FILE, "w").write("")
445 self.failUnless(os.path.exists(TWISTD_PID_FILE))
446 # rm this so we can detect when the second incarnation is ready
447 os.unlink(PORTNUMFILE)
449 return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "restart", c1], env=os.environ)
450 d.addCallback(_started)
453 out, err, rc_or_sig = res
455 open(HOTLINE_FILE, "w").write("")
456 errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
457 self.failUnlessEqual(rc_or_sig, 0, errstr)
458 self.failUnlessEqual(out, "", errstr)
459 # self.failUnlessEqual(err, "", errstr) # See test_client_no_noise -- for now we ignore noise.
462 # again, the second incarnation of the node might not be ready yet,
463 # so poll until it is
464 d.addCallback(lambda res: self.poll(_node_has_started))
466 # now we can kill it. TODO: On a slow machine, the node might kill
467 # itself before we get a chance too, especially if spawning the
468 # 'tahoe stop' command takes a while.
470 open(HOTLINE_FILE, "w").write("")
471 self.failUnless(os.path.exists(TWISTD_PID_FILE), (TWISTD_PID_FILE, os.listdir(os.path.dirname(TWISTD_PID_FILE))))
472 return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "stop", c1], env=os.environ)
476 out, err, rc_or_sig = res
478 open(HOTLINE_FILE, "w").write("")
479 # the parent has exited by now
480 errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
481 self.failUnlessEqual(rc_or_sig, 0, errstr)
482 self.failUnlessEqual(out, "", errstr)
483 # self.failUnlessEqual(err, "", errstr) # See test_client_no_noise -- for now we ignore noise.
484 # the parent was supposed to poll and wait until it sees
485 # twistd.pid go away before it exits, so twistd.pid should be
487 self.failIf(os.path.exists(TWISTD_PID_FILE))
489 def _remove_hotline(res):
490 os.unlink(HOTLINE_FILE)
492 d.addBoth(_remove_hotline)
495 def test_baddir(self):
496 self.skip_on_cygwin()
497 if not os.path.exists(bintahoe):
498 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.")
499 basedir = self.workdir("test_baddir")
500 fileutil.make_dirs(basedir)
502 d = utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "start", "--basedir", basedir], env=os.environ)
504 out, err, rc_or_sig = res
505 self.failUnlessEqual(rc_or_sig, 1)
506 self.failUnless("does not look like a node directory" in err)
509 def _then_stop_it(res):
510 return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "stop", "--basedir", basedir], env=os.environ)
511 d.addCallback(_then_stop_it)
514 out, err, rc_or_sig = res
515 self.failUnlessEqual(rc_or_sig, 2)
516 self.failUnless("does not look like a running node directory" in err)
519 def _then_start_in_bogus_basedir(res):
520 not_a_dir = os.path.join(basedir, "bogus")
521 return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "start", "--basedir", not_a_dir], env=os.environ)
522 d.addCallback(_then_start_in_bogus_basedir)
525 out, err, rc_or_sig = res
526 self.failUnlessEqual(rc_or_sig, 1)
527 self.failUnless("does not look like a directory at all" in err, err)
531 def test_keygen(self):
532 self.skip_on_cygwin()
533 if not os.path.exists(bintahoe):
534 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.")
535 if runtime.platformType == "win32":
536 # twistd on windows doesn't daemonize. cygwin works normally.
537 raise unittest.SkipTest("twistd does not fork under windows")
538 basedir = self.workdir("test_keygen")
539 c1 = os.path.join(basedir, "c1")
540 TWISTD_PID_FILE = os.path.join(c1, "twistd.pid")
541 KEYGEN_FURL_FILE = os.path.join(c1, "key_generator.furl")
543 d = utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "create-key-generator", "--basedir", c1], env=os.environ)
545 out, err, rc_or_sig = res
546 self.failUnlessEqual(rc_or_sig, 0)
550 return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "start", c1], env=os.environ)
551 d.addCallback(_start)
554 out, err, rc_or_sig = res
555 errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
556 self.failUnlessEqual(rc_or_sig, 0, errstr)
557 self.failUnlessEqual(out, "", errstr)
558 # self.failUnlessEqual(err, "", errstr) # See test_client_no_noise -- for now we ignore noise.
560 # the parent (twistd) has exited. However, twistd writes the pid
561 # from the child, not the parent, so we can't expect twistd.pid
562 # to exist quite yet.
564 # the node is running, but it might not have made it past the
565 # first reactor turn yet, and if we kill it too early, it won't
566 # remove the twistd.pid file. So wait until it does something
567 # that we know it won't do until after the first turn.
570 def _node_has_started():
571 return os.path.exists(KEYGEN_FURL_FILE)
572 d.addCallback(lambda res: self.poll(_node_has_started))
575 self.failUnless(os.path.exists(TWISTD_PID_FILE))
576 # rm this so we can detect when the second incarnation is ready
577 os.unlink(KEYGEN_FURL_FILE)
578 return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "restart", c1], env=os.environ)
579 d.addCallback(_started)
582 out, err, rc_or_sig = res
583 errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
584 self.failUnlessEqual(rc_or_sig, 0, errstr)
585 self.failUnlessEqual(out, "", errstr)
586 # self.failUnlessEqual(err, "", errstr) # See test_client_no_noise -- for now we ignore noise.
589 # again, the second incarnation of the node might not be ready yet,
590 # so poll until it is
591 d.addCallback(lambda res: self.poll(_node_has_started))
593 # now we can kill it. TODO: On a slow machine, the node might kill
594 # itself before we get a chance too, especially if spawning the
595 # 'tahoe stop' command takes a while.
597 self.failUnless(os.path.exists(TWISTD_PID_FILE))
598 return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "stop", c1], env=os.environ)
602 out, err, rc_or_sig = res
603 # the parent has exited by now
604 errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
605 self.failUnlessEqual(rc_or_sig, 0, errstr)
606 self.failUnlessEqual(out, "", errstr)
607 # self.failUnlessEqual(err, "", errstr) # See test_client_no_noise -- for now we ignore noise.
608 # the parent was supposed to poll and wait until it sees
609 # twistd.pid go away before it exits, so twistd.pid should be
611 self.failIf(os.path.exists(TWISTD_PID_FILE))