1 # -*- coding: utf-8 -*-
3 from twisted.trial import unittest
5 from twisted.python import usage, runtime
6 from twisted.internet import utils
7 import os.path, re, sys
8 from cStringIO import StringIO
9 from allmydata.util import fileutil, pollmixin
10 from allmydata.scripts import runner
12 from allmydata.test import common_util
15 bintahoe = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(allmydata.__file__))), 'bin', 'tahoe')
16 if sys.platform == "win32":
19 class SkipOnCygwinMixin:
20 def skip_on_cygwin(self):
21 if "cygwin" in sys.platform.lower():
22 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.")
24 class TheRightCode(common_util.SignalMixin, unittest.TestCase,
28 if not os.path.exists(bintahoe):
29 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.")
30 d = utils.getProcessOutputAndValue(bintahoe, args=["--version-and-path"], env=os.environ)
32 out, err, rc_or_sig = res
33 self.failUnlessEqual(rc_or_sig, 0)
35 # Fail unless the allmydata-tahoe package is *this* version *and* was loaded from *this* source directory.
36 required_ver_and_path = "allmydata-tahoe: %s (%s)" % (allmydata.__version__, os.path.dirname(os.path.dirname(allmydata.__file__)))
37 self.failUnless(out.startswith(required_ver_and_path), (out, err, rc_or_sig, required_ver_and_path))
41 class CreateNode(unittest.TestCase):
42 # exercise "tahoe create-client", create-introducer,
43 # create-key-generator, and create-stats-gatherer, by calling the
44 # corresponding code as a subroutine.
46 def workdir(self, name):
47 basedir = os.path.join("test_runner", "CreateNode", name)
48 fileutil.make_dirs(basedir)
51 def run_tahoe(self, argv):
52 out,err = StringIO(), StringIO()
53 rc = runner.runner(argv, stdout=out, stderr=err)
54 return rc, out.getvalue(), err.getvalue()
56 def test_client(self):
57 basedir = self.workdir("test_client")
58 c1 = os.path.join(basedir, "c1")
59 argv = ["--quiet", "create-client", "--basedir", c1]
60 rc, out, err = self.run_tahoe(argv)
61 self.failUnlessEqual(err, "")
62 self.failUnlessEqual(out, "")
63 self.failUnlessEqual(rc, 0)
64 self.failUnless(os.path.exists(c1))
65 self.failUnless(os.path.exists(os.path.join(c1, "tahoe-client.tac")))
67 # creating the client a second time should be rejected
68 rc, out, err = self.run_tahoe(argv)
69 self.failIfEqual(rc, 0, str((out, err, rc)))
70 self.failUnlessEqual(out, "")
71 self.failUnless("is not empty." in err)
73 # Fail if there is a non-empty line that doesn't end with a
75 for line in err.splitlines():
76 self.failIf(re.search("[\S][^\.!?]$", line), (line,))
78 # test that the non --basedir form works too
79 c2 = os.path.join(basedir, "c2")
80 argv = ["--quiet", "create-client", c2]
81 rc, out, err = self.run_tahoe(argv)
82 self.failUnless(os.path.exists(c2))
83 self.failUnless(os.path.exists(os.path.join(c2, "tahoe-client.tac")))
85 # make sure it rejects too many arguments
86 argv = ["create-client", "basedir", "extraarg"]
87 self.failUnlessRaises(usage.UsageError,
91 def test_introducer(self):
92 basedir = self.workdir("test_introducer")
93 c1 = os.path.join(basedir, "c1")
94 argv = ["--quiet", "create-introducer", "--basedir", c1]
95 rc, out, err = self.run_tahoe(argv)
96 self.failUnlessEqual(err, "", err)
97 self.failUnlessEqual(out, "")
98 self.failUnlessEqual(rc, 0)
99 self.failUnless(os.path.exists(c1))
100 self.failUnless(os.path.exists(os.path.join(c1,"tahoe-introducer.tac")))
102 # creating the introducer a second time should be rejected
103 rc, out, err = self.run_tahoe(argv)
104 self.failIfEqual(rc, 0)
105 self.failUnlessEqual(out, "")
106 self.failUnless("is not empty" in err)
108 # Fail if there is a non-empty line that doesn't end with a
110 for line in err.splitlines():
111 self.failIf(re.search("[\S][^\.!?]$", line), (line,))
113 # test the non --basedir form
114 c2 = os.path.join(basedir, "c2")
115 argv = ["--quiet", "create-introducer", c2]
116 rc, out, err = self.run_tahoe(argv)
117 self.failUnlessEqual(err, "", err)
118 self.failUnlessEqual(out, "")
119 self.failUnlessEqual(rc, 0)
120 self.failUnless(os.path.exists(c2))
121 self.failUnless(os.path.exists(os.path.join(c2,"tahoe-introducer.tac")))
123 # reject extra arguments
124 argv = ["create-introducer", "basedir", "extraarg"]
125 self.failUnlessRaises(usage.UsageError,
128 # and require basedir to be provided in some form
129 argv = ["create-introducer"]
130 self.failUnlessRaises(usage.UsageError,
134 def test_key_generator(self):
135 basedir = self.workdir("test_key_generator")
136 kg1 = os.path.join(basedir, "kg1")
137 argv = ["--quiet", "create-key-generator", "--basedir", kg1]
138 rc, out, err = self.run_tahoe(argv)
139 self.failUnlessEqual(err, "")
140 self.failUnlessEqual(out, "")
141 self.failUnlessEqual(rc, 0)
142 self.failUnless(os.path.exists(kg1))
143 self.failUnless(os.path.exists(os.path.join(kg1, "tahoe-key-generator.tac")))
145 # creating it a second time should be rejected
146 rc, out, err = self.run_tahoe(argv)
147 self.failIfEqual(rc, 0, str((out, err, rc)))
148 self.failUnlessEqual(out, "")
149 self.failUnless("is not empty." in err)
151 # make sure it rejects too many arguments
152 argv = ["create-key-generator", "basedir", "extraarg"]
153 self.failUnlessRaises(usage.UsageError,
157 # make sure it rejects a missing basedir specification
158 argv = ["create-key-generator"]
159 rc, out, err = self.run_tahoe(argv)
160 self.failIfEqual(rc, 0, str((out, err, rc)))
161 self.failUnlessEqual(out, "")
162 self.failUnless("a basedir was not provided" in err)
164 def test_stats_gatherer(self):
165 basedir = self.workdir("test_stats_gatherer")
166 sg1 = os.path.join(basedir, "sg1")
167 argv = ["--quiet", "create-stats-gatherer", "--basedir", sg1]
168 rc, out, err = self.run_tahoe(argv)
169 self.failUnlessEqual(err, "")
170 self.failUnlessEqual(out, "")
171 self.failUnlessEqual(rc, 0)
172 self.failUnless(os.path.exists(sg1))
173 self.failUnless(os.path.exists(os.path.join(sg1, "tahoe-stats-gatherer.tac")))
175 # creating it a second time should be rejected
176 rc, out, err = self.run_tahoe(argv)
177 self.failIfEqual(rc, 0, str((out, err, rc)))
178 self.failUnlessEqual(out, "")
179 self.failUnless("is not empty." in err)
181 # test the non --basedir form
182 kg2 = os.path.join(basedir, "kg2")
183 argv = ["--quiet", "create-stats-gatherer", kg2]
184 rc, out, err = self.run_tahoe(argv)
185 self.failUnlessEqual(err, "", err)
186 self.failUnlessEqual(out, "")
187 self.failUnlessEqual(rc, 0)
188 self.failUnless(os.path.exists(kg2))
189 self.failUnless(os.path.exists(os.path.join(kg2,"tahoe-stats-gatherer.tac")))
191 # make sure it rejects too many arguments
192 argv = ["create-stats-gatherer", "basedir", "extraarg"]
193 self.failUnlessRaises(usage.UsageError,
197 # make sure it rejects a missing basedir specification
198 argv = ["create-stats-gatherer"]
199 rc, out, err = self.run_tahoe(argv)
200 self.failIfEqual(rc, 0, str((out, err, rc)))
201 self.failUnlessEqual(out, "")
202 self.failUnless("a basedir was not provided" in err)
204 def test_subcommands(self):
205 # no arguments should trigger a command listing, via UsageError
206 self.failUnlessRaises(usage.UsageError,
212 class RunNode(common_util.SignalMixin, unittest.TestCase, pollmixin.PollMixin,
214 # exercise "tahoe start", for both introducer, client node, and
215 # key-generator, by spawning "tahoe start" as a subprocess. This doesn't
216 # get us figleaf-based line-level coverage, but it does a better job of
217 # confirming that the user can actually run "./bin/tahoe start" and
218 # expect it to work. This verifies that bin/tahoe sets up PYTHONPATH and
219 # the like correctly.
221 # This doesn't work on cygwin (it hangs forever), so we skip this test
222 # when we're on cygwin. It is likely that "tahoe start" itself doesn't
223 # work on cygwin: twisted seems unable to provide a version of
224 # spawnProcess which really works there.
226 def workdir(self, name):
227 basedir = os.path.join("test_runner", "RunNode", name)
228 fileutil.make_dirs(basedir)
231 def test_introducer(self):
232 self.skip_on_cygwin()
233 if not os.path.exists(bintahoe):
234 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.")
235 if runtime.platformType == "win32":
236 # twistd on windows doesn't daemonize. cygwin works normally.
237 raise unittest.SkipTest("twistd does not fork under windows")
238 basedir = self.workdir("test_introducer")
239 c1 = os.path.join(basedir, "c1")
240 HOTLINE_FILE = os.path.join(c1, "suicide_prevention_hotline")
241 TWISTD_PID_FILE = os.path.join(c1, "twistd.pid")
242 INTRODUCER_FURL_FILE = os.path.join(c1, "introducer.furl")
244 d = utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "create-introducer", "--basedir", c1], env=os.environ)
246 out, err, rc_or_sig = res
247 self.failUnlessEqual(rc_or_sig, 0)
248 # by writing this file, we get ten seconds before the node will
249 # exit. This insures that even if the test fails (and the 'stop'
250 # command doesn't work), the client should still terminate.
251 open(HOTLINE_FILE, "w").write("")
252 # now it's safe to start the node
255 def _then_start_the_node(res):
256 return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "start", c1], env=os.environ)
257 d.addCallback(_then_start_the_node)
260 out, err, rc_or_sig = res
262 open(HOTLINE_FILE, "w").write("")
263 errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
264 self.failUnlessEqual(rc_or_sig, 0, errstr)
265 self.failUnlessEqual(out, "", errstr)
266 # self.failUnlessEqual(err, "", errstr) # See test_client_no_noise -- for now we ignore noise.
268 # the parent (twistd) has exited. However, twistd writes the pid
269 # from the child, not the parent, so we can't expect twistd.pid
270 # to exist quite yet.
272 # the node is running, but it might not have made it past the
273 # first reactor turn yet, and if we kill it too early, it won't
274 # remove the twistd.pid file. So wait until it does something
275 # that we know it won't do until after the first turn.
278 def _node_has_started():
279 return os.path.exists(INTRODUCER_FURL_FILE)
280 d.addCallback(lambda res: self.poll(_node_has_started))
283 open(HOTLINE_FILE, "w").write("")
284 self.failUnless(os.path.exists(TWISTD_PID_FILE))
285 # rm this so we can detect when the second incarnation is ready
286 os.unlink(INTRODUCER_FURL_FILE)
287 return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "restart", c1], env=os.environ)
288 d.addCallback(_started)
291 out, err, rc_or_sig = res
292 open(HOTLINE_FILE, "w").write("")
293 errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
294 self.failUnlessEqual(rc_or_sig, 0, errstr)
295 self.failUnlessEqual(out, "", errstr)
296 # self.failUnlessEqual(err, "", errstr) # See test_client_no_noise -- for now we ignore noise.
299 # again, the second incarnation of the node might not be ready yet,
300 # so poll until it is
301 d.addCallback(lambda res: self.poll(_node_has_started))
303 # now we can kill it. TODO: On a slow machine, the node might kill
304 # itself before we get a chance too, especially if spawning the
305 # 'tahoe stop' command takes a while.
307 open(HOTLINE_FILE, "w").write("")
308 self.failUnless(os.path.exists(TWISTD_PID_FILE))
310 return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "stop", c1], env=os.environ)
313 def _after_stopping(res):
314 out, err, rc_or_sig = res
315 open(HOTLINE_FILE, "w").write("")
316 # the parent has exited by now
317 errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
318 self.failUnlessEqual(rc_or_sig, 0, errstr)
319 self.failUnlessEqual(out, "", errstr)
320 # self.failUnlessEqual(err, "", errstr) # See test_client_no_noise -- for now we ignore noise.
321 # the parent was supposed to poll and wait until it sees
322 # twistd.pid go away before it exits, so twistd.pid should be
324 self.failIf(os.path.exists(TWISTD_PID_FILE))
325 d.addCallback(_after_stopping)
327 def _remove_hotline(res):
328 os.unlink(HOTLINE_FILE)
330 d.addBoth(_remove_hotline)
332 test_introducer.timeout = 240 # This hit the 120-second timeout on "François Lenny-armv5tel"
334 def test_client_no_noise(self):
335 self.skip_on_cygwin()
336 if not os.path.exists(bintahoe):
337 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.")
338 basedir = self.workdir("test_client_no_noise")
339 c1 = os.path.join(basedir, "c1")
340 HOTLINE_FILE = os.path.join(c1, "suicide_prevention_hotline")
341 TWISTD_PID_FILE = os.path.join(c1, "twistd.pid")
342 PORTNUMFILE = os.path.join(c1, "client.port")
344 d = utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "create-client", "--basedir", c1, "--webport", "0"], env=os.environ)
346 out, err, rc_or_sig = res
347 errstr = "cc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
348 assert rc_or_sig == 0, errstr
349 self.failUnlessEqual(rc_or_sig, 0)
350 # By writing this file, we get forty seconds before the client will exit. This insures
351 # that even if the 'stop' command doesn't work (and the test fails), the client should
353 open(HOTLINE_FILE, "w").write("")
354 open(os.path.join(c1, "introducer.furl"), "w").write("pb://xrndsskn2zuuian5ltnxrte7lnuqdrkz@127.0.0.1:55617/introducer\n")
355 # now it's safe to start the node
359 return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "start", c1], env=os.environ)
360 d.addCallback(_start)
363 out, err, rc_or_sig = res
364 errstr = "cc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
365 open(HOTLINE_FILE, "w").write("")
366 self.failUnlessEqual(rc_or_sig, 0, errstr)
367 self.failUnlessEqual(out, "", errstr) # If you emit noise, you fail this test.
368 self.failUnlessEqual(err, "", errstr)
370 # the parent (twistd) has exited. However, twistd writes the pid
371 # from the child, not the parent, so we can't expect twistd.pid
372 # to exist quite yet.
374 # the node is running, but it might not have made it past the
375 # first reactor turn yet, and if we kill it too early, it won't
376 # remove the twistd.pid file. So wait until it does something
377 # that we know it won't do until after the first turn.
380 def _node_has_started():
381 return os.path.exists(PORTNUMFILE)
382 d.addCallback(lambda res: self.poll(_node_has_started))
384 # now we can kill it. TODO: On a slow machine, the node might kill
385 # itself before we get a chance too, especially if spawning the
386 # 'tahoe stop' command takes a while.
388 self.failUnless(os.path.exists(TWISTD_PID_FILE), (TWISTD_PID_FILE, os.listdir(os.path.dirname(TWISTD_PID_FILE))))
389 return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "stop", c1], env=os.environ)
392 test_client_no_noise.todo = "We submitted a patch to Nevow to silence this warning: http://divmod.org/trac/ticket/2830"
394 def test_client(self):
395 self.skip_on_cygwin()
396 if not os.path.exists(bintahoe):
397 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.")
398 if runtime.platformType == "win32":
399 # twistd on windows doesn't daemonize. cygwin works normally.
400 raise unittest.SkipTest("twistd does not fork under windows")
401 basedir = self.workdir("test_client")
402 c1 = os.path.join(basedir, "c1")
403 HOTLINE_FILE = os.path.join(c1, "suicide_prevention_hotline")
404 TWISTD_PID_FILE = os.path.join(c1, "twistd.pid")
405 PORTNUMFILE = os.path.join(c1, "client.port")
407 d = utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "create-client", "--basedir", c1, "--webport", "0"], env=os.environ)
409 out, err, rc_or_sig = res
410 self.failUnlessEqual(rc_or_sig, 0)
411 # By writing this file, we get sixty seconds before the client will exit. This insures
412 # that even if the 'stop' command doesn't work (and the test fails), the client should
414 open(HOTLINE_FILE, "w").write("")
415 open(os.path.join(c1, "introducer.furl"), "w").write("pb://xrndsskn2zuuian5ltnxrte7lnuqdrkz@127.0.0.1:55617/introducer\n")
416 # now it's safe to start the node
420 return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "start", c1], env=os.environ)
421 d.addCallback(_start)
424 out, err, rc_or_sig = res
425 open(HOTLINE_FILE, "w").write("")
426 errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
427 self.failUnlessEqual(rc_or_sig, 0, errstr)
428 self.failUnlessEqual(out, "", errstr)
429 # self.failUnlessEqual(err, "", errstr) # See test_client_no_noise -- for now we ignore noise.
431 # the parent (twistd) has exited. However, twistd writes the pid
432 # from the child, not the parent, so we can't expect twistd.pid
433 # to exist quite yet.
435 # the node is running, but it might not have made it past the
436 # first reactor turn yet, and if we kill it too early, it won't
437 # remove the twistd.pid file. So wait until it does something
438 # that we know it won't do until after the first turn.
441 def _node_has_started():
442 return os.path.exists(PORTNUMFILE)
443 d.addCallback(lambda res: self.poll(_node_has_started))
446 open(HOTLINE_FILE, "w").write("")
447 self.failUnless(os.path.exists(TWISTD_PID_FILE))
448 # rm this so we can detect when the second incarnation is ready
449 os.unlink(PORTNUMFILE)
451 return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "restart", c1], env=os.environ)
452 d.addCallback(_started)
455 out, err, rc_or_sig = res
457 open(HOTLINE_FILE, "w").write("")
458 errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
459 self.failUnlessEqual(rc_or_sig, 0, errstr)
460 self.failUnlessEqual(out, "", errstr)
461 # self.failUnlessEqual(err, "", errstr) # See test_client_no_noise -- for now we ignore noise.
464 # again, the second incarnation of the node might not be ready yet,
465 # so poll until it is
466 d.addCallback(lambda res: self.poll(_node_has_started))
468 # now we can kill it. TODO: On a slow machine, the node might kill
469 # itself before we get a chance too, especially if spawning the
470 # 'tahoe stop' command takes a while.
472 open(HOTLINE_FILE, "w").write("")
473 self.failUnless(os.path.exists(TWISTD_PID_FILE), (TWISTD_PID_FILE, os.listdir(os.path.dirname(TWISTD_PID_FILE))))
474 return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "stop", c1], env=os.environ)
478 out, err, rc_or_sig = res
480 open(HOTLINE_FILE, "w").write("")
481 # the parent has exited by now
482 errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
483 self.failUnlessEqual(rc_or_sig, 0, errstr)
484 self.failUnlessEqual(out, "", errstr)
485 # self.failUnlessEqual(err, "", errstr) # See test_client_no_noise -- for now we ignore noise.
486 # the parent was supposed to poll and wait until it sees
487 # twistd.pid go away before it exits, so twistd.pid should be
489 self.failIf(os.path.exists(TWISTD_PID_FILE))
491 def _remove_hotline(res):
492 os.unlink(HOTLINE_FILE)
494 d.addBoth(_remove_hotline)
497 def test_baddir(self):
498 self.skip_on_cygwin()
499 if not os.path.exists(bintahoe):
500 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.")
501 basedir = self.workdir("test_baddir")
502 fileutil.make_dirs(basedir)
504 d = utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "start", "--basedir", basedir], env=os.environ)
506 out, err, rc_or_sig = res
507 self.failUnlessEqual(rc_or_sig, 1)
508 self.failUnless("does not look like a node directory" in err)
511 def _then_stop_it(res):
512 return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "stop", "--basedir", basedir], env=os.environ)
513 d.addCallback(_then_stop_it)
516 out, err, rc_or_sig = res
517 self.failUnlessEqual(rc_or_sig, 2)
518 self.failUnless("does not look like a running node directory" in err)
521 def _then_start_in_bogus_basedir(res):
522 not_a_dir = os.path.join(basedir, "bogus")
523 return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "start", "--basedir", not_a_dir], env=os.environ)
524 d.addCallback(_then_start_in_bogus_basedir)
527 out, err, rc_or_sig = res
528 self.failUnlessEqual(rc_or_sig, 1)
529 self.failUnless("does not look like a directory at all" in err, err)
533 def test_keygen(self):
534 self.skip_on_cygwin()
535 if not os.path.exists(bintahoe):
536 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.")
537 if runtime.platformType == "win32":
538 # twistd on windows doesn't daemonize. cygwin works normally.
539 raise unittest.SkipTest("twistd does not fork under windows")
540 basedir = self.workdir("test_keygen")
541 c1 = os.path.join(basedir, "c1")
542 TWISTD_PID_FILE = os.path.join(c1, "twistd.pid")
543 KEYGEN_FURL_FILE = os.path.join(c1, "key_generator.furl")
545 d = utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "create-key-generator", "--basedir", c1], env=os.environ)
547 out, err, rc_or_sig = res
548 self.failUnlessEqual(rc_or_sig, 0)
552 return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "start", c1], env=os.environ)
553 d.addCallback(_start)
556 out, err, rc_or_sig = res
557 errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
558 self.failUnlessEqual(rc_or_sig, 0, errstr)
559 self.failUnlessEqual(out, "", errstr)
560 # self.failUnlessEqual(err, "", errstr) # See test_client_no_noise -- for now we ignore noise.
562 # the parent (twistd) has exited. However, twistd writes the pid
563 # from the child, not the parent, so we can't expect twistd.pid
564 # to exist quite yet.
566 # the node is running, but it might not have made it past the
567 # first reactor turn yet, and if we kill it too early, it won't
568 # remove the twistd.pid file. So wait until it does something
569 # that we know it won't do until after the first turn.
572 def _node_has_started():
573 return os.path.exists(KEYGEN_FURL_FILE)
574 d.addCallback(lambda res: self.poll(_node_has_started))
577 self.failUnless(os.path.exists(TWISTD_PID_FILE))
578 # rm this so we can detect when the second incarnation is ready
579 os.unlink(KEYGEN_FURL_FILE)
580 return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "restart", c1], env=os.environ)
581 d.addCallback(_started)
584 out, err, rc_or_sig = res
585 errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
586 self.failUnlessEqual(rc_or_sig, 0, errstr)
587 self.failUnlessEqual(out, "", errstr)
588 # self.failUnlessEqual(err, "", errstr) # See test_client_no_noise -- for now we ignore noise.
591 # again, the second incarnation of the node might not be ready yet,
592 # so poll until it is
593 d.addCallback(lambda res: self.poll(_node_has_started))
595 # now we can kill it. TODO: On a slow machine, the node might kill
596 # itself before we get a chance too, especially if spawning the
597 # 'tahoe stop' command takes a while.
599 self.failUnless(os.path.exists(TWISTD_PID_FILE))
600 return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "stop", c1], env=os.environ)
604 out, err, rc_or_sig = res
605 # the parent has exited by now
606 errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
607 self.failUnlessEqual(rc_or_sig, 0, errstr)
608 self.failUnlessEqual(out, "", errstr)
609 # self.failUnlessEqual(err, "", errstr) # See test_client_no_noise -- for now we ignore noise.
610 # the parent was supposed to poll and wait until it sees
611 # twistd.pid go away before it exits, so twistd.pid should be
613 self.failIf(os.path.exists(TWISTD_PID_FILE))