Ticket #937: run-introducer.diff

File run-introducer.diff, 3.0 KB (added by warner, at 2012-05-21T05:45:49Z)

enable 'tahoe run' for introducer nodes

  • src/allmydata/scripts/startstop_node.py

    diff --git a/src/allmydata/scripts/startstop_node.py b/src/allmydata/scripts/startstop_node.py
    index 5045bd6..9a5417e 100644
    a b def restart(config, stdout, stderr): 
    149149def run(config, stdout, stderr):
    150150    from twisted.internet import reactor
    151151    from twisted.python import log, logfile
    152     from allmydata import client
    153152
    154153    basedir = config['basedir']
    155154    precondition(isinstance(basedir, unicode), basedir)
    def run(config, stdout, stderr): 
    164163    else:
    165164        print >>stderr, "%s does not look like a node directory (no .tac file)" % quote_output(basedir)
    166165        return 1
    167     if "client" not in tac:
    168         print >>stderr, ("%s looks like it contains a non-client node (%s).\n"
    169                          "Use 'tahoe start' instead of 'tahoe run'."
    170                          % (quote_output(basedir), tac))
    171         return 1
    172166
    173167    os.chdir(basedir)
    174168
     169    if tac == "tahoe-client.tac":
     170        from allmydata import client
     171        nodetype = client.Client
     172    elif tac == "tahoe-introducer.tac":
     173        from allmydata.introducer.server import IntroducerNode
     174        nodetype = IntroducerNode
     175    else:
     176        print >>stderr, ("I don't know how to start the node in %s\n"
     177                         "(I only know how to start clients and introducers)\n"
     178                         "Please use 'tahoe start' instead of 'tahoe run'."
     179                         % (quote_output(basedir),))
     180        return 1
     181
    175182    # set up twisted logging. this will become part of the node rsn.
    176183    logdir = os.path.join(basedir, 'logs')
    177184    if not os.path.exists(logdir):
    def run(config, stdout, stderr): 
    180187    log.startLogging(lf)
    181188
    182189    # run the node itself
    183     c = client.Client(basedir)
     190    c = nodetype(basedir)
    184191    reactor.callLater(0, c.startService) # after reactor startup
    185192    reactor.run()
    186193
  • src/allmydata/test/test_runner.py

    diff --git a/src/allmydata/test/test_runner.py b/src/allmydata/test/test_runner.py
    index 4e9f683..82be33b 100644
    a b class RunNode(common_util.SignalMixin, unittest.TestCase, pollmixin.PollMixin, 
    687687            self.failUnlessEqual(rc_or_sig, 1)
    688688            self.failUnless("does not look like a directory at all" in err, err)
    689689        d.addCallback(_cb3)
     690
     691        def _then_run_in_unknown_dir(res):
     692            unknowndir = os.path.join(basedir, "unknown")
     693            fileutil.make_dirs(unknowndir)
     694            fileutil.write(os.path.join(unknowndir, "unknown.tac"), "")
     695            return self.run_bintahoe(["--quiet", "run", "--basedir", unknowndir])
     696        d.addCallback(_then_run_in_unknown_dir)
     697        def _cb4(res):
     698            out, err, rc_or_sig = res
     699            self.failUnlessEqual(rc_or_sig, 1)
     700            self.failUnlessIn("I don't know how to start the node in", err)
     701        d.addCallback(_cb4)
     702
    690703        return d
    691704
    692705    def test_keygen(self):