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(unittest.TestCase, common_util.SignalMixin,
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(unittest.TestCase, pollmixin.PollMixin, common_util.SignalMixin,
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)
331 def test_client_no_noise(self):
332 self.skip_on_cygwin()
333 if not os.path.exists(bintahoe):
334 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.")
335 basedir = self.workdir("test_client_no_noise")
336 c1 = os.path.join(basedir, "c1")
337 HOTLINE_FILE = os.path.join(c1, "suicide_prevention_hotline")
338 TWISTD_PID_FILE = os.path.join(c1, "twistd.pid")
339 PORTNUMFILE = os.path.join(c1, "client.port")
341 d = utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "create-client", "--basedir", c1, "--webport", "0"], env=os.environ)
343 out, err, rc_or_sig = res
344 errstr = "cc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
345 assert rc_or_sig == 0, errstr
346 self.failUnlessEqual(rc_or_sig, 0)
347 # By writing this file, we get forty seconds before the client will exit. This insures
348 # that even if the 'stop' command doesn't work (and the test fails), the client should
350 open(HOTLINE_FILE, "w").write("")
351 open(os.path.join(c1, "introducer.furl"), "w").write("pb://xrndsskn2zuuian5ltnxrte7lnuqdrkz@127.0.0.1:55617/introducer\n")
352 # now it's safe to start the node
356 return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "start", c1], env=os.environ)
357 d.addCallback(_start)
360 out, err, rc_or_sig = res
361 errstr = "cc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
362 open(HOTLINE_FILE, "w").write("")
363 self.failUnlessEqual(rc_or_sig, 0, errstr)
364 self.failUnlessEqual(out, "", errstr) # If you emit noise, you fail this test.
365 self.failUnlessEqual(err, "", errstr)
367 # the parent (twistd) has exited. However, twistd writes the pid
368 # from the child, not the parent, so we can't expect twistd.pid
369 # to exist quite yet.
371 # the node is running, but it might not have made it past the
372 # first reactor turn yet, and if we kill it too early, it won't
373 # remove the twistd.pid file. So wait until it does something
374 # that we know it won't do until after the first turn.
377 def _node_has_started():
378 return os.path.exists(PORTNUMFILE)
379 d.addCallback(lambda res: self.poll(_node_has_started))
381 # now we can kill it. TODO: On a slow machine, the node might kill
382 # itself before we get a chance too, especially if spawning the
383 # 'tahoe stop' command takes a while.
385 self.failUnless(os.path.exists(TWISTD_PID_FILE), (TWISTD_PID_FILE, os.listdir(os.path.dirname(TWISTD_PID_FILE))))
386 return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "stop", c1], env=os.environ)
389 test_client_no_noise.todo = "We submitted a patch to Nevow to silence this warning: http://divmod.org/trac/ticket/2830"
391 def test_client(self):
392 self.skip_on_cygwin()
393 if not os.path.exists(bintahoe):
394 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.")
395 if runtime.platformType == "win32":
396 # twistd on windows doesn't daemonize. cygwin works normally.
397 raise unittest.SkipTest("twistd does not fork under windows")
398 basedir = self.workdir("test_client")
399 c1 = os.path.join(basedir, "c1")
400 HOTLINE_FILE = os.path.join(c1, "suicide_prevention_hotline")
401 TWISTD_PID_FILE = os.path.join(c1, "twistd.pid")
402 PORTNUMFILE = os.path.join(c1, "client.port")
404 d = utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "create-client", "--basedir", c1, "--webport", "0"], env=os.environ)
406 out, err, rc_or_sig = res
407 self.failUnlessEqual(rc_or_sig, 0)
408 # By writing this file, we get sixty seconds before the client will exit. This insures
409 # that even if the 'stop' command doesn't work (and the test fails), the client should
411 open(HOTLINE_FILE, "w").write("")
412 open(os.path.join(c1, "introducer.furl"), "w").write("pb://xrndsskn2zuuian5ltnxrte7lnuqdrkz@127.0.0.1:55617/introducer\n")
413 # now it's safe to start the node
417 return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "start", c1], env=os.environ)
418 d.addCallback(_start)
421 out, err, rc_or_sig = res
422 open(HOTLINE_FILE, "w").write("")
423 errstr = "cc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
424 self.failUnlessEqual(rc_or_sig, 0, errstr)
425 self.failUnlessEqual(out, "", errstr)
426 # self.failUnlessEqual(err, "", errstr) # See test_client_no_noise -- for now we ignore noise.
428 # the parent (twistd) has exited. However, twistd writes the pid
429 # from the child, not the parent, so we can't expect twistd.pid
430 # to exist quite yet.
432 # the node is running, but it might not have made it past the
433 # first reactor turn yet, and if we kill it too early, it won't
434 # remove the twistd.pid file. So wait until it does something
435 # that we know it won't do until after the first turn.
438 def _node_has_started():
439 return os.path.exists(PORTNUMFILE)
440 d.addCallback(lambda res: self.poll(_node_has_started))
443 open(HOTLINE_FILE, "w").write("")
444 self.failUnless(os.path.exists(TWISTD_PID_FILE))
445 # rm this so we can detect when the second incarnation is ready
446 os.unlink(PORTNUMFILE)
448 return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "restart", c1], env=os.environ)
449 d.addCallback(_started)
452 out, err, rc_or_sig = res
454 open(HOTLINE_FILE, "w").write("")
455 errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
456 self.failUnlessEqual(rc_or_sig, 0, errstr)
457 self.failUnlessEqual(out, "", errstr)
458 # self.failUnlessEqual(err, "", errstr) # See test_client_no_noise -- for now we ignore noise.
461 # again, the second incarnation of the node might not be ready yet,
462 # so poll until it is
463 d.addCallback(lambda res: self.poll(_node_has_started))
465 # now we can kill it. TODO: On a slow machine, the node might kill
466 # itself before we get a chance too, especially if spawning the
467 # 'tahoe stop' command takes a while.
469 open(HOTLINE_FILE, "w").write("")
470 self.failUnless(os.path.exists(TWISTD_PID_FILE), (TWISTD_PID_FILE, os.listdir(os.path.dirname(TWISTD_PID_FILE))))
471 return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "stop", c1], env=os.environ)
475 out, err, rc_or_sig = res
477 open(HOTLINE_FILE, "w").write("")
478 # the parent has exited by now
479 errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
480 self.failUnlessEqual(rc_or_sig, 0, errstr)
481 self.failUnlessEqual(out, "", errstr)
482 # self.failUnlessEqual(err, "", errstr) # See test_client_no_noise -- for now we ignore noise.
483 # the parent was supposed to poll and wait until it sees
484 # twistd.pid go away before it exits, so twistd.pid should be
486 self.failIf(os.path.exists(TWISTD_PID_FILE))
488 def _remove_hotline(res):
489 os.unlink(HOTLINE_FILE)
491 d.addBoth(_remove_hotline)
494 def test_baddir(self):
495 self.skip_on_cygwin()
496 if not os.path.exists(bintahoe):
497 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.")
498 basedir = self.workdir("test_baddir")
499 fileutil.make_dirs(basedir)
501 d = utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "start", "--basedir", basedir], env=os.environ)
503 out, err, rc_or_sig = res
504 self.failUnlessEqual(rc_or_sig, 1)
505 self.failUnless("does not look like a node directory" in err)
508 def _then_stop_it(res):
509 return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "stop", "--basedir", basedir], env=os.environ)
510 d.addCallback(_then_stop_it)
513 out, err, rc_or_sig = res
514 self.failUnlessEqual(rc_or_sig, 2)
515 self.failUnless("does not look like a running node directory" in err)
518 def _then_start_in_bogus_basedir(res):
519 not_a_dir = os.path.join(basedir, "bogus")
520 return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "start", "--basedir", not_a_dir], env=os.environ)
521 d.addCallback(_then_start_in_bogus_basedir)
524 out, err, rc_or_sig = res
525 self.failUnlessEqual(rc_or_sig, 1)
526 self.failUnless("does not look like a directory at all" in err, err)
530 def test_keygen(self):
531 self.skip_on_cygwin()
532 if not os.path.exists(bintahoe):
533 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.")
534 if runtime.platformType == "win32":
535 # twistd on windows doesn't daemonize. cygwin works normally.
536 raise unittest.SkipTest("twistd does not fork under windows")
537 basedir = self.workdir("test_keygen")
538 c1 = os.path.join(basedir, "c1")
539 TWISTD_PID_FILE = os.path.join(c1, "twistd.pid")
540 KEYGEN_FURL_FILE = os.path.join(c1, "key_generator.furl")
542 d = utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "create-key-generator", "--basedir", c1], env=os.environ)
544 out, err, rc_or_sig = res
545 self.failUnlessEqual(rc_or_sig, 0)
549 return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "start", c1], env=os.environ)
550 d.addCallback(_start)
553 out, err, rc_or_sig = res
554 errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
555 self.failUnlessEqual(rc_or_sig, 0, errstr)
556 self.failUnlessEqual(out, "", errstr)
557 # self.failUnlessEqual(err, "", errstr) # See test_client_no_noise -- for now we ignore noise.
559 # the parent (twistd) has exited. However, twistd writes the pid
560 # from the child, not the parent, so we can't expect twistd.pid
561 # to exist quite yet.
563 # the node is running, but it might not have made it past the
564 # first reactor turn yet, and if we kill it too early, it won't
565 # remove the twistd.pid file. So wait until it does something
566 # that we know it won't do until after the first turn.
569 def _node_has_started():
570 return os.path.exists(KEYGEN_FURL_FILE)
571 d.addCallback(lambda res: self.poll(_node_has_started))
574 self.failUnless(os.path.exists(TWISTD_PID_FILE))
575 # rm this so we can detect when the second incarnation is ready
576 os.unlink(KEYGEN_FURL_FILE)
577 return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "restart", c1], env=os.environ)
578 d.addCallback(_started)
581 out, err, rc_or_sig = res
582 errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
583 self.failUnlessEqual(rc_or_sig, 0, errstr)
584 self.failUnlessEqual(out, "", errstr)
585 # self.failUnlessEqual(err, "", errstr) # See test_client_no_noise -- for now we ignore noise.
588 # again, the second incarnation of the node might not be ready yet,
589 # so poll until it is
590 d.addCallback(lambda res: self.poll(_node_has_started))
592 # now we can kill it. TODO: On a slow machine, the node might kill
593 # itself before we get a chance too, especially if spawning the
594 # 'tahoe stop' command takes a while.
596 self.failUnless(os.path.exists(TWISTD_PID_FILE))
597 return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "stop", c1], env=os.environ)
601 out, err, rc_or_sig = res
602 # the parent has exited by now
603 errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
604 self.failUnlessEqual(rc_or_sig, 0, errstr)
605 self.failUnlessEqual(out, "", errstr)
606 # self.failUnlessEqual(err, "", errstr) # See test_client_no_noise -- for now we ignore noise.
607 # the parent was supposed to poll and wait until it sees
608 # twistd.pid go away before it exits, so twistd.pid should be
610 self.failIf(os.path.exists(TWISTD_PID_FILE))