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.util.encodingutil import unicode_to_argv, unicode_to_output, get_filesystem_encoding
11 from allmydata.scripts import runner
13 from allmydata.test import common_util
18 srcfile = allmydata.__file__
19 srcdir = os.path.dirname(os.path.dirname(os.path.realpath(srcfile)))
20 rootdir = os.path.dirname(srcdir)
22 bintahoe = os.path.join(rootdir, 'bin', 'tahoe')
23 if sys.platform == "win32":
24 bintahoe += ".pyscript"
28 def skip_if_cannot_run_bintahoe(self):
29 if "cygwin" in sys.platform.lower():
30 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.")
31 if not os.path.exists(bintahoe):
32 raise unittest.SkipTest("The bin/tahoe script isn't to be found in the expected location (%s), 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. Perhaps running 'setup.py build' again will help." % (bintahoe,))
34 def skip_if_cannot_daemonize(self):
35 self.skip_if_cannot_run_bintahoe()
36 if runtime.platformType == "win32":
37 # twistd on windows doesn't daemonize. cygwin should work normally.
38 raise unittest.SkipTest("twistd does not fork under windows")
41 class BinTahoe(common_util.SignalMixin, unittest.TestCase, SkipMixin):
42 def test_the_right_code(self):
44 root_from_cwd = os.path.normcase(os.path.normpath(os.path.join(cwd, "..")))
45 root_from_test = os.path.normcase(os.path.normpath(rootdir))
47 same = (root_from_cwd == root_from_test)
50 same = os.path.samefile(root_from_cwd, root_from_test)
51 except AttributeError, e:
55 msg = ("We seem to be testing the code at %r,\n"
56 "(according to the source filename %r),\n"
57 "but expected to be testing the code at %r.\n"
58 % (root_from_test, srcfile, root_from_cwd))
59 if (not isinstance(cwd, unicode) and
60 cwd.decode(get_filesystem_encoding(), 'replace') != os.path.normcase(os.path.normpath(os.getcwdu()))):
61 msg += ("However, this may be a false alarm because the current directory path\n"
62 "is not representable in the filesystem encoding. Please run the tests\n"
63 "from the root of the Tahoe-LAFS distribution at a non-Unicode path.")
64 raise unittest.SkipTest(msg)
66 msg += "Please run the tests from the root of the Tahoe-LAFS distribution."
70 self.skip_if_cannot_run_bintahoe()
71 d = utils.getProcessOutputAndValue(bintahoe, args=["--version-and-path"], env=os.environ)
73 out, err, rc_or_sig = res
74 self.failUnlessEqual(rc_or_sig, 0, str(res))
76 # Fail unless the package is *this* version *and* was loaded from *this* source directory.
77 required_ver_and_path = "%s: %s (%s)" % (allmydata.__appname__, allmydata.__version__, srcdir)
78 self.failUnless(out.startswith(required_ver_and_path),
79 str((out, err, rc_or_sig, required_ver_and_path)))
81 self.failIfEqual(allmydata.__version__, "unknown",
82 "We don't know our version, because this distribution didn't come "
83 "with a _version.py and 'setup.py darcsver' hasn't been run.")
87 def test_unicode_arguments_and_output(self):
88 self.skip_if_cannot_run_bintahoe()
92 tricky_arg = unicode_to_argv(tricky, mangle=True)
93 tricky_out = unicode_to_output(tricky)
94 except UnicodeEncodeError:
95 raise unittest.SkipTest("A non-ASCII argument/output could not be encoded on this platform.")
97 d = utils.getProcessOutputAndValue(bintahoe, args=[tricky_arg], env=os.environ)
99 out, err, rc_or_sig = res
100 self.failUnlessEqual(rc_or_sig, 1, str(res))
101 self.failUnlessIn("Unknown command: "+tricky_out, out)
105 def test_run_with_python_options(self):
106 self.skip_if_cannot_run_bintahoe()
108 # -t is a harmless option that warns about tabs.
109 d = utils.getProcessOutputAndValue(sys.executable, args=['-t', bintahoe, '--version'],
112 out, err, rc_or_sig = res
113 self.failUnlessEqual(rc_or_sig, 0, str(res))
114 self.failUnless(out.startswith(allmydata.__appname__+':'), str(res))
118 def test_version_no_noise(self):
119 self.skip_if_cannot_run_bintahoe()
122 pkg_resources.require("Twisted>=9.0.0")
123 except pkg_resources.VersionConflict:
124 raise unittest.SkipTest("We pass this test only with Twisted >= v9.0.0")
126 d = utils.getProcessOutputAndValue(bintahoe, args=["--version"], env=os.environ)
128 out, err, rc_or_sig = res
129 self.failUnlessEqual(rc_or_sig, 0, str(res))
130 self.failUnless(out.startswith(allmydata.__appname__+':'), str(res))
131 self.failIfIn("DeprecationWarning", out, str(res))
132 self.failUnlessEqual(err, "", str(res))
137 class CreateNode(unittest.TestCase):
138 # exercise "tahoe create-node", create-introducer,
139 # create-key-generator, and create-stats-gatherer, by calling the
140 # corresponding code as a subroutine.
142 def workdir(self, name):
143 basedir = os.path.join("test_runner", "CreateNode", name)
144 fileutil.make_dirs(basedir)
147 def run_tahoe(self, argv):
148 out,err = StringIO(), StringIO()
149 rc = runner.runner(argv, stdout=out, stderr=err)
150 return rc, out.getvalue(), err.getvalue()
152 def do_create(self, kind):
153 basedir = self.workdir("test_" + kind)
154 command = "create-" + kind
155 is_client = kind in ("node", "client")
156 tac = is_client and "tahoe-client.tac" or ("tahoe-" + kind + ".tac")
158 n1 = os.path.join(basedir, command + "-n1")
159 argv = ["--quiet", command, "--basedir", n1]
160 rc, out, err = self.run_tahoe(argv)
161 self.failUnlessEqual(err, "")
162 self.failUnlessEqual(out, "")
163 self.failUnlessEqual(rc, 0)
164 self.failUnless(os.path.exists(n1))
165 self.failUnless(os.path.exists(os.path.join(n1, tac)))
168 # tahoe.cfg should exist, and should have storage enabled for
169 # 'create-node', and disabled for 'create-client'.
170 tahoe_cfg = os.path.join(n1, "tahoe.cfg")
171 self.failUnless(os.path.exists(tahoe_cfg))
172 content = open(tahoe_cfg).read()
174 self.failUnless("\n[storage]\nenabled = false\n" in content)
176 self.failUnless("\n[storage]\nenabled = true\n" in content)
178 # creating the node a second time should be rejected
179 rc, out, err = self.run_tahoe(argv)
180 self.failIfEqual(rc, 0, str((out, err, rc)))
181 self.failUnlessEqual(out, "")
182 self.failUnless("is not empty." in err)
184 # Fail if there is a non-empty line that doesn't end with a
186 for line in err.splitlines():
187 self.failIf(re.search("[\S][^\.!?]$", line), (line,))
189 # test that the non --basedir form works too
190 n2 = os.path.join(basedir, command + "-n2")
191 argv = ["--quiet", command, n2]
192 rc, out, err = self.run_tahoe(argv)
193 self.failUnlessEqual(err, "")
194 self.failUnlessEqual(out, "")
195 self.failUnlessEqual(rc, 0)
196 self.failUnless(os.path.exists(n2))
197 self.failUnless(os.path.exists(os.path.join(n2, tac)))
199 # test the --node-directory form
200 n3 = os.path.join(basedir, command + "-n3")
201 argv = ["--quiet", command, "--node-directory", n3]
202 rc, out, err = self.run_tahoe(argv)
203 self.failUnlessEqual(err, "")
204 self.failUnlessEqual(out, "")
205 self.failUnlessEqual(rc, 0)
206 self.failUnless(os.path.exists(n3))
207 self.failUnless(os.path.exists(os.path.join(n3, tac)))
209 # test the --multiple form
210 n4 = os.path.join(basedir, command + "-n4")
211 n5 = os.path.join(basedir, command + "-n5")
212 argv = ["--quiet", command, "--multiple", n4, n5]
213 rc, out, err = self.run_tahoe(argv)
214 self.failUnlessEqual(err, "")
215 self.failUnlessEqual(out, "")
216 self.failUnlessEqual(rc, 0)
217 self.failUnless(os.path.exists(n4))
218 self.failUnless(os.path.exists(os.path.join(n4, tac)))
219 self.failUnless(os.path.exists(n5))
220 self.failUnless(os.path.exists(os.path.join(n5, tac)))
222 # make sure it rejects too many arguments without --multiple
223 argv = [command, "basedir", "extraarg"]
224 self.failUnlessRaises(usage.UsageError,
228 # when creating a non-client, there is no default for the basedir
231 self.failUnlessRaises(usage.UsageError,
237 self.do_create("node")
239 def test_client(self):
240 # create-client should behave like create-node --no-storage.
241 self.do_create("client")
243 def test_introducer(self):
244 self.do_create("introducer")
246 def test_key_generator(self):
247 self.do_create("key-generator")
249 def test_stats_gatherer(self):
250 self.do_create("stats-gatherer")
252 def test_subcommands(self):
253 # no arguments should trigger a command listing, via UsageError
254 self.failUnlessRaises(usage.UsageError,
260 class RunNode(common_util.SignalMixin, unittest.TestCase, pollmixin.PollMixin,
262 # exercise "tahoe start", for both introducer, client node, and
263 # key-generator, by spawning "tahoe start" as a subprocess. This doesn't
264 # get us figleaf-based line-level coverage, but it does a better job of
265 # confirming that the user can actually run "./bin/tahoe start" and
266 # expect it to work. This verifies that bin/tahoe sets up PYTHONPATH and
267 # the like correctly.
269 # This doesn't work on cygwin (it hangs forever), so we skip this test
270 # when we're on cygwin. It is likely that "tahoe start" itself doesn't
271 # work on cygwin: twisted seems unable to provide a version of
272 # spawnProcess which really works there.
274 def workdir(self, name):
275 basedir = os.path.join("test_runner", "RunNode", name)
276 fileutil.make_dirs(basedir)
279 def test_introducer(self):
280 self.skip_if_cannot_daemonize()
281 basedir = self.workdir("test_introducer")
282 c1 = os.path.join(basedir, "c1")
283 HOTLINE_FILE = os.path.join(c1, "suicide_prevention_hotline")
284 TWISTD_PID_FILE = os.path.join(c1, "twistd.pid")
285 INTRODUCER_FURL_FILE = os.path.join(c1, "introducer.furl")
287 d = utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "create-introducer", "--basedir", c1], env=os.environ)
289 out, err, rc_or_sig = res
290 self.failUnlessEqual(rc_or_sig, 0)
291 # by writing this file, we get ten seconds before the node will
292 # exit. This insures that even if the test fails (and the 'stop'
293 # command doesn't work), the client should still terminate.
294 open(HOTLINE_FILE, "w").write("")
295 # now it's safe to start the node
298 def _then_start_the_node(res):
299 return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "start", c1], env=os.environ)
300 d.addCallback(_then_start_the_node)
303 out, err, rc_or_sig = res
305 open(HOTLINE_FILE, "w").write("")
306 errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
307 self.failUnlessEqual(rc_or_sig, 0, errstr)
308 self.failUnlessEqual(out, "", errstr)
309 # self.failUnlessEqual(err, "", errstr) # See test_client_no_noise -- for now we ignore noise.
311 # the parent (twistd) has exited. However, twistd writes the pid
312 # from the child, not the parent, so we can't expect twistd.pid
313 # to exist quite yet.
315 # the node is running, but it might not have made it past the
316 # first reactor turn yet, and if we kill it too early, it won't
317 # remove the twistd.pid file. So wait until it does something
318 # that we know it won't do until after the first turn.
321 def _node_has_started():
322 return os.path.exists(INTRODUCER_FURL_FILE)
323 d.addCallback(lambda res: self.poll(_node_has_started))
326 open(HOTLINE_FILE, "w").write("")
327 self.failUnless(os.path.exists(TWISTD_PID_FILE))
328 # rm this so we can detect when the second incarnation is ready
329 os.unlink(INTRODUCER_FURL_FILE)
330 return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "restart", c1], env=os.environ)
331 d.addCallback(_started)
334 out, err, rc_or_sig = res
335 open(HOTLINE_FILE, "w").write("")
336 errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
337 self.failUnlessEqual(rc_or_sig, 0, errstr)
338 self.failUnlessEqual(out, "", errstr)
339 # self.failUnlessEqual(err, "", errstr) # See test_client_no_noise -- for now we ignore noise.
342 # again, the second incarnation of the node might not be ready yet,
343 # so poll until it is
344 d.addCallback(lambda res: self.poll(_node_has_started))
346 # now we can kill it. TODO: On a slow machine, the node might kill
347 # itself before we get a chance too, especially if spawning the
348 # 'tahoe stop' command takes a while.
350 open(HOTLINE_FILE, "w").write("")
351 self.failUnless(os.path.exists(TWISTD_PID_FILE))
353 return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "stop", c1], env=os.environ)
356 def _after_stopping(res):
357 out, err, rc_or_sig = res
358 open(HOTLINE_FILE, "w").write("")
359 # the parent has exited by now
360 errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
361 self.failUnlessEqual(rc_or_sig, 0, errstr)
362 self.failUnlessEqual(out, "", errstr)
363 # self.failUnlessEqual(err, "", errstr) # See test_client_no_noise -- for now we ignore noise.
364 # the parent was supposed to poll and wait until it sees
365 # twistd.pid go away before it exits, so twistd.pid should be
367 self.failIf(os.path.exists(TWISTD_PID_FILE))
368 d.addCallback(_after_stopping)
370 def _remove_hotline(res):
371 os.unlink(HOTLINE_FILE)
373 d.addBoth(_remove_hotline)
375 test_introducer.timeout = 480 # This hit the 120-second timeout on "François Lenny-armv5tel", then it hit a 240-second timeout on our feisty2.5 buildslave: http://allmydata.org/buildbot/builders/feisty2.5/builds/2381/steps/test/logs/test.log
377 def test_client_no_noise(self):
378 self.skip_if_cannot_daemonize()
381 pkg_resources.require("Twisted>=9.0.0")
382 except pkg_resources.VersionConflict:
383 raise unittest.SkipTest("We pass this test only with Twisted >= v9.0.0")
384 basedir = self.workdir("test_client_no_noise")
385 c1 = os.path.join(basedir, "c1")
386 HOTLINE_FILE = os.path.join(c1, "suicide_prevention_hotline")
387 TWISTD_PID_FILE = os.path.join(c1, "twistd.pid")
388 PORTNUMFILE = os.path.join(c1, "client.port")
390 d = utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "create-client", "--basedir", c1, "--webport", "0"], env=os.environ)
392 out, err, rc_or_sig = res
393 errstr = "cc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
394 assert rc_or_sig == 0, errstr
395 self.failUnlessEqual(rc_or_sig, 0)
396 # By writing this file, we get forty seconds before the client will exit. This insures
397 # that even if the 'stop' command doesn't work (and the test fails), the client should
399 open(HOTLINE_FILE, "w").write("")
400 open(os.path.join(c1, "introducer.furl"), "w").write("pb://xrndsskn2zuuian5ltnxrte7lnuqdrkz@127.0.0.1:55617/introducer\n")
401 # now it's safe to start the node
405 return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "start", c1], env=os.environ)
406 d.addCallback(_start)
409 out, err, rc_or_sig = res
410 errstr = "cc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
411 open(HOTLINE_FILE, "w").write("")
412 self.failUnlessEqual(rc_or_sig, 0, errstr)
413 self.failUnlessEqual(out, "", errstr) # If you emit noise, you fail this test.
414 self.failUnlessEqual(err, "", errstr)
416 # the parent (twistd) has exited. However, twistd writes the pid
417 # from the child, not the parent, so we can't expect twistd.pid
418 # to exist quite yet.
420 # the node is running, but it might not have made it past the
421 # first reactor turn yet, and if we kill it too early, it won't
422 # remove the twistd.pid file. So wait until it does something
423 # that we know it won't do until after the first turn.
426 def _node_has_started():
427 return os.path.exists(PORTNUMFILE)
428 d.addCallback(lambda res: self.poll(_node_has_started))
430 # now we can kill it. TODO: On a slow machine, the node might kill
431 # itself before we get a chance too, especially if spawning the
432 # 'tahoe stop' command takes a while.
434 self.failUnless(os.path.exists(TWISTD_PID_FILE), (TWISTD_PID_FILE, os.listdir(os.path.dirname(TWISTD_PID_FILE))))
435 return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "stop", c1], env=os.environ)
439 def test_client(self):
440 self.skip_if_cannot_daemonize()
441 basedir = self.workdir("test_client")
442 c1 = os.path.join(basedir, "c1")
443 HOTLINE_FILE = os.path.join(c1, "suicide_prevention_hotline")
444 TWISTD_PID_FILE = os.path.join(c1, "twistd.pid")
445 PORTNUMFILE = os.path.join(c1, "client.port")
447 d = utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "create-node", "--basedir", c1, "--webport", "0"], env=os.environ)
449 out, err, rc_or_sig = res
450 self.failUnlessEqual(rc_or_sig, 0)
451 # By writing this file, we get sixty seconds before the client will exit. This insures
452 # that even if the 'stop' command doesn't work (and the test fails), the client should
454 open(HOTLINE_FILE, "w").write("")
455 open(os.path.join(c1, "introducer.furl"), "w").write("pb://xrndsskn2zuuian5ltnxrte7lnuqdrkz@127.0.0.1:55617/introducer\n")
456 # now it's safe to start the node
460 return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "start", c1], env=os.environ)
461 d.addCallback(_start)
464 out, err, rc_or_sig = res
465 open(HOTLINE_FILE, "w").write("")
466 errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
467 self.failUnlessEqual(rc_or_sig, 0, errstr)
468 self.failUnlessEqual(out, "", errstr)
469 # self.failUnlessEqual(err, "", errstr) # See test_client_no_noise -- for now we ignore noise.
471 # the parent (twistd) has exited. However, twistd writes the pid
472 # from the child, not the parent, so we can't expect twistd.pid
473 # to exist quite yet.
475 # the node is running, but it might not have made it past the
476 # first reactor turn yet, and if we kill it too early, it won't
477 # remove the twistd.pid file. So wait until it does something
478 # that we know it won't do until after the first turn.
481 def _node_has_started():
482 return os.path.exists(PORTNUMFILE)
483 d.addCallback(lambda res: self.poll(_node_has_started))
486 open(HOTLINE_FILE, "w").write("")
487 self.failUnless(os.path.exists(TWISTD_PID_FILE))
488 # rm this so we can detect when the second incarnation is ready
489 os.unlink(PORTNUMFILE)
491 return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "restart", c1], env=os.environ)
492 d.addCallback(_started)
495 out, err, rc_or_sig = res
497 open(HOTLINE_FILE, "w").write("")
498 errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
499 self.failUnlessEqual(rc_or_sig, 0, errstr)
500 self.failUnlessEqual(out, "", errstr)
501 # self.failUnlessEqual(err, "", errstr) # See test_client_no_noise -- for now we ignore noise.
504 # again, the second incarnation of the node might not be ready yet,
505 # so poll until it is
506 d.addCallback(lambda res: self.poll(_node_has_started))
508 # now we can kill it. TODO: On a slow machine, the node might kill
509 # itself before we get a chance too, especially if spawning the
510 # 'tahoe stop' command takes a while.
512 open(HOTLINE_FILE, "w").write("")
513 self.failUnless(os.path.exists(TWISTD_PID_FILE), (TWISTD_PID_FILE, os.listdir(os.path.dirname(TWISTD_PID_FILE))))
514 return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "stop", c1], env=os.environ)
518 out, err, rc_or_sig = res
520 open(HOTLINE_FILE, "w").write("")
521 # the parent has exited by now
522 errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
523 self.failUnlessEqual(rc_or_sig, 0, errstr)
524 self.failUnlessEqual(out, "", errstr)
525 # self.failUnlessEqual(err, "", errstr) # See test_client_no_noise -- for now we ignore noise.
526 # the parent was supposed to poll and wait until it sees
527 # twistd.pid go away before it exits, so twistd.pid should be
529 self.failIf(os.path.exists(TWISTD_PID_FILE))
531 def _remove_hotline(res):
532 os.unlink(HOTLINE_FILE)
534 d.addBoth(_remove_hotline)
537 def test_baddir(self):
538 self.skip_if_cannot_daemonize()
539 basedir = self.workdir("test_baddir")
540 fileutil.make_dirs(basedir)
542 d = utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "start", "--basedir", basedir], env=os.environ)
544 out, err, rc_or_sig = res
545 self.failUnlessEqual(rc_or_sig, 1)
546 self.failUnless("does not look like a node directory" in err, err)
549 def _then_stop_it(res):
550 return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "stop", "--basedir", basedir], env=os.environ)
551 d.addCallback(_then_stop_it)
554 out, err, rc_or_sig = res
555 self.failUnlessEqual(rc_or_sig, 2)
556 self.failUnless("does not look like a running node directory" in err)
559 def _then_start_in_bogus_basedir(res):
560 not_a_dir = os.path.join(basedir, "bogus")
561 return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "start", "--basedir", not_a_dir], env=os.environ)
562 d.addCallback(_then_start_in_bogus_basedir)
565 out, err, rc_or_sig = res
566 self.failUnlessEqual(rc_or_sig, 1)
567 self.failUnless("does not look like a directory at all" in err, err)
571 def test_keygen(self):
572 self.skip_if_cannot_daemonize()
573 basedir = self.workdir("test_keygen")
574 c1 = os.path.join(basedir, "c1")
575 TWISTD_PID_FILE = os.path.join(c1, "twistd.pid")
576 KEYGEN_FURL_FILE = os.path.join(c1, "key_generator.furl")
578 d = utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "create-key-generator", "--basedir", c1], env=os.environ)
580 out, err, rc_or_sig = res
581 self.failUnlessEqual(rc_or_sig, 0)
585 return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "start", c1], env=os.environ)
586 d.addCallback(_start)
589 out, err, rc_or_sig = res
590 errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
591 self.failUnlessEqual(rc_or_sig, 0, errstr)
592 self.failUnlessEqual(out, "", errstr)
593 # self.failUnlessEqual(err, "", errstr) # See test_client_no_noise -- for now we ignore noise.
595 # the parent (twistd) has exited. However, twistd writes the pid
596 # from the child, not the parent, so we can't expect twistd.pid
597 # to exist quite yet.
599 # the node is running, but it might not have made it past the
600 # first reactor turn yet, and if we kill it too early, it won't
601 # remove the twistd.pid file. So wait until it does something
602 # that we know it won't do until after the first turn.
605 def _node_has_started():
606 return os.path.exists(KEYGEN_FURL_FILE)
607 d.addCallback(lambda res: self.poll(_node_has_started))
610 self.failUnless(os.path.exists(TWISTD_PID_FILE))
611 # rm this so we can detect when the second incarnation is ready
612 os.unlink(KEYGEN_FURL_FILE)
613 return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "restart", c1], env=os.environ)
614 d.addCallback(_started)
617 out, err, rc_or_sig = res
618 errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
619 self.failUnlessEqual(rc_or_sig, 0, errstr)
620 self.failUnlessEqual(out, "", errstr)
621 # self.failUnlessEqual(err, "", errstr) # See test_client_no_noise -- for now we ignore noise.
624 # again, the second incarnation of the node might not be ready yet,
625 # so poll until it is
626 d.addCallback(lambda res: self.poll(_node_has_started))
628 # now we can kill it. TODO: On a slow machine, the node might kill
629 # itself before we get a chance too, especially if spawning the
630 # 'tahoe stop' command takes a while.
632 self.failUnless(os.path.exists(TWISTD_PID_FILE))
633 return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "stop", c1], env=os.environ)
637 out, err, rc_or_sig = res
638 # the parent has exited by now
639 errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
640 self.failUnlessEqual(rc_or_sig, 0, errstr)
641 self.failUnlessEqual(out, "", errstr)
642 # self.failUnlessEqual(err, "", errstr) # See test_client_no_noise -- for now we ignore noise.
643 # the parent was supposed to poll and wait until it sees
644 # twistd.pid go away before it exits, so twistd.pid should be
646 self.failIf(os.path.exists(TWISTD_PID_FILE))