Changeset f36bda2 in trunk


Ignore:
Timestamp:
2010-11-27T00:44:11Z (15 years ago)
Author:
Brian Warner <warner@…>
Branches:
master
Children:
69b42c6
Parents:
f3adb03
Message:

Revert previous commit: there's an ugly corner-case on windows that fails tests.

Specifically, test_runner.CreateNode?.test_client failed, because the
os.fork-is-present test decided that --multiple should not be allowed on
windows, even though --multiple works just fine for 'tahoe create-client'.
The only restriction on --multiple is for 'tahoe start' and 'tahoe restart'.

This needs a different approach, probably by cleaning up BasedirMixin?. We
should only be withholding --multiple on windows for "start" and
"restart". (we should continue withholding --multiple on all platforms for
"run").

This reverts (git) commit f3adb037ae0d22eb06c719c2faef75a834618442:

"startstop_node.py: fix "tahoe start -m" by forking before non-final targets"

Location:
src/allmydata
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified src/allmydata/scripts/common.py

    rf3adb03 rf36bda2  
    5555    default_nodedir = _default_nodedir
    5656    allow_multiple = True
    57     # startstop_node.py needs os.fork to implement the "-m" option on "tahoe
    58     # start" option
    59     can_start_multiple = hasattr(os, "fork")
    60 
    6157
    6258    optParameters = [
    6359        ["basedir", "C", None, "Same as --node-directory."],
    6460    ]
    65     optFlags = [ ]
    66     if can_start_multiple:
    67         optFlags.append(["multiple", "m",
    68                          "Specify multiple node directories at once."])
     61    optFlags = [
     62        ["multiple", "m", "Specify multiple node directories at once."],
     63    ]
    6964
    7065    def parseArgs(self, *args):
  • TabularUnified src/allmydata/scripts/startstop_node.py

    rf3adb03 rf36bda2  
    2727    optParameters = [
    2828        ["node-directory", "d", None, "Specify the directory of the node to be run. [default, for 'tahoe run' only: current directory]"],
    29         ]
    30     optFlags = [ ]
    31     if BasedirMixin.can_start_multiple:
    32         # usage.Options doesn't let us remove flags that we inherit from a
    33         # parent class, so at least provide a --help string that warns people
    34         # away from using it. There is also code (switching on
    35         # allow_multiple) to disable it at runtime.
    36         optFlags.append(["multiple", "m",
    37                          "['tahoe run' cannot accept multiple node directories]"])
    38 
    39 def do_start(basedir, opts, out=sys.stdout, err=sys.stderr, fork=False):
     29        ["multiple", "m", None, "['tahoe run' cannot accept multiple node directories]"],
     30    ]
     31
     32def do_start(basedir, opts, out=sys.stdout, err=sys.stderr):
    4033    print >>out, "STARTING", quote_output(basedir)
    4134    if not os.path.isdir(basedir):
     
    6558        args.extend(["--profile=profiling_results.prof", "--savestats",])
    6659    # now we're committed
    67     if fork:
    68         if os.fork() != 0:
    69             return 0 # parent
    70         # we're in the child
    7160    os.chdir(basedir)
    7261    from twisted.scripts import twistd
     
    135124def start(config, stdout, stderr):
    136125    rc = 0
    137     for basedir in config['basedirs'][:-1]:
    138         # fork before starting all but the last one
    139         rc = do_start(basedir, config, stdout, stderr, fork=True) or rc
    140     # start the last one in the current process, to capture its exit code
    141     rc = do_start(config['basedirs'][-1], config, stdout, stderr, fork=False) or rc
     126    for basedir in config['basedirs']:
     127        rc = do_start(basedir, config, stdout, stderr) or rc
    142128    return rc
    143129
     
    158144        print >>stderr, "not restarting"
    159145        return rc
    160     rc = start(config, stdout, stderr) or rc
     146    for basedir in config['basedirs']:
     147        rc = do_start(basedir, config, stdout, stderr) or rc
    161148    return rc
    162149
  • TabularUnified src/allmydata/test/test_runner.py

    rf3adb03 rf36bda2  
    579579        return d
    580580
    581     def test_multiple_clients(self):
    582         self.skip_if_cannot_daemonize()
    583         basedir = self.workdir("test_multiple_clients")
    584         # this furl must be syntactically correct, else 'tahoe start' will
    585         # correctly report an error. It doesn't need to point at a real
    586         # introducer.
    587         introducer_furl = "pb://xrndsskn2zuuian5ltnxrte7lnuqdrkz@127.0.0.1:55617/introducer"
    588         c1 = os.path.join(basedir, "c1")
    589         HOTLINE_FILE_1 = os.path.join(c1, "suicide_prevention_hotline")
    590         TWISTD_PID_FILE_1 = os.path.join(c1, "twistd.pid")
    591         PORTNUMFILE_1 = os.path.join(c1, "client.port")
    592         c1_args = ["--quiet", "create-node", "--basedir", c1, "--webport", "0",
    593                    "--introducer", introducer_furl]
    594 
    595         c2 = os.path.join(basedir, "c2")
    596         HOTLINE_FILE_2 = os.path.join(c2, "suicide_prevention_hotline")
    597         TWISTD_PID_FILE_2 = os.path.join(c2, "twistd.pid")
    598         PORTNUMFILE_2 = os.path.join(c2, "client.port")
    599         c2_args = ["--quiet", "create-node", "--basedir", c2, "--webport", "0",
    600                    "--introducer", introducer_furl]
    601 
    602         d = utils.getProcessOutputAndValue(bintahoe, args=c1_args, env=os.environ)
    603         def _cb1(res):
    604             out, err, rc_or_sig = res
    605             self.failUnlessEqual(rc_or_sig, 0)
    606             return utils.getProcessOutputAndValue(bintahoe, args=c2_args,
    607                                                   env=os.environ)
    608         d.addCallback(_cb1)
    609         def _cb2(res):
    610             out, err, rc_or_sig = res
    611             self.failUnlessEqual(rc_or_sig, 0)
    612             # both nodes have been constructed, but they are not yet running
    613 
    614             # By writing this file, we get sixty seconds before the client
    615             # will exit. This insures that even if the 'stop' command doesn't
    616             # work (and the test fails), the client should still terminate.
    617             open(HOTLINE_FILE_1, "w").write("")
    618             open(HOTLINE_FILE_2, "w").write("")
    619             # now it's safe to start the nodes
    620             start_args = ["--quiet", "start", "-m", c1, c2]
    621             return utils.getProcessOutputAndValue(bintahoe, args=start_args,
    622                                                   env=os.environ)
    623         d.addCallback(_cb2)
    624 
    625         def _nodes_have_started():
    626             open(HOTLINE_FILE_1, "w").write("")
    627             open(HOTLINE_FILE_2, "w").write("")
    628             return (os.path.exists(PORTNUMFILE_1)
    629                     and os.path.exists(PORTNUMFILE_2))
    630 
    631         def _cb3(res):
    632             out, err, rc_or_sig = res
    633             open(HOTLINE_FILE_1, "w").write("")
    634             open(HOTLINE_FILE_2, "w").write("")
    635             errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
    636             self.failUnlessEqual(rc_or_sig, 0, errstr)
    637             self.failUnlessEqual(out, "", errstr)
    638             # See test_client_no_noise -- for now we ignore noise.
    639             # self.failUnlessEqual(err, "", errstr)
    640 
    641             # if 'tahoe start' exited without error, we're guaranteed that it
    642             # successfully loaded the code and tahoe.cfg for the last node
    643             # (argv[-1]), since these happen before twistd.run() calls
    644             # fork(). There made have been a runtime error after fork().
    645             # Also, there may have been an import or config error while
    646             # loading any of the earlier nodes (argv[:-1]), since 'tahoe
    647             # start' must do an additional fork before calling twistd.run()
    648             # on those.
    649 
    650             # so watch the filesystem to determine when the nodes have
    651             # started running
    652 
    653             return self.poll(_nodes_have_started)
    654         d.addCallback(_cb3)
    655 
    656         def _restart(ign):
    657             # delete the port-number files, then restart the nodes. The new
    658             # instances will re-write those files.
    659             os.unlink(PORTNUMFILE_1)
    660             os.unlink(PORTNUMFILE_2)
    661             restart_args = ["--quiet", "restart", "-m", c1, c2]
    662             return utils.getProcessOutputAndValue(bintahoe, args=restart_args,
    663                                                   env=os.environ)
    664         d.addCallback(_restart)
    665         def _did_restart(res):
    666             out, err, rc_or_sig = res
    667             errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
    668             self.failUnlessEqual(rc_or_sig, 0, errstr)
    669             self.failUnlessEqual(out, "", errstr)
    670             # See test_client_no_noise -- for now we ignore noise.
    671             # self.failUnlessEqual(err, "", errstr)
    672 
    673             # we must still poll for the startup process to get far enough
    674             return self.poll(_nodes_have_started)
    675         d.addCallback(_did_restart)
    676         # when that finishes, we know the nodes have restarted. If 'tahoe
    677         # restart -m' is broken, that will time out.
    678 
    679         # now we can kill it. TODO: On a slow machine, the node might kill
    680         # itself before we get a chance too, especially if spawning the
    681         # 'tahoe stop' command takes a while.
    682         def _stop(res):
    683             open(HOTLINE_FILE_1, "w").write("")
    684             open(HOTLINE_FILE_2, "w").write("")
    685             self.failUnless(os.path.exists(TWISTD_PID_FILE_1),
    686                             (TWISTD_PID_FILE_1, os.listdir(c1)))
    687             self.failUnless(os.path.exists(TWISTD_PID_FILE_2),
    688                             (TWISTD_PID_FILE_2, os.listdir(c2)))
    689             stop_args = ["--quiet", "stop", "-m", c1, c2]
    690             return utils.getProcessOutputAndValue(bintahoe, args=stop_args,
    691                                                   env=os.environ)
    692         d.addCallback(_stop)
    693 
    694         def _cb4(res):
    695             out, err, rc_or_sig = res
    696             errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
    697             self.failUnlessEqual(rc_or_sig, 0, errstr)
    698             self.failUnlessEqual(out, "", errstr)
    699             # See test_client_no_noise -- for now we ignore noise.
    700             # self.failUnlessEqual(err, "", errstr)
    701 
    702             # the parent was supposed to poll and wait until it sees
    703             # twistd.pid go away before it exits, so twistd.pid should be
    704             # gone by now.
    705             self.failIf(os.path.exists(TWISTD_PID_FILE_1))
    706             self.failIf(os.path.exists(TWISTD_PID_FILE_2))
    707         d.addCallback(_cb4)
    708         def _remove_hotline(res):
    709             # always remove these, so that if something went wrong, the nodes
    710             # will quit eventually
    711             os.unlink(HOTLINE_FILE_1)
    712             os.unlink(HOTLINE_FILE_2)
    713             return res
    714         d.addBoth(_remove_hotline)
    715         return d
    716 
    717 
    718581    def test_baddir(self):
    719582        self.skip_if_cannot_daemonize()
Note: See TracChangeset for help on using the changeset viewer.