]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blob - src/allmydata/test/test_runner.py
test_runner.py: revert the CreateNode section to using runner() inline, rather than...
[tahoe-lafs/tahoe-lafs.git] / src / allmydata / test / test_runner.py
1
2 from twisted.trial import unittest
3
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
10
11 from allmydata.test import common_util
12 import allmydata
13
14 bintahoe = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(allmydata.__file__))), 'bin', 'tahoe')
15 if sys.platform == "win32":
16     bintahoe += ".exe"
17
18 class TheRightCode(unittest.TestCase, common_util.SignalMixin):
19     def test_path(self):
20         if not os.path.exists(bintahoe):
21             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.")
22         d = utils.getProcessOutputAndValue(bintahoe, args=["--version-and-path"], env=os.environ)
23         def _cb(res):
24             out, err, rc_or_sig = res
25             self.failUnlessEqual(rc_or_sig, 0)
26
27             # Fail unless the allmydata-tahoe package is *this* version *and* was loaded from *this* source directory.
28             required_ver_and_path = "allmydata-tahoe: %s (%s)" % (allmydata.__version__, os.path.dirname(os.path.dirname(allmydata.__file__)))
29             self.failUnless(out.startswith(required_ver_and_path), (out, err, rc_or_sig, required_ver_and_path))
30         d.addCallback(_cb)
31         return d
32
33 class CreateNode(unittest.TestCase):
34     # exercise "tahoe create-client", create-introducer,
35     # create-key-generator, and create-stats-gatherer, by calling the
36     # corresponding code as a subroutine.
37
38     def workdir(self, name):
39         basedir = os.path.join("test_runner", "CreateNode", name)
40         fileutil.make_dirs(basedir)
41         return basedir
42
43     def run_tahoe(self, argv):
44         out,err = StringIO(), StringIO()
45         rc = runner.runner(argv, stdout=out, stderr=err)
46         return rc, out.getvalue(), err.getvalue()
47
48     def test_client(self):
49         basedir = self.workdir("test_client")
50         c1 = os.path.join(basedir, "c1")
51         argv = ["--quiet", "create-client", "--basedir", c1]
52         rc, out, err = self.run_tahoe(argv)
53         self.failUnlessEqual(err, "")
54         self.failUnlessEqual(out, "")
55         self.failUnlessEqual(rc, 0)
56         self.failUnless(os.path.exists(c1))
57         self.failUnless(os.path.exists(os.path.join(c1, "tahoe-client.tac")))
58
59         # creating the client a second time should be rejected
60         rc, out, err = self.run_tahoe(argv)
61         self.failIfEqual(rc, 0, str((out, err, rc)))
62         self.failUnlessEqual(out, "")
63         self.failUnless("is not empty." in err)
64
65         # Fail if there is a non-empty line that doesn't end with a
66         # punctuation mark.
67         for line in err.splitlines():
68             self.failIf(re.search("[\S][^\.!?]$", line), (line,))
69
70         # test that the non --basedir form works too
71         c2 = os.path.join(basedir, "c2")
72         argv = ["--quiet", "create-client", c2]
73         rc, out, err = self.run_tahoe(argv)
74         self.failUnless(os.path.exists(c2))
75         self.failUnless(os.path.exists(os.path.join(c2, "tahoe-client.tac")))
76
77         # make sure it rejects too many arguments
78         argv = ["create-client", "basedir", "extraarg"]
79         self.failUnlessRaises(usage.UsageError,
80                               runner.runner, argv,
81                               run_by_human=False)
82
83     def test_introducer(self):
84         basedir = self.workdir("test_introducer")
85         c1 = os.path.join(basedir, "c1")
86         argv = ["--quiet", "create-introducer", "--basedir", c1]
87         rc, out, err = self.run_tahoe(argv)
88         self.failUnlessEqual(err, "", err)
89         self.failUnlessEqual(out, "")
90         self.failUnlessEqual(rc, 0)
91         self.failUnless(os.path.exists(c1))
92         self.failUnless(os.path.exists(os.path.join(c1,"tahoe-introducer.tac")))
93
94         # creating the introducer a second time should be rejected
95         rc, out, err = self.run_tahoe(argv)
96         self.failIfEqual(rc, 0)
97         self.failUnlessEqual(out, "")
98         self.failUnless("is not empty" in err)
99
100         # Fail if there is a non-empty line that doesn't end with a
101         # punctuation mark.
102         for line in err.splitlines():
103             self.failIf(re.search("[\S][^\.!?]$", line), (line,))
104
105         # test the non --basedir form
106         c2 = os.path.join(basedir, "c2")
107         argv = ["--quiet", "create-introducer", c2]
108         rc, out, err = self.run_tahoe(argv)
109         self.failUnlessEqual(err, "", err)
110         self.failUnlessEqual(out, "")
111         self.failUnlessEqual(rc, 0)
112         self.failUnless(os.path.exists(c2))
113         self.failUnless(os.path.exists(os.path.join(c2,"tahoe-introducer.tac")))
114
115         # reject extra arguments
116         argv = ["create-introducer", "basedir", "extraarg"]
117         self.failUnlessRaises(usage.UsageError,
118                               runner.runner, argv,
119                               run_by_human=False)
120         # and require basedir to be provided in some form
121         argv = ["create-introducer"]
122         self.failUnlessRaises(usage.UsageError,
123                               runner.runner, argv,
124                               run_by_human=False)
125
126     def test_key_generator(self):
127         basedir = self.workdir("test_key_generator")
128         kg1 = os.path.join(basedir, "kg1")
129         argv = ["--quiet", "create-key-generator", "--basedir", kg1]
130         rc, out, err = self.run_tahoe(argv)
131         self.failUnlessEqual(err, "")
132         self.failUnlessEqual(out, "")
133         self.failUnlessEqual(rc, 0)
134         self.failUnless(os.path.exists(kg1))
135         self.failUnless(os.path.exists(os.path.join(kg1, "tahoe-key-generator.tac")))
136
137         # creating it a second time should be rejected
138         rc, out, err = self.run_tahoe(argv)
139         self.failIfEqual(rc, 0, str((out, err, rc)))
140         self.failUnlessEqual(out, "")
141         self.failUnless("is not empty." in err)
142
143         # make sure it rejects too many arguments
144         argv = ["create-key-generator", "basedir", "extraarg"]
145         self.failUnlessRaises(usage.UsageError,
146                               runner.runner, argv,
147                               run_by_human=False)
148
149         # make sure it rejects a missing basedir specification
150         argv = ["create-key-generator"]
151         rc, out, err = self.run_tahoe(argv)
152         self.failIfEqual(rc, 0, str((out, err, rc)))
153         self.failUnlessEqual(out, "")
154         self.failUnless("a basedir was not provided" in err)
155
156     def test_stats_gatherer(self):
157         basedir = self.workdir("test_stats_gatherer")
158         sg1 = os.path.join(basedir, "sg1")
159         argv = ["--quiet", "create-stats-gatherer", "--basedir", sg1]
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(sg1))
165         self.failUnless(os.path.exists(os.path.join(sg1, "tahoe-stats-gatherer.tac")))
166
167         # creating it a second time should be rejected
168         rc, out, err = self.run_tahoe(argv)
169         self.failIfEqual(rc, 0, str((out, err, rc)))
170         self.failUnlessEqual(out, "")
171         self.failUnless("is not empty." in err)
172
173         # test the non --basedir form
174         kg2 = os.path.join(basedir, "kg2")
175         argv = ["--quiet", "create-stats-gatherer", kg2]
176         rc, out, err = self.run_tahoe(argv)
177         self.failUnlessEqual(err, "", err)
178         self.failUnlessEqual(out, "")
179         self.failUnlessEqual(rc, 0)
180         self.failUnless(os.path.exists(kg2))
181         self.failUnless(os.path.exists(os.path.join(kg2,"tahoe-stats-gatherer.tac")))
182
183         # make sure it rejects too many arguments
184         argv = ["create-stats-gatherer", "basedir", "extraarg"]
185         self.failUnlessRaises(usage.UsageError,
186                               runner.runner, argv,
187                               run_by_human=False)
188
189         # make sure it rejects a missing basedir specification
190         argv = ["create-stats-gatherer"]
191         rc, out, err = self.run_tahoe(argv)
192         self.failIfEqual(rc, 0, str((out, err, rc)))
193         self.failUnlessEqual(out, "")
194         self.failUnless("a basedir was not provided" in err)
195
196     def test_subcommands(self):
197         # no arguments should trigger a command listing, via UsageError
198         self.failUnlessRaises(usage.UsageError,
199                               runner.runner,
200                               [],
201                               run_by_human=False)
202
203
204 class RunNode(unittest.TestCase, pollmixin.PollMixin, common_util.SignalMixin):
205     def workdir(self, name):
206         basedir = os.path.join("test_runner", "RunNode", name)
207         fileutil.make_dirs(basedir)
208         return basedir
209
210     def test_introducer(self):
211         if not os.path.exists(bintahoe):
212             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.")
213         if runtime.platformType == "win32":
214             # twistd on windows doesn't daemonize. cygwin works normally.
215             raise unittest.SkipTest("twistd does not fork under windows")
216         basedir = self.workdir("test_introducer")
217         c1 = os.path.join(basedir, "c1")
218         HOTLINE_FILE = os.path.join(c1, "suicide_prevention_hotline")
219         TWISTD_PID_FILE = os.path.join(c1, "twistd.pid")
220         INTRODUCER_FURL_FILE = os.path.join(c1, "introducer.furl")
221
222         d = utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "create-introducer", "--basedir", c1], env=os.environ)
223         def _cb(res):
224             out, err, rc_or_sig = res
225             self.failUnlessEqual(rc_or_sig, 0)
226             # by writing this file, we get ten seconds before the node will
227             # exit. This insures that even if the test fails (and the 'stop'
228             # command doesn't work), the client should still terminate.
229             open(HOTLINE_FILE, "w").write("")
230             # now it's safe to start the node
231         d.addCallback(_cb)
232
233         def _then_start_the_node(res):
234             return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "start", c1], env=os.environ)
235         d.addCallback(_then_start_the_node)
236
237         def _cb2(res):
238             out, err, rc_or_sig = res
239
240             open(HOTLINE_FILE, "w").write("")
241             errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
242             self.failUnlessEqual(rc_or_sig, 0, errstr)
243             self.failUnlessEqual(out, "", errstr)
244             # self.failUnlessEqual(err, "", errstr) # See test_client_no_noise -- for now we ignore noise.
245
246             # the parent (twistd) has exited. However, twistd writes the pid
247             # from the child, not the parent, so we can't expect twistd.pid
248             # to exist quite yet.
249
250             # the node is running, but it might not have made it past the
251             # first reactor turn yet, and if we kill it too early, it won't
252             # remove the twistd.pid file. So wait until it does something
253             # that we know it won't do until after the first turn.
254         d.addCallback(_cb2)
255
256         def _node_has_started():
257             return os.path.exists(INTRODUCER_FURL_FILE)
258         d.addCallback(lambda res: self.poll(_node_has_started))
259
260         def _started(res):
261             open(HOTLINE_FILE, "w").write("")
262             self.failUnless(os.path.exists(TWISTD_PID_FILE))
263             # rm this so we can detect when the second incarnation is ready
264             os.unlink(INTRODUCER_FURL_FILE)
265             return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "restart", c1], env=os.environ)
266         d.addCallback(_started)
267
268         def _then(res):
269             out, err, rc_or_sig = res
270             open(HOTLINE_FILE, "w").write("")
271             errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
272             self.failUnlessEqual(rc_or_sig, 0, errstr)
273             self.failUnlessEqual(out, "", errstr)
274             # self.failUnlessEqual(err, "", errstr) # See test_client_no_noise -- for now we ignore noise.
275         d.addCallback(_then)
276
277         # again, the second incarnation of the node might not be ready yet,
278         # so poll until it is
279         d.addCallback(lambda res: self.poll(_node_has_started))
280
281         # now we can kill it. TODO: On a slow machine, the node might kill
282         # itself before we get a chance too, especially if spawning the
283         # 'tahoe stop' command takes a while.
284         def _stop(res):
285             open(HOTLINE_FILE, "w").write("")
286             self.failUnless(os.path.exists(TWISTD_PID_FILE))
287
288             return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "stop", c1], env=os.environ)
289         d.addCallback(_stop)
290
291         def _after_stopping(res):
292             out, err, rc_or_sig = res
293             open(HOTLINE_FILE, "w").write("")
294             # the parent has exited by now
295             errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
296             self.failUnlessEqual(rc_or_sig, 0, errstr)
297             self.failUnlessEqual(out, "", errstr)
298             # self.failUnlessEqual(err, "", errstr) # See test_client_no_noise -- for now we ignore noise.
299             # the parent was supposed to poll and wait until it sees
300             # twistd.pid go away before it exits, so twistd.pid should be
301             # gone by now.
302             self.failIf(os.path.exists(TWISTD_PID_FILE))
303         d.addCallback(_after_stopping)
304
305         def _remove_hotline(res):
306             os.unlink(HOTLINE_FILE)
307             return res
308         d.addBoth(_remove_hotline)
309         return d
310
311     def test_client_no_noise(self):
312         if not os.path.exists(bintahoe):
313             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.")
314         basedir = self.workdir("test_client_no_noise")
315         c1 = os.path.join(basedir, "c1")
316         HOTLINE_FILE = os.path.join(c1, "suicide_prevention_hotline")
317         TWISTD_PID_FILE = os.path.join(c1, "twistd.pid")
318         PORTNUMFILE = os.path.join(c1, "client.port")
319
320         d = utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "create-client", "--basedir", c1, "--webport", "0"], env=os.environ)
321         def _cb(res):
322             out, err, rc_or_sig = res
323             errstr = "cc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
324             assert rc_or_sig == 0, errstr
325             self.failUnlessEqual(rc_or_sig, 0)
326             # By writing this file, we get forty seconds before the client will exit. This insures
327             # that even if the 'stop' command doesn't work (and the test fails), the client should
328             # still terminate.
329             open(HOTLINE_FILE, "w").write("")
330             open(os.path.join(c1, "introducer.furl"), "w").write("pb://xrndsskn2zuuian5ltnxrte7lnuqdrkz@127.0.0.1:55617/introducer\n")
331             # now it's safe to start the node
332         d.addCallback(_cb)
333
334         def _start(res):
335             return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "start", c1], env=os.environ)
336         d.addCallback(_start)
337
338         def _cb2(res):
339             out, err, rc_or_sig = res
340             errstr = "cc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
341             open(HOTLINE_FILE, "w").write("")
342             self.failUnlessEqual(rc_or_sig, 0, errstr)
343             self.failUnlessEqual(out, "", errstr) # If you emit noise, you fail this test.
344             self.failUnlessEqual(err, "", errstr)
345
346             # the parent (twistd) has exited. However, twistd writes the pid
347             # from the child, not the parent, so we can't expect twistd.pid
348             # to exist quite yet.
349
350             # the node is running, but it might not have made it past the
351             # first reactor turn yet, and if we kill it too early, it won't
352             # remove the twistd.pid file. So wait until it does something
353             # that we know it won't do until after the first turn.
354         d.addCallback(_cb2)
355
356         def _node_has_started():
357             return os.path.exists(PORTNUMFILE)
358         d.addCallback(lambda res: self.poll(_node_has_started))
359
360         # now we can kill it. TODO: On a slow machine, the node might kill
361         # itself before we get a chance too, especially if spawning the
362         # 'tahoe stop' command takes a while.
363         def _stop(res):
364             self.failUnless(os.path.exists(TWISTD_PID_FILE), (TWISTD_PID_FILE, os.listdir(os.path.dirname(TWISTD_PID_FILE))))
365             return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "stop", c1], env=os.environ)
366         d.addCallback(_stop)
367         return d
368     test_client_no_noise.todo = "We submitted a patch to Nevow to silence this warning: http://divmod.org/trac/ticket/2830"
369
370     def test_client(self):
371         if not os.path.exists(bintahoe):
372             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.")
373         if runtime.platformType == "win32":
374             # twistd on windows doesn't daemonize. cygwin works normally.
375             raise unittest.SkipTest("twistd does not fork under windows")
376         basedir = self.workdir("test_client")
377         c1 = os.path.join(basedir, "c1")
378         HOTLINE_FILE = os.path.join(c1, "suicide_prevention_hotline")
379         TWISTD_PID_FILE = os.path.join(c1, "twistd.pid")
380         PORTNUMFILE = os.path.join(c1, "client.port")
381
382         d = utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "create-client", "--basedir", c1, "--webport", "0"], env=os.environ)
383         def _cb(res):
384             out, err, rc_or_sig = res
385             self.failUnlessEqual(rc_or_sig, 0)
386             # By writing this file, we get forty seconds before the client will exit. This insures
387             # that even if the 'stop' command doesn't work (and the test fails), the client should
388             # still terminate.
389             open(HOTLINE_FILE, "w").write("")
390             open(os.path.join(c1, "introducer.furl"), "w").write("pb://xrndsskn2zuuian5ltnxrte7lnuqdrkz@127.0.0.1:55617/introducer\n")
391             # now it's safe to start the node
392         d.addCallback(_cb)
393
394         def _start(res):
395             return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "start", c1], env=os.environ)
396         d.addCallback(_start)
397
398         def _cb2(res):
399             out, err, rc_or_sig = res
400             open(HOTLINE_FILE, "w").write("")
401             errstr = "cc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
402             self.failUnlessEqual(rc_or_sig, 0, errstr)
403             self.failUnlessEqual(out, "", errstr)
404             # self.failUnlessEqual(err, "", errstr) # See test_client_no_noise -- for now we ignore noise.
405
406             # the parent (twistd) has exited. However, twistd writes the pid
407             # from the child, not the parent, so we can't expect twistd.pid
408             # to exist quite yet.
409
410             # the node is running, but it might not have made it past the
411             # first reactor turn yet, and if we kill it too early, it won't
412             # remove the twistd.pid file. So wait until it does something
413             # that we know it won't do until after the first turn.
414         d.addCallback(_cb2)
415
416         def _node_has_started():
417             return os.path.exists(PORTNUMFILE)
418         d.addCallback(lambda res: self.poll(_node_has_started))
419
420         def _started(res):
421             open(HOTLINE_FILE, "w").write("")
422             self.failUnless(os.path.exists(TWISTD_PID_FILE))
423             # rm this so we can detect when the second incarnation is ready
424             os.unlink(PORTNUMFILE)
425
426             return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "restart", c1], env=os.environ)
427         d.addCallback(_started)
428
429         def _cb3(res):
430             out, err, rc_or_sig = res
431
432             open(HOTLINE_FILE, "w").write("")
433             errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
434             self.failUnlessEqual(rc_or_sig, 0, errstr)
435             self.failUnlessEqual(out, "", errstr)
436             # self.failUnlessEqual(err, "", errstr) # See test_client_no_noise -- for now we ignore noise.
437         d.addCallback(_cb3)
438
439         # again, the second incarnation of the node might not be ready yet,
440         # so poll until it is
441         d.addCallback(lambda res: self.poll(_node_has_started))
442
443         # now we can kill it. TODO: On a slow machine, the node might kill
444         # itself before we get a chance too, especially if spawning the
445         # 'tahoe stop' command takes a while.
446         def _stop(res):
447             open(HOTLINE_FILE, "w").write("")
448             self.failUnless(os.path.exists(TWISTD_PID_FILE), (TWISTD_PID_FILE, os.listdir(os.path.dirname(TWISTD_PID_FILE))))
449             return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "stop", c1], env=os.environ)
450         d.addCallback(_stop)
451
452         def _cb4(res):
453             out, err, rc_or_sig = res
454
455             open(HOTLINE_FILE, "w").write("")
456             # the parent has exited by now
457             errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
458             self.failUnlessEqual(rc_or_sig, 0, errstr)
459             self.failUnlessEqual(out, "", errstr)
460             # self.failUnlessEqual(err, "", errstr) # See test_client_no_noise -- for now we ignore noise.
461             # the parent was supposed to poll and wait until it sees
462             # twistd.pid go away before it exits, so twistd.pid should be
463             # gone by now.
464             self.failIf(os.path.exists(TWISTD_PID_FILE))
465         d.addCallback(_cb4)
466         def _remove_hotline(res):
467             os.unlink(HOTLINE_FILE)
468             return res
469         d.addBoth(_remove_hotline)
470         return d
471
472     def test_baddir(self):
473         if not os.path.exists(bintahoe):
474             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.")
475         basedir = self.workdir("test_baddir")
476         fileutil.make_dirs(basedir)
477
478         d = utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "start", "--basedir", basedir], env=os.environ)
479         def _cb(res):
480             out, err, rc_or_sig = res
481             self.failUnlessEqual(rc_or_sig, 1)
482             self.failUnless("does not look like a node directory" in err)
483         d.addCallback(_cb)
484
485         def _then_stop_it(res):
486             return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "stop", "--basedir", basedir], env=os.environ)
487         d.addCallback(_then_stop_it)
488
489         def _cb2(res):
490             out, err, rc_or_sig = res
491             self.failUnlessEqual(rc_or_sig, 2)
492             self.failUnless("does not look like a running node directory" in err)
493         d.addCallback(_cb2)
494
495         def _then_start_in_bogus_basedir(res):
496             not_a_dir = os.path.join(basedir, "bogus")
497             return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "start", "--basedir", not_a_dir], env=os.environ)
498         d.addCallback(_then_start_in_bogus_basedir)
499
500         def _cb3(res):
501             out, err, rc_or_sig = res
502             self.failUnlessEqual(rc_or_sig, 1)
503             self.failUnless("does not look like a directory at all" in err, err)
504         d.addCallback(_cb3)
505         return d
506
507     def test_keygen(self):
508         if not os.path.exists(bintahoe):
509             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.")
510         if runtime.platformType == "win32":
511             # twistd on windows doesn't daemonize. cygwin works normally.
512             raise unittest.SkipTest("twistd does not fork under windows")
513         basedir = self.workdir("test_keygen")
514         c1 = os.path.join(basedir, "c1")
515         TWISTD_PID_FILE = os.path.join(c1, "twistd.pid")
516         KEYGEN_FURL_FILE = os.path.join(c1, "key_generator.furl")
517
518         d = utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "create-key-generator", "--basedir", c1], env=os.environ)
519         def _cb(res):
520             out, err, rc_or_sig = res
521             self.failUnlessEqual(rc_or_sig, 0)
522         d.addCallback(_cb)
523
524         def _start(res):
525             return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "start", c1], env=os.environ)
526         d.addCallback(_start)
527
528         def _cb2(res):
529             out, err, rc_or_sig = res
530             errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
531             self.failUnlessEqual(rc_or_sig, 0, errstr)
532             self.failUnlessEqual(out, "", errstr)
533             # self.failUnlessEqual(err, "", errstr) # See test_client_no_noise -- for now we ignore noise.
534
535             # the parent (twistd) has exited. However, twistd writes the pid
536             # from the child, not the parent, so we can't expect twistd.pid
537             # to exist quite yet.
538
539             # the node is running, but it might not have made it past the
540             # first reactor turn yet, and if we kill it too early, it won't
541             # remove the twistd.pid file. So wait until it does something
542             # that we know it won't do until after the first turn.
543         d.addCallback(_cb2)
544
545         def _node_has_started():
546             return os.path.exists(KEYGEN_FURL_FILE)
547         d.addCallback(lambda res: self.poll(_node_has_started))
548
549         def _started(res):
550             self.failUnless(os.path.exists(TWISTD_PID_FILE))
551             # rm this so we can detect when the second incarnation is ready
552             os.unlink(KEYGEN_FURL_FILE)
553             return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "restart", c1], env=os.environ)
554         d.addCallback(_started)
555
556         def _cb3(res):
557             out, err, rc_or_sig = res
558             errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
559             self.failUnlessEqual(rc_or_sig, 0, errstr)
560             self.failUnlessEqual(out, "", errstr)
561             # self.failUnlessEqual(err, "", errstr) # See test_client_no_noise -- for now we ignore noise.
562         d.addCallback(_cb3)
563
564         # again, the second incarnation of the node might not be ready yet,
565         # so poll until it is
566         d.addCallback(lambda res: self.poll(_node_has_started))
567
568         # now we can kill it. TODO: On a slow machine, the node might kill
569         # itself before we get a chance too, especially if spawning the
570         # 'tahoe stop' command takes a while.
571         def _stop(res):
572             self.failUnless(os.path.exists(TWISTD_PID_FILE))
573             return utils.getProcessOutputAndValue(bintahoe, args=["--quiet", "stop", c1], env=os.environ)
574         d.addCallback(_stop)
575
576         def _cb4(res):
577             out, err, rc_or_sig = res
578             # the parent has exited by now
579             errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
580             self.failUnlessEqual(rc_or_sig, 0, errstr)
581             self.failUnlessEqual(out, "", errstr)
582             # self.failUnlessEqual(err, "", errstr) # See test_client_no_noise -- for now we ignore noise.
583             # the parent was supposed to poll and wait until it sees
584             # twistd.pid go away before it exits, so twistd.pid should be
585             # gone by now.
586             self.failIf(os.path.exists(TWISTD_PID_FILE))
587         d.addCallback(_cb4)
588         return d