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 if os.path.normcase(os.path.basename(srcdir)) == 'site-packages':
21 srcdir = os.path.dirname(srcdir)
22 if re.search(r'python.+\..+', os.path.normcase(os.path.basename(srcdir))):
23 srcdir = os.path.dirname(srcdir)
25 rootdir = os.path.dirname(srcdir)
27 bintahoe = os.path.join(rootdir, 'bin', 'tahoe')
28 if sys.platform == "win32":
29 bintahoe += ".pyscript"
30 if not os.path.exists(bintahoe):
31 alt_bintahoe = os.path.join(rootdir, 'Scripts', 'tahoe.pyscript')
32 if os.path.exists(alt_bintahoe):
33 bintahoe = alt_bintahoe
37 def skip_if_cannot_run_bintahoe(self):
38 if "cygwin" in sys.platform.lower():
39 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.")
40 if not os.path.exists(bintahoe):
41 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,))
43 def skip_if_cannot_daemonize(self):
44 self.skip_if_cannot_run_bintahoe()
45 if runtime.platformType == "win32":
46 # twistd on windows doesn't daemonize. cygwin should work normally.
47 raise unittest.SkipTest("twistd does not fork under windows")
50 class BinTahoe(common_util.SignalMixin, unittest.TestCase, SkipMixin):
51 def test_the_right_code(self):
53 root_from_cwd = os.path.normcase(os.path.normpath(os.path.join(cwd, "..")))
54 root_from_test = os.path.normcase(os.path.normpath(rootdir))
56 same = (root_from_cwd == root_from_test)
59 same = os.path.samefile(root_from_cwd, root_from_test)
60 except AttributeError, e:
64 msg = ("We seem to be testing the code at %r,\n"
65 "(according to the source filename %r),\n"
66 "but expected to be testing the code at %r.\n"
67 % (root_from_test, srcfile, root_from_cwd))
68 if (not isinstance(cwd, unicode) and
69 (os.path.normcase(os.path.normpath(cwd))).decode(get_filesystem_encoding(), 'replace')
70 != os.path.normcase(os.path.normpath(os.getcwdu()))):
71 msg += ("However, this may be a false alarm because the current directory path\n"
72 "is not representable in the filesystem encoding. Please run the tests\n"
73 "from the root of the Tahoe-LAFS distribution at a non-Unicode path.")
74 raise unittest.SkipTest(msg)
76 msg += "Please run the tests from the root of the Tahoe-LAFS distribution."
80 self.skip_if_cannot_run_bintahoe()
81 d = utils.getProcessOutputAndValue(bintahoe, args=["--version-and-path"], env=os.environ)
83 out, err, rc_or_sig = res
84 self.failUnlessEqual(rc_or_sig, 0, str(res))
86 # Fail unless the package is *this* version *and* was loaded from *this* source directory.
87 required_ver_and_path = "%s: %s (%s)" % (allmydata.__appname__, allmydata.__version__, srcdir)
88 self.failUnless(out.startswith(required_ver_and_path),
89 str((out, err, rc_or_sig, required_ver_and_path)))
91 self.failIfEqual(allmydata.__version__, "unknown",
92 "We don't know our version, because this distribution didn't come "
93 "with a _version.py and 'setup.py darcsver' hasn't been run.")
97 def test_unicode_arguments_and_output(self):
98 self.skip_if_cannot_run_bintahoe()
102 tricky_arg = unicode_to_argv(tricky, mangle=True)
103 tricky_out = unicode_to_output(tricky)
104 except UnicodeEncodeError:
105 raise unittest.SkipTest("A non-ASCII argument/output could not be encoded on this platform.")
107 d = utils.getProcessOutputAndValue(bintahoe, args=[tricky_arg], env=os.environ)
109 out, err, rc_or_sig = res
110 self.failUnlessEqual(rc_or_sig, 1, str(res))
111 self.failUnlessIn("Unknown command: "+tricky_out, out)
115 def test_run_with_python_options(self):
116 self.skip_if_cannot_run_bintahoe()
118 # -t is a harmless option that warns about tabs.
119 d = utils.getProcessOutputAndValue(sys.executable, args=['-t', bintahoe, '--version'],
122 out, err, rc_or_sig = res
123 self.failUnlessEqual(rc_or_sig, 0, str(res))
124 self.failUnless(out.startswith(allmydata.__appname__+':'), str(res))
128 def test_version_no_noise(self):
129 self.skip_if_cannot_run_bintahoe()
132 pkg_resources.require("Twisted>=9.0.0")
133 except pkg_resources.VersionConflict:
134 raise unittest.SkipTest("We pass this test only with Twisted >= v9.0.0")
136 d = utils.getProcessOutputAndValue(bintahoe, args=["--version"], env=os.environ)
138 out, err, rc_or_sig = res
139 self.failUnlessEqual(rc_or_sig, 0, str(res))
140 self.failUnless(out.startswith(allmydata.__appname__+':'), str(res))
141 self.failIfIn("DeprecationWarning", out, str(res))
142 self.failUnlessEqual(err, "", str(res))
147 class CreateNode(unittest.TestCase):
148 # exercise "tahoe create-node", create-introducer,
149 # create-key-generator, and create-stats-gatherer, by calling the
150 # corresponding code as a subroutine.
152 def workdir(self, name):
153 basedir = os.path.join("test_runner", "CreateNode", name)
154 fileutil.make_dirs(basedir)
157 def run_tahoe(self, argv):
158 out,err = StringIO(), StringIO()
159 rc = runner.runner(argv, stdout=out, stderr=err)
160 return rc, out.getvalue(), err.getvalue()
162 def do_create(self, kind):
163 basedir = self.workdir("test_" + kind)
164 command = "create-" + kind
165 is_client = kind in ("node", "client")
166 tac = is_client and "tahoe-client.tac" or ("tahoe-" + kind + ".tac")
168 n1 = os.path.join(basedir, command + "-n1")
169 argv = ["--quiet", command, "--basedir", n1]
170 rc, out, err = self.run_tahoe(argv)
171 self.failUnlessEqual(err, "")
172 self.failUnlessEqual(out, "")
173 self.failUnlessEqual(rc, 0)
174 self.failUnless(os.path.exists(n1))
175 self.failUnless(os.path.exists(os.path.join(n1, tac)))
178 # tahoe.cfg should exist, and should have storage enabled for
179 # 'create-node', and disabled for 'create-client'.
180 tahoe_cfg = os.path.join(n1, "tahoe.cfg")
181 self.failUnless(os.path.exists(tahoe_cfg))
182 content = open(tahoe_cfg).read()
184 self.failUnless("\n[storage]\nenabled = false\n" in content)
186 self.failUnless("\n[storage]\nenabled = true\n" in content)
188 # creating the node a second time should be rejected
189 rc, out, err = self.run_tahoe(argv)
190 self.failIfEqual(rc, 0, str((out, err, rc)))
191 self.failUnlessEqual(out, "")
192 self.failUnless("is not empty." in err)
194 # Fail if there is a non-empty line that doesn't end with a
196 for line in err.splitlines():
197 self.failIf(re.search("[\S][^\.!?]$", line), (line,))
199 # test that the non --basedir form works too
200 n2 = os.path.join(basedir, command + "-n2")
201 argv = ["--quiet", command, n2]
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(n2))
207 self.failUnless(os.path.exists(os.path.join(n2, tac)))
209 # test the --node-directory form
210 n3 = os.path.join(basedir, command + "-n3")
211 argv = ["--quiet", command, "--node-directory", n3]
212 rc, out, err = self.run_tahoe(argv)
213 self.failUnlessEqual(err, "")
214 self.failUnlessEqual(out, "")
215 self.failUnlessEqual(rc, 0)
216 self.failUnless(os.path.exists(n3))
217 self.failUnless(os.path.exists(os.path.join(n3, tac)))
219 # test the --multiple form
220 n4 = os.path.join(basedir, command + "-n4")
221 n5 = os.path.join(basedir, command + "-n5")
222 argv = ["--quiet", command, "--multiple", n4, n5]
223 rc, out, err = self.run_tahoe(argv)
224 self.failUnlessEqual(err, "")
225 self.failUnlessEqual(out, "")
226 self.failUnlessEqual(rc, 0)
227 self.failUnless(os.path.exists(n4))
228 self.failUnless(os.path.exists(os.path.join(n4, tac)))
229 self.failUnless(os.path.exists(n5))
230 self.failUnless(os.path.exists(os.path.join(n5, tac)))
232 # make sure it rejects too many arguments without --multiple
233 argv = [command, "basedir", "extraarg"]
234 self.failUnlessRaises(usage.UsageError,
238 # when creating a non-client, there is no default for the basedir
241 self.failUnlessRaises(usage.UsageError,
247 self.do_create("node")
249 def test_client(self):
250 # create-client should behave like create-node --no-storage.
251 self.do_create("client")
253 def test_introducer(self):
254 self.do_create("introducer")
256 def test_key_generator(self):
257 self.do_create("key-generator")
259 def test_stats_gatherer(self):
260 self.do_create("stats-gatherer")
262 def test_subcommands(self):
263 # no arguments should trigger a command listing, via UsageError
264 self.failUnlessRaises(usage.UsageError,
270 class RunNode(common_util.SignalMixin, unittest.TestCase, pollmixin.PollMixin,
272 # exercise "tahoe start", for both introducer, client node, and
273 # key-generator, by spawning "tahoe start" as a subprocess. This doesn't
274 # get us figleaf-based line-level coverage, but it does a better job of
275 # confirming that the user can actually run "./bin/tahoe start" and
276 # expect it to work. This verifies that bin/tahoe sets up PYTHONPATH and
277 # the like correctly.
279 # This doesn't work on cygwin (it hangs forever), so we skip this test
280 # when we're on cygwin. It is likely that "tahoe start" itself doesn't
281 # work on cygwin: twisted seems unable to provide a version of
282 # spawnProcess which really works there.
284 def workdir(self, name):
285 basedir = os.path.join("test_runner", "RunNode", name)
286 fileutil.make_dirs(basedir)
289 def test_introducer(self):
290 self.skip_if_cannot_daemonize()
291 basedir = self.workdir("test_introducer")
292 c1 = os.path.join(basedir, "c1")
293 HOTLINE_FILE = os.path.join(c1, "suicide_prevention_hotline")
294 TWISTD_PID_FILE = os.path.join(c1, "twistd.pid")
295 INTRODUCER_FURL_FILE = os.path.join(c1, "introducer.furl")
297 d = utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "create-introducer", "--basedir", c1], env=os.environ)
299 out, err, rc_or_sig = res
300 self.failUnlessEqual(rc_or_sig, 0)
301 # by writing this file, we get ten seconds before the node will
302 # exit. This insures that even if the test fails (and the 'stop'
303 # command doesn't work), the client should still terminate.
304 open(HOTLINE_FILE, "w").write("")
305 # now it's safe to start the node
308 def _then_start_the_node(res):
309 return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "start", c1], env=os.environ)
310 d.addCallback(_then_start_the_node)
313 out, err, rc_or_sig = res
315 open(HOTLINE_FILE, "w").write("")
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.
321 # the parent (twistd) has exited. However, twistd writes the pid
322 # from the child, not the parent, so we can't expect twistd.pid
323 # to exist quite yet.
325 # the node is running, but it might not have made it past the
326 # first reactor turn yet, and if we kill it too early, it won't
327 # remove the twistd.pid file. So wait until it does something
328 # that we know it won't do until after the first turn.
331 def _node_has_started():
332 return os.path.exists(INTRODUCER_FURL_FILE)
333 d.addCallback(lambda res: self.poll(_node_has_started))
336 open(HOTLINE_FILE, "w").write("")
337 self.failUnless(os.path.exists(TWISTD_PID_FILE))
338 # rm this so we can detect when the second incarnation is ready
339 os.unlink(INTRODUCER_FURL_FILE)
340 return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "restart", c1], env=os.environ)
341 d.addCallback(_started)
344 out, err, rc_or_sig = res
345 open(HOTLINE_FILE, "w").write("")
346 errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
347 self.failUnlessEqual(rc_or_sig, 0, errstr)
348 self.failUnlessEqual(out, "", errstr)
349 # self.failUnlessEqual(err, "", errstr) # See test_client_no_noise -- for now we ignore noise.
352 # again, the second incarnation of the node might not be ready yet,
353 # so poll until it is
354 d.addCallback(lambda res: self.poll(_node_has_started))
356 # now we can kill it. TODO: On a slow machine, the node might kill
357 # itself before we get a chance too, especially if spawning the
358 # 'tahoe stop' command takes a while.
360 open(HOTLINE_FILE, "w").write("")
361 self.failUnless(os.path.exists(TWISTD_PID_FILE))
363 return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "stop", c1], env=os.environ)
366 def _after_stopping(res):
367 out, err, rc_or_sig = res
368 open(HOTLINE_FILE, "w").write("")
369 # the parent has exited by now
370 errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
371 self.failUnlessEqual(rc_or_sig, 0, errstr)
372 self.failUnlessEqual(out, "", errstr)
373 # self.failUnlessEqual(err, "", errstr) # See test_client_no_noise -- for now we ignore noise.
374 # the parent was supposed to poll and wait until it sees
375 # twistd.pid go away before it exits, so twistd.pid should be
377 self.failIf(os.path.exists(TWISTD_PID_FILE))
378 d.addCallback(_after_stopping)
380 def _remove_hotline(res):
381 os.unlink(HOTLINE_FILE)
383 d.addBoth(_remove_hotline)
385 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
387 def test_client_no_noise(self):
388 self.skip_if_cannot_daemonize()
391 pkg_resources.require("Twisted>=9.0.0")
392 except pkg_resources.VersionConflict:
393 raise unittest.SkipTest("We pass this test only with Twisted >= v9.0.0")
394 basedir = self.workdir("test_client_no_noise")
395 c1 = os.path.join(basedir, "c1")
396 HOTLINE_FILE = os.path.join(c1, "suicide_prevention_hotline")
397 TWISTD_PID_FILE = os.path.join(c1, "twistd.pid")
398 PORTNUMFILE = os.path.join(c1, "client.port")
400 d = utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "create-client", "--basedir", c1, "--webport", "0"], env=os.environ)
402 out, err, rc_or_sig = res
403 errstr = "cc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
404 assert rc_or_sig == 0, errstr
405 self.failUnlessEqual(rc_or_sig, 0)
406 # By writing this file, we get forty seconds before the client will exit. This insures
407 # that even if the 'stop' command doesn't work (and the test fails), the client should
409 open(HOTLINE_FILE, "w").write("")
410 open(os.path.join(c1, "introducer.furl"), "w").write("pb://xrndsskn2zuuian5ltnxrte7lnuqdrkz@127.0.0.1:55617/introducer\n")
411 # now it's safe to start the node
415 return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "start", c1], env=os.environ)
416 d.addCallback(_start)
419 out, err, rc_or_sig = res
420 errstr = "cc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
421 open(HOTLINE_FILE, "w").write("")
422 self.failUnlessEqual(rc_or_sig, 0, errstr)
423 self.failUnlessEqual(out, "", errstr) # If you emit noise, you fail this test.
424 self.failUnlessEqual(err, "", errstr)
426 # the parent (twistd) has exited. However, twistd writes the pid
427 # from the child, not the parent, so we can't expect twistd.pid
428 # to exist quite yet.
430 # the node is running, but it might not have made it past the
431 # first reactor turn yet, and if we kill it too early, it won't
432 # remove the twistd.pid file. So wait until it does something
433 # that we know it won't do until after the first turn.
436 def _node_has_started():
437 return os.path.exists(PORTNUMFILE)
438 d.addCallback(lambda res: self.poll(_node_has_started))
440 # now we can kill it. TODO: On a slow machine, the node might kill
441 # itself before we get a chance too, especially if spawning the
442 # 'tahoe stop' command takes a while.
444 self.failUnless(os.path.exists(TWISTD_PID_FILE), (TWISTD_PID_FILE, os.listdir(os.path.dirname(TWISTD_PID_FILE))))
445 return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "stop", c1], env=os.environ)
449 def test_client(self):
450 self.skip_if_cannot_daemonize()
451 basedir = self.workdir("test_client")
452 c1 = os.path.join(basedir, "c1")
453 HOTLINE_FILE = os.path.join(c1, "suicide_prevention_hotline")
454 TWISTD_PID_FILE = os.path.join(c1, "twistd.pid")
455 PORTNUMFILE = os.path.join(c1, "client.port")
457 d = utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "create-node", "--basedir", c1, "--webport", "0"], env=os.environ)
459 out, err, rc_or_sig = res
460 self.failUnlessEqual(rc_or_sig, 0)
461 # By writing this file, we get sixty seconds before the client will exit. This insures
462 # that even if the 'stop' command doesn't work (and the test fails), the client should
464 open(HOTLINE_FILE, "w").write("")
465 open(os.path.join(c1, "introducer.furl"), "w").write("pb://xrndsskn2zuuian5ltnxrte7lnuqdrkz@127.0.0.1:55617/introducer\n")
466 # now it's safe to start the node
470 return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "start", c1], env=os.environ)
471 d.addCallback(_start)
474 out, err, rc_or_sig = res
475 open(HOTLINE_FILE, "w").write("")
476 errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
477 self.failUnlessEqual(rc_or_sig, 0, errstr)
478 self.failUnlessEqual(out, "", errstr)
479 # self.failUnlessEqual(err, "", errstr) # See test_client_no_noise -- for now we ignore noise.
481 # the parent (twistd) has exited. However, twistd writes the pid
482 # from the child, not the parent, so we can't expect twistd.pid
483 # to exist quite yet.
485 # the node is running, but it might not have made it past the
486 # first reactor turn yet, and if we kill it too early, it won't
487 # remove the twistd.pid file. So wait until it does something
488 # that we know it won't do until after the first turn.
491 def _node_has_started():
492 return os.path.exists(PORTNUMFILE)
493 d.addCallback(lambda res: self.poll(_node_has_started))
496 open(HOTLINE_FILE, "w").write("")
497 self.failUnless(os.path.exists(TWISTD_PID_FILE))
498 # rm this so we can detect when the second incarnation is ready
499 os.unlink(PORTNUMFILE)
501 return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "restart", c1], env=os.environ)
502 d.addCallback(_started)
505 out, err, rc_or_sig = res
507 open(HOTLINE_FILE, "w").write("")
508 errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
509 self.failUnlessEqual(rc_or_sig, 0, errstr)
510 self.failUnlessEqual(out, "", errstr)
511 # self.failUnlessEqual(err, "", errstr) # See test_client_no_noise -- for now we ignore noise.
514 # again, the second incarnation of the node might not be ready yet,
515 # so poll until it is
516 d.addCallback(lambda res: self.poll(_node_has_started))
518 # now we can kill it. TODO: On a slow machine, the node might kill
519 # itself before we get a chance too, especially if spawning the
520 # 'tahoe stop' command takes a while.
522 open(HOTLINE_FILE, "w").write("")
523 self.failUnless(os.path.exists(TWISTD_PID_FILE), (TWISTD_PID_FILE, os.listdir(os.path.dirname(TWISTD_PID_FILE))))
524 return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "stop", c1], env=os.environ)
528 out, err, rc_or_sig = res
530 open(HOTLINE_FILE, "w").write("")
531 # the parent has exited by now
532 errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
533 self.failUnlessEqual(rc_or_sig, 0, errstr)
534 self.failUnlessEqual(out, "", errstr)
535 # self.failUnlessEqual(err, "", errstr) # See test_client_no_noise -- for now we ignore noise.
536 # the parent was supposed to poll and wait until it sees
537 # twistd.pid go away before it exits, so twistd.pid should be
539 self.failIf(os.path.exists(TWISTD_PID_FILE))
541 def _remove_hotline(res):
542 os.unlink(HOTLINE_FILE)
544 d.addBoth(_remove_hotline)
547 def test_baddir(self):
548 self.skip_if_cannot_daemonize()
549 basedir = self.workdir("test_baddir")
550 fileutil.make_dirs(basedir)
552 d = utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "start", "--basedir", basedir], env=os.environ)
554 out, err, rc_or_sig = res
555 self.failUnlessEqual(rc_or_sig, 1)
556 self.failUnless("does not look like a node directory" in err, err)
559 def _then_stop_it(res):
560 return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "stop", "--basedir", basedir], env=os.environ)
561 d.addCallback(_then_stop_it)
564 out, err, rc_or_sig = res
565 self.failUnlessEqual(rc_or_sig, 2)
566 self.failUnless("does not look like a running node directory" in err)
569 def _then_start_in_bogus_basedir(res):
570 not_a_dir = os.path.join(basedir, "bogus")
571 return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "start", "--basedir", not_a_dir], env=os.environ)
572 d.addCallback(_then_start_in_bogus_basedir)
575 out, err, rc_or_sig = res
576 self.failUnlessEqual(rc_or_sig, 1)
577 self.failUnless("does not look like a directory at all" in err, err)
581 def test_keygen(self):
582 self.skip_if_cannot_daemonize()
583 basedir = self.workdir("test_keygen")
584 c1 = os.path.join(basedir, "c1")
585 TWISTD_PID_FILE = os.path.join(c1, "twistd.pid")
586 KEYGEN_FURL_FILE = os.path.join(c1, "key_generator.furl")
588 d = utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "create-key-generator", "--basedir", c1], env=os.environ)
590 out, err, rc_or_sig = res
591 self.failUnlessEqual(rc_or_sig, 0)
595 return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "start", c1], env=os.environ)
596 d.addCallback(_start)
599 out, err, rc_or_sig = res
600 errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
601 self.failUnlessEqual(rc_or_sig, 0, errstr)
602 self.failUnlessEqual(out, "", errstr)
603 # self.failUnlessEqual(err, "", errstr) # See test_client_no_noise -- for now we ignore noise.
605 # the parent (twistd) has exited. However, twistd writes the pid
606 # from the child, not the parent, so we can't expect twistd.pid
607 # to exist quite yet.
609 # the node is running, but it might not have made it past the
610 # first reactor turn yet, and if we kill it too early, it won't
611 # remove the twistd.pid file. So wait until it does something
612 # that we know it won't do until after the first turn.
615 def _node_has_started():
616 return os.path.exists(KEYGEN_FURL_FILE)
617 d.addCallback(lambda res: self.poll(_node_has_started))
620 self.failUnless(os.path.exists(TWISTD_PID_FILE))
621 # rm this so we can detect when the second incarnation is ready
622 os.unlink(KEYGEN_FURL_FILE)
623 return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "restart", c1], env=os.environ)
624 d.addCallback(_started)
627 out, err, rc_or_sig = res
628 errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
629 self.failUnlessEqual(rc_or_sig, 0, errstr)
630 self.failUnlessEqual(out, "", errstr)
631 # self.failUnlessEqual(err, "", errstr) # See test_client_no_noise -- for now we ignore noise.
634 # again, the second incarnation of the node might not be ready yet,
635 # so poll until it is
636 d.addCallback(lambda res: self.poll(_node_has_started))
638 # now we can kill it. TODO: On a slow machine, the node might kill
639 # itself before we get a chance too, especially if spawning the
640 # 'tahoe stop' command takes a while.
642 self.failUnless(os.path.exists(TWISTD_PID_FILE))
643 return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "stop", c1], env=os.environ)
647 out, err, rc_or_sig = res
648 # the parent has exited by now
649 errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
650 self.failUnlessEqual(rc_or_sig, 0, errstr)
651 self.failUnlessEqual(out, "", errstr)
652 # self.failUnlessEqual(err, "", errstr) # See test_client_no_noise -- for now we ignore noise.
653 # the parent was supposed to poll and wait until it sees
654 # twistd.pid go away before it exits, so twistd.pid should be
656 self.failIf(os.path.exists(TWISTD_PID_FILE))