PORTNUMFILE = "client.port"
STOREDIR = 'storage'
NODETYPE = "client"
- SUICIDE_PREVENTION_HOTLINE_FILE = "suicide_prevention_hotline"
+ EXIT_TRIGGER_FILE = "exit_trigger"
# This means that if a storage server treats me as though I were a
# 1.0.0 storage client, it will work as they expect.
self.init_sftp_server()
self.init_drop_uploader()
- hotline_file = os.path.join(self.basedir,
- self.SUICIDE_PREVENTION_HOTLINE_FILE)
- if os.path.exists(hotline_file):
- age = time.time() - os.stat(hotline_file)[stat.ST_MTIME]
- self.log("hotline file noticed (%ds old), starting timer" % age)
- hotline = TimerService(1.0, self._check_hotline, hotline_file)
- hotline.setServiceParent(self)
+ # If the node sees an exit_trigger file, it will poll every second to see
+ # whether the file still exists, and what its mtime is. If the file does not
+ # exist or has not been modified for a given timeout, the node will exit.
+ exit_trigger_file = os.path.join(self.basedir,
+ self.EXIT_TRIGGER_FILE)
+ if os.path.exists(exit_trigger_file):
+ age = time.time() - os.stat(exit_trigger_file)[stat.ST_MTIME]
+ self.log("%s file noticed (%ds old), starting timer" % (self.EXIT_TRIGGER_FILE, age))
+ exit_trigger = TimerService(1.0, self._check_exit_trigger, exit_trigger_file)
+ exit_trigger.setServiceParent(self)
# this needs to happen last, so it can use getServiceNamed() to
# acquire references to StorageServer and other web-statusable things
except Exception, e:
self.log("couldn't start drop-uploader: %r", args=(e,))
- def _check_hotline(self, hotline_file):
- if os.path.exists(hotline_file):
- mtime = os.stat(hotline_file)[stat.ST_MTIME]
+ def _check_exit_trigger(self, exit_trigger_file):
+ if os.path.exists(exit_trigger_file):
+ mtime = os.stat(exit_trigger_file)[stat.ST_MTIME]
if mtime > time.time() - 120.0:
return
else:
- self.log("hotline file too old, shutting down")
+ self.log("%s file too old, shutting down" % (self.EXIT_TRIGGER_FILE,))
else:
- self.log("hotline file missing, shutting down")
+ self.log("%s file missing, shutting down" % (self.EXIT_TRIGGER_FILE,))
reactor.stop()
def get_encoding_parameters(self):
+import os.path, re, sys, subprocess
+from cStringIO import StringIO
+
from twisted.trial import unittest
from twisted.python import usage, runtime
from twisted.internet import threads
-import os.path, re, sys, subprocess
-from cStringIO import StringIO
from allmydata.util import fileutil, pollmixin
from allmydata.util.encodingutil import unicode_to_argv, unicode_to_output, get_filesystem_encoding
from allmydata.scripts import runner
-
+from allmydata.client import Client
from allmydata.test import common_util
import allmydata
+
timeout = 240
def get_root_from_file(src):
self.skip_if_cannot_daemonize()
basedir = self.workdir("test_introducer")
c1 = os.path.join(basedir, "c1")
- HOTLINE_FILE = os.path.join(c1, "suicide_prevention_hotline")
+ exit_trigger_file = os.path.join(c1, Client.EXIT_TRIGGER_FILE)
TWISTD_PID_FILE = os.path.join(c1, "twistd.pid")
INTRODUCER_FURL_FILE = os.path.join(c1, "private", "introducer.furl")
PORTNUM_FILE = os.path.join(c1, "introducer.port")
# by writing this file, we get ten seconds before the node will
# exit. This insures that even if the test fails (and the 'stop'
# command doesn't work), the client should still terminate.
- fileutil.write(HOTLINE_FILE, "")
+ fileutil.write(exit_trigger_file, "")
# now it's safe to start the node
d.addCallback(_cb)
def _cb2(res):
out, err, rc_or_sig = res
- fileutil.write(HOTLINE_FILE, "")
+ fileutil.write(exit_trigger_file, "")
errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
self.failUnlessEqual(rc_or_sig, 0, errstr)
self.failUnlessEqual(out, "", errstr)
self.failUnless(os.path.exists(PORTNUM_FILE))
self.portnum = fileutil.read(PORTNUM_FILE)
- fileutil.write(HOTLINE_FILE, "")
+ fileutil.write(exit_trigger_file, "")
self.failUnless(os.path.exists(TWISTD_PID_FILE))
self.failUnless(os.path.exists(NODE_URL_FILE))
def _then(res):
out, err, rc_or_sig = res
- fileutil.write(HOTLINE_FILE, "")
+ fileutil.write(exit_trigger_file, "")
errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
self.failUnlessEqual(rc_or_sig, 0, errstr)
self.failUnlessEqual(out, "", errstr)
# itself before we get a chance to, especially if spawning the
# 'tahoe stop' command takes a while.
def _stop(res):
- fileutil.write(HOTLINE_FILE, "")
+ fileutil.write(exit_trigger_file, "")
self.failUnless(os.path.exists(TWISTD_PID_FILE))
return self.run_bintahoe(["--quiet", "stop", c1])
def _after_stopping(res):
out, err, rc_or_sig = res
- fileutil.write(HOTLINE_FILE, "")
+ fileutil.write(exit_trigger_file, "")
# the parent has exited by now
errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
self.failUnlessEqual(rc_or_sig, 0, errstr)
# gone by now.
self.failIf(os.path.exists(TWISTD_PID_FILE))
d.addCallback(_after_stopping)
- d.addBoth(self._remove, HOTLINE_FILE)
+ d.addBoth(self._remove, exit_trigger_file)
return d
# This test has hit a 240-second timeout on our feisty2.5 buildslave, and a 480-second timeout
# on Francois's Lenny-armv5tel buildslave.
basedir = self.workdir("test_client_no_noise")
c1 = os.path.join(basedir, "c1")
- HOTLINE_FILE = os.path.join(c1, "suicide_prevention_hotline")
+ exit_trigger_file = os.path.join(c1, Client.EXIT_TRIGGER_FILE)
TWISTD_PID_FILE = os.path.join(c1, "twistd.pid")
PORTNUM_FILE = os.path.join(c1, "client.port")
# By writing this file, we get two minutes before the client will exit. This ensures
# that even if the 'stop' command doesn't work (and the test fails), the client should
# still terminate.
- fileutil.write(HOTLINE_FILE, "")
+ fileutil.write(exit_trigger_file, "")
# now it's safe to start the node
d.addCallback(_cb)
def _cb2(res):
out, err, rc_or_sig = res
errstr = "cc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
- fileutil.write(HOTLINE_FILE, "")
+ fileutil.write(exit_trigger_file, "")
self.failUnlessEqual(rc_or_sig, 0, errstr)
self.failUnlessEqual(out, "", errstr) # If you emit noise, you fail this test.
errlines = err.split("\n")
self.failUnless(os.path.exists(TWISTD_PID_FILE), (TWISTD_PID_FILE, os.listdir(os.path.dirname(TWISTD_PID_FILE))))
return self.run_bintahoe(["--quiet", "stop", c1])
d.addCallback(_stop)
- d.addBoth(self._remove, HOTLINE_FILE)
+ d.addBoth(self._remove, exit_trigger_file)
return d
def test_client(self):
self.skip_if_cannot_daemonize()
basedir = self.workdir("test_client")
c1 = os.path.join(basedir, "c1")
- HOTLINE_FILE = os.path.join(c1, "suicide_prevention_hotline")
+ exit_trigger_file = os.path.join(c1, Client.EXIT_TRIGGER_FILE)
TWISTD_PID_FILE = os.path.join(c1, "twistd.pid")
PORTNUM_FILE = os.path.join(c1, "client.port")
NODE_URL_FILE = os.path.join(c1, "node.url")
# By writing this file, we get two minutes before the client will exit. This ensures
# that even if the 'stop' command doesn't work (and the test fails), the client should
# still terminate.
- fileutil.write(HOTLINE_FILE, "")
+ fileutil.write(exit_trigger_file, "")
# now it's safe to start the node
d.addCallback(_cb)
def _cb2(res):
out, err, rc_or_sig = res
- fileutil.write(HOTLINE_FILE, "")
+ fileutil.write(exit_trigger_file, "")
errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
self.failUnlessEqual(rc_or_sig, 0, errstr)
self.failUnlessEqual(out, "", errstr)
# don't change on restart
self.portnum = fileutil.read(PORTNUM_FILE)
- fileutil.write(HOTLINE_FILE, "")
+ fileutil.write(exit_trigger_file, "")
self.failUnless(os.path.exists(TWISTD_PID_FILE))
# rm this so we can detect when the second incarnation is ready
def _cb3(res):
out, err, rc_or_sig = res
- fileutil.write(HOTLINE_FILE, "")
+ fileutil.write(exit_trigger_file, "")
errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
self.failUnlessEqual(rc_or_sig, 0, errstr)
self.failUnlessEqual(out, "", errstr)
# itself before we get a chance to, especially if spawning the
# 'tahoe stop' command takes a while.
def _stop(res):
- fileutil.write(HOTLINE_FILE, "")
+ fileutil.write(exit_trigger_file, "")
self.failUnless(os.path.exists(TWISTD_PID_FILE),
(TWISTD_PID_FILE,
os.listdir(os.path.dirname(TWISTD_PID_FILE))))
def _cb4(res):
out, err, rc_or_sig = res
- fileutil.write(HOTLINE_FILE, "")
+ fileutil.write(exit_trigger_file, "")
# the parent has exited by now
errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
self.failUnlessEqual(rc_or_sig, 0, errstr)
# gone by now.
self.failIf(os.path.exists(TWISTD_PID_FILE))
d.addCallback(_cb4)
- d.addBoth(self._remove, HOTLINE_FILE)
+ d.addBoth(self._remove, exit_trigger_file)
return d
def _remove(self, res, file):