2 from twisted.trial import unittest
4 from twisted.python import usage, runtime
5 from twisted.internet import utils
6 import os.path, re, sys
7 from cStringIO import StringIO
8 from allmydata.util import fileutil, pollmixin
9 from allmydata.scripts import runner
11 from allmydata.test import common_util
14 bintahoe = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(allmydata.__file__))), 'bin', 'tahoe')
15 if sys.platform == "win32":
18 class SkipOnCygwinMixin:
19 def skip_on_cygwin(self):
20 if "cygwin" in sys.platform.lower():
21 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.")
23 class TheRightCode(unittest.TestCase, common_util.SignalMixin,
27 if not os.path.exists(bintahoe):
28 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.")
29 d = utils.getProcessOutputAndValue(bintahoe, args=["--version-and-path"], env=os.environ)
31 out, err, rc_or_sig = res
32 self.failUnlessEqual(rc_or_sig, 0)
34 # Fail unless the allmydata-tahoe package is *this* version *and* was loaded from *this* source directory.
35 required_ver_and_path = "allmydata-tahoe: %s (%s)" % (allmydata.__version__, os.path.dirname(os.path.dirname(allmydata.__file__)))
36 self.failUnless(out.startswith(required_ver_and_path), (out, err, rc_or_sig, required_ver_and_path))
40 class CreateNode(unittest.TestCase):
41 # exercise "tahoe create-client", create-introducer,
42 # create-key-generator, and create-stats-gatherer, by calling the
43 # corresponding code as a subroutine.
45 def workdir(self, name):
46 basedir = os.path.join("test_runner", "CreateNode", name)
47 fileutil.make_dirs(basedir)
50 def run_tahoe(self, argv):
51 out,err = StringIO(), StringIO()
52 rc = runner.runner(argv, stdout=out, stderr=err)
53 return rc, out.getvalue(), err.getvalue()
55 def test_client(self):
56 basedir = self.workdir("test_client")
57 c1 = os.path.join(basedir, "c1")
58 argv = ["--quiet", "create-client", "--basedir", c1]
59 rc, out, err = self.run_tahoe(argv)
60 self.failUnlessEqual(err, "")
61 self.failUnlessEqual(out, "")
62 self.failUnlessEqual(rc, 0)
63 self.failUnless(os.path.exists(c1))
64 self.failUnless(os.path.exists(os.path.join(c1, "tahoe-client.tac")))
66 # creating the client a second time should be rejected
67 rc, out, err = self.run_tahoe(argv)
68 self.failIfEqual(rc, 0, str((out, err, rc)))
69 self.failUnlessEqual(out, "")
70 self.failUnless("is not empty." in err)
72 # Fail if there is a non-empty line that doesn't end with a
74 for line in err.splitlines():
75 self.failIf(re.search("[\S][^\.!?]$", line), (line,))
77 # test that the non --basedir form works too
78 c2 = os.path.join(basedir, "c2")
79 argv = ["--quiet", "create-client", c2]
80 rc, out, err = self.run_tahoe(argv)
81 self.failUnless(os.path.exists(c2))
82 self.failUnless(os.path.exists(os.path.join(c2, "tahoe-client.tac")))
84 # make sure it rejects too many arguments
85 argv = ["create-client", "basedir", "extraarg"]
86 self.failUnlessRaises(usage.UsageError,
90 def test_introducer(self):
91 basedir = self.workdir("test_introducer")
92 c1 = os.path.join(basedir, "c1")
93 argv = ["--quiet", "create-introducer", "--basedir", c1]
94 rc, out, err = self.run_tahoe(argv)
95 self.failUnlessEqual(err, "", err)
96 self.failUnlessEqual(out, "")
97 self.failUnlessEqual(rc, 0)
98 self.failUnless(os.path.exists(c1))
99 self.failUnless(os.path.exists(os.path.join(c1,"tahoe-introducer.tac")))
101 # creating the introducer a second time should be rejected
102 rc, out, err = self.run_tahoe(argv)
103 self.failIfEqual(rc, 0)
104 self.failUnlessEqual(out, "")
105 self.failUnless("is not empty" in err)
107 # Fail if there is a non-empty line that doesn't end with a
109 for line in err.splitlines():
110 self.failIf(re.search("[\S][^\.!?]$", line), (line,))
112 # test the non --basedir form
113 c2 = os.path.join(basedir, "c2")
114 argv = ["--quiet", "create-introducer", c2]
115 rc, out, err = self.run_tahoe(argv)
116 self.failUnlessEqual(err, "", err)
117 self.failUnlessEqual(out, "")
118 self.failUnlessEqual(rc, 0)
119 self.failUnless(os.path.exists(c2))
120 self.failUnless(os.path.exists(os.path.join(c2,"tahoe-introducer.tac")))
122 # reject extra arguments
123 argv = ["create-introducer", "basedir", "extraarg"]
124 self.failUnlessRaises(usage.UsageError,
127 # and require basedir to be provided in some form
128 argv = ["create-introducer"]
129 self.failUnlessRaises(usage.UsageError,
133 def test_key_generator(self):
134 basedir = self.workdir("test_key_generator")
135 kg1 = os.path.join(basedir, "kg1")
136 argv = ["--quiet", "create-key-generator", "--basedir", kg1]
137 rc, out, err = self.run_tahoe(argv)
138 self.failUnlessEqual(err, "")
139 self.failUnlessEqual(out, "")
140 self.failUnlessEqual(rc, 0)
141 self.failUnless(os.path.exists(kg1))
142 self.failUnless(os.path.exists(os.path.join(kg1, "tahoe-key-generator.tac")))
144 # creating it a second time should be rejected
145 rc, out, err = self.run_tahoe(argv)
146 self.failIfEqual(rc, 0, str((out, err, rc)))
147 self.failUnlessEqual(out, "")
148 self.failUnless("is not empty." in err)
150 # make sure it rejects too many arguments
151 argv = ["create-key-generator", "basedir", "extraarg"]
152 self.failUnlessRaises(usage.UsageError,
156 # make sure it rejects a missing basedir specification
157 argv = ["create-key-generator"]
158 rc, out, err = self.run_tahoe(argv)
159 self.failIfEqual(rc, 0, str((out, err, rc)))
160 self.failUnlessEqual(out, "")
161 self.failUnless("a basedir was not provided" in err)
163 def test_stats_gatherer(self):
164 basedir = self.workdir("test_stats_gatherer")
165 sg1 = os.path.join(basedir, "sg1")
166 argv = ["--quiet", "create-stats-gatherer", "--basedir", sg1]
167 rc, out, err = self.run_tahoe(argv)
168 self.failUnlessEqual(err, "")
169 self.failUnlessEqual(out, "")
170 self.failUnlessEqual(rc, 0)
171 self.failUnless(os.path.exists(sg1))
172 self.failUnless(os.path.exists(os.path.join(sg1, "tahoe-stats-gatherer.tac")))
174 # creating it a second time should be rejected
175 rc, out, err = self.run_tahoe(argv)
176 self.failIfEqual(rc, 0, str((out, err, rc)))
177 self.failUnlessEqual(out, "")
178 self.failUnless("is not empty." in err)
180 # test the non --basedir form
181 kg2 = os.path.join(basedir, "kg2")
182 argv = ["--quiet", "create-stats-gatherer", kg2]
183 rc, out, err = self.run_tahoe(argv)
184 self.failUnlessEqual(err, "", err)
185 self.failUnlessEqual(out, "")
186 self.failUnlessEqual(rc, 0)
187 self.failUnless(os.path.exists(kg2))
188 self.failUnless(os.path.exists(os.path.join(kg2,"tahoe-stats-gatherer.tac")))
190 # make sure it rejects too many arguments
191 argv = ["create-stats-gatherer", "basedir", "extraarg"]
192 self.failUnlessRaises(usage.UsageError,
196 # make sure it rejects a missing basedir specification
197 argv = ["create-stats-gatherer"]
198 rc, out, err = self.run_tahoe(argv)
199 self.failIfEqual(rc, 0, str((out, err, rc)))
200 self.failUnlessEqual(out, "")
201 self.failUnless("a basedir was not provided" in err)
203 def test_subcommands(self):
204 # no arguments should trigger a command listing, via UsageError
205 self.failUnlessRaises(usage.UsageError,
211 class RunNode(unittest.TestCase, pollmixin.PollMixin, common_util.SignalMixin,
213 # exercise "tahoe start", for both introducer, client node, and
214 # key-generator, by spawning "tahoe start" as a subprocess. This doesn't
215 # get us figleaf-based line-level coverage, but it does a better job of
216 # confirming that the user can actually run "./bin/tahoe start" and
217 # expect it to work. This verifies that bin/tahoe sets up PYTHONPATH and
218 # the like correctly.
220 # This doesn't work on cygwin (it hangs forever), so we skip this test
221 # when we're on cygwin. It is likely that "tahoe start" itself doesn't
222 # work on cygwin: twisted seems unable to provide a version of
223 # spawnProcess which really works there.
225 def workdir(self, name):
226 basedir = os.path.join("test_runner", "RunNode", name)
227 fileutil.make_dirs(basedir)
230 def test_introducer(self):
231 self.skip_on_cygwin()
232 if not os.path.exists(bintahoe):
233 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.")
234 if runtime.platformType == "win32":
235 # twistd on windows doesn't daemonize. cygwin works normally.
236 raise unittest.SkipTest("twistd does not fork under windows")
237 basedir = self.workdir("test_introducer")
238 c1 = os.path.join(basedir, "c1")
239 HOTLINE_FILE = os.path.join(c1, "suicide_prevention_hotline")
240 TWISTD_PID_FILE = os.path.join(c1, "twistd.pid")
241 INTRODUCER_FURL_FILE = os.path.join(c1, "introducer.furl")
243 d = utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "create-introducer", "--basedir", c1], env=os.environ)
245 out, err, rc_or_sig = res
246 self.failUnlessEqual(rc_or_sig, 0)
247 # by writing this file, we get ten seconds before the node will
248 # exit. This insures that even if the test fails (and the 'stop'
249 # command doesn't work), the client should still terminate.
250 open(HOTLINE_FILE, "w").write("")
251 # now it's safe to start the node
254 def _then_start_the_node(res):
255 return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "start", c1], env=os.environ)
256 d.addCallback(_then_start_the_node)
259 out, err, rc_or_sig = res
261 open(HOTLINE_FILE, "w").write("")
262 errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
263 self.failUnlessEqual(rc_or_sig, 0, errstr)
264 self.failUnlessEqual(out, "", errstr)
265 # self.failUnlessEqual(err, "", errstr) # See test_client_no_noise -- for now we ignore noise.
267 # the parent (twistd) has exited. However, twistd writes the pid
268 # from the child, not the parent, so we can't expect twistd.pid
269 # to exist quite yet.
271 # the node is running, but it might not have made it past the
272 # first reactor turn yet, and if we kill it too early, it won't
273 # remove the twistd.pid file. So wait until it does something
274 # that we know it won't do until after the first turn.
277 def _node_has_started():
278 return os.path.exists(INTRODUCER_FURL_FILE)
279 d.addCallback(lambda res: self.poll(_node_has_started))
282 open(HOTLINE_FILE, "w").write("")
283 self.failUnless(os.path.exists(TWISTD_PID_FILE))
284 # rm this so we can detect when the second incarnation is ready
285 os.unlink(INTRODUCER_FURL_FILE)
286 return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "restart", c1], env=os.environ)
287 d.addCallback(_started)
290 out, err, rc_or_sig = res
291 open(HOTLINE_FILE, "w").write("")
292 errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
293 self.failUnlessEqual(rc_or_sig, 0, errstr)
294 self.failUnlessEqual(out, "", errstr)
295 # self.failUnlessEqual(err, "", errstr) # See test_client_no_noise -- for now we ignore noise.
298 # again, the second incarnation of the node might not be ready yet,
299 # so poll until it is
300 d.addCallback(lambda res: self.poll(_node_has_started))
302 # now we can kill it. TODO: On a slow machine, the node might kill
303 # itself before we get a chance too, especially if spawning the
304 # 'tahoe stop' command takes a while.
306 open(HOTLINE_FILE, "w").write("")
307 self.failUnless(os.path.exists(TWISTD_PID_FILE))
309 return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "stop", c1], env=os.environ)
312 def _after_stopping(res):
313 out, err, rc_or_sig = res
314 open(HOTLINE_FILE, "w").write("")
315 # the parent has exited by now
316 errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
317 self.failUnlessEqual(rc_or_sig, 0, errstr)
318 self.failUnlessEqual(out, "", errstr)
319 # self.failUnlessEqual(err, "", errstr) # See test_client_no_noise -- for now we ignore noise.
320 # the parent was supposed to poll and wait until it sees
321 # twistd.pid go away before it exits, so twistd.pid should be
323 self.failIf(os.path.exists(TWISTD_PID_FILE))
324 d.addCallback(_after_stopping)
326 def _remove_hotline(res):
327 os.unlink(HOTLINE_FILE)
329 d.addBoth(_remove_hotline)
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 forty 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))