Changeset 647ebce6 in trunk
- Timestamp:
- 2014-08-17T14:51:19Z (11 years ago)
- Branches:
- master
- Children:
- 91077f0
- Parents:
- 8f303df
- git-author:
- Daira Hopwood <daira@…> (2014-08-17 14:36:57)
- git-committer:
- Daira Hopwood <daira@…> (2014-08-17 14:51:19)
- Location:
- src/allmydata
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/allmydata/client.py ¶
r8f303df r647ebce6 110 110 STOREDIR = 'storage' 111 111 NODETYPE = "client" 112 SUICIDE_PREVENTION_HOTLINE_FILE = "suicide_prevention_hotline"112 EXIT_TRIGGER_FILE = "exit_trigger" 113 113 114 114 # This means that if a storage server treats me as though I were a … … 151 151 self.init_drop_uploader() 152 152 153 hotline_file = os.path.join(self.basedir, 154 self.SUICIDE_PREVENTION_HOTLINE_FILE) 155 if os.path.exists(hotline_file): 156 age = time.time() - os.stat(hotline_file)[stat.ST_MTIME] 157 self.log("hotline file noticed (%ds old), starting timer" % age) 158 hotline = TimerService(1.0, self._check_hotline, hotline_file) 159 hotline.setServiceParent(self) 153 # If the node sees an exit_trigger file, it will poll every second to see 154 # whether the file still exists, and what its mtime is. If the file does not 155 # exist or has not been modified for a given timeout, the node will exit. 156 exit_trigger_file = os.path.join(self.basedir, 157 self.EXIT_TRIGGER_FILE) 158 if os.path.exists(exit_trigger_file): 159 age = time.time() - os.stat(exit_trigger_file)[stat.ST_MTIME] 160 self.log("%s file noticed (%ds old), starting timer" % (self.EXIT_TRIGGER_FILE, age)) 161 exit_trigger = TimerService(1.0, self._check_exit_trigger, exit_trigger_file) 162 exit_trigger.setServiceParent(self) 160 163 161 164 # this needs to happen last, so it can use getServiceNamed() to … … 493 496 self.log("couldn't start drop-uploader: %r", args=(e,)) 494 497 495 def _check_ hotline(self, hotline_file):496 if os.path.exists( hotline_file):497 mtime = os.stat( hotline_file)[stat.ST_MTIME]498 def _check_exit_trigger(self, exit_trigger_file): 499 if os.path.exists(exit_trigger_file): 500 mtime = os.stat(exit_trigger_file)[stat.ST_MTIME] 498 501 if mtime > time.time() - 120.0: 499 502 return 500 503 else: 501 self.log(" hotline file too old, shutting down")504 self.log("%s file too old, shutting down" % (self.EXIT_TRIGGER_FILE,)) 502 505 else: 503 self.log(" hotline file missing, shutting down")506 self.log("%s file missing, shutting down" % (self.EXIT_TRIGGER_FILE,)) 504 507 reactor.stop() 505 508 -
TabularUnified src/allmydata/test/check_memory.py ¶
r8f303df r647ebce6 146 146 def tearDown(self, passthrough): 147 147 # the client node will shut down in a few seconds 148 #os.remove(os.path.join(self.clientdir, "suicide_prevention_hotline"))148 #os.remove(os.path.join(self.clientdir, client.Client.EXIT_TRIGGER_FILE)) 149 149 log.msg("shutting down SystemTest services") 150 150 if self.keepalive_file and os.path.exists(self.keepalive_file): … … 256 256 f.close() 257 257 self.keepalive_file = os.path.join(clientdir, 258 "suicide_prevention_hotline")258 client.Client.EXIT_TRIGGER_FILE) 259 259 # now start updating the mtime. 260 260 self.touch_keepalive() -
TabularUnified src/allmydata/test/test_client.py ¶
r8f303df r647ebce6 318 318 dummy = "pb://wl74cyahejagspqgy4x5ukrvfnevlknt@127.0.0.1:58889/bogus" 319 319 fileutil.write(os.path.join(basedir, "tahoe.cfg"), BASECONFIG_I % dummy) 320 fileutil.write(os.path.join(basedir, "suicide_prevention_hotline"), "")320 fileutil.write(os.path.join(basedir, client.Client.EXIT_TRIGGER_FILE), "") 321 321 client.Client(basedir) 322 322 … … 341 341 def _restart(res): 342 342 # TODO: pause for slightly over one second, to let 343 # Client._check_ hotlinepoll the file once. That will exercise343 # Client._check_exit_trigger poll the file once. That will exercise 344 344 # another few lines. Then add another test in which we don't 345 # update the file at all, and watch to see the node shutdown. (to346 # do this, use a modified node which overrides Node.shutdown(),347 # also change _check_ hotlineto use it instead of a raw345 # update the file at all, and watch to see the node shutdown. 346 # (To do this, use a modified node which overrides Node.shutdown(), 347 # also change _check_exit_trigger to use it instead of a raw 348 348 # reactor.stop, also instrument the shutdown event in an 349 # attribute that we can check )349 # attribute that we can check.) 350 350 c2 = client.Client(basedir) 351 351 c2.setServiceParent(self.sparent) -
TabularUnified src/allmydata/test/test_runner.py ¶
r8f303df r647ebce6 1 import os.path, re, sys, subprocess 2 from cStringIO import StringIO 3 1 4 from twisted.trial import unittest 2 5 … … 4 7 from twisted.internet import threads 5 8 6 import os.path, re, sys, subprocess7 from cStringIO import StringIO8 9 from allmydata.util import fileutil, pollmixin 9 10 from allmydata.util.encodingutil import unicode_to_argv, unicode_to_output, get_filesystem_encoding 10 11 from allmydata.scripts import runner 11 12 from allmydata.client import Client 12 13 from allmydata.test import common_util 13 14 import allmydata 15 14 16 15 17 timeout = 240 … … 358 360 basedir = self.workdir("test_introducer") 359 361 c1 = os.path.join(basedir, "c1") 360 HOTLINE_FILE = os.path.join(c1, "suicide_prevention_hotline")362 exit_trigger_file = os.path.join(c1, Client.EXIT_TRIGGER_FILE) 361 363 TWISTD_PID_FILE = os.path.join(c1, "twistd.pid") 362 364 INTRODUCER_FURL_FILE = os.path.join(c1, "private", "introducer.furl") … … 379 381 # exit. This insures that even if the test fails (and the 'stop' 380 382 # command doesn't work), the client should still terminate. 381 fileutil.write( HOTLINE_FILE, "")383 fileutil.write(exit_trigger_file, "") 382 384 # now it's safe to start the node 383 385 d.addCallback(_cb) … … 390 392 out, err, rc_or_sig = res 391 393 392 fileutil.write( HOTLINE_FILE, "")394 fileutil.write(exit_trigger_file, "") 393 395 errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err) 394 396 self.failUnlessEqual(rc_or_sig, 0, errstr) … … 417 419 self.portnum = fileutil.read(PORTNUM_FILE) 418 420 419 fileutil.write( HOTLINE_FILE, "")421 fileutil.write(exit_trigger_file, "") 420 422 self.failUnless(os.path.exists(TWISTD_PID_FILE)) 421 423 self.failUnless(os.path.exists(NODE_URL_FILE)) … … 428 430 def _then(res): 429 431 out, err, rc_or_sig = res 430 fileutil.write( HOTLINE_FILE, "")432 fileutil.write(exit_trigger_file, "") 431 433 errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err) 432 434 self.failUnlessEqual(rc_or_sig, 0, errstr) … … 452 454 # 'tahoe stop' command takes a while. 453 455 def _stop(res): 454 fileutil.write( HOTLINE_FILE, "")456 fileutil.write(exit_trigger_file, "") 455 457 self.failUnless(os.path.exists(TWISTD_PID_FILE)) 456 458 … … 460 462 def _after_stopping(res): 461 463 out, err, rc_or_sig = res 462 fileutil.write( HOTLINE_FILE, "")464 fileutil.write(exit_trigger_file, "") 463 465 # the parent has exited by now 464 466 errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err) … … 471 473 self.failIf(os.path.exists(TWISTD_PID_FILE)) 472 474 d.addCallback(_after_stopping) 473 d.addBoth(self._remove, HOTLINE_FILE)475 d.addBoth(self._remove, exit_trigger_file) 474 476 return d 475 477 # This test has hit a 240-second timeout on our feisty2.5 buildslave, and a 480-second timeout … … 482 484 basedir = self.workdir("test_client_no_noise") 483 485 c1 = os.path.join(basedir, "c1") 484 HOTLINE_FILE = os.path.join(c1, "suicide_prevention_hotline")486 exit_trigger_file = os.path.join(c1, Client.EXIT_TRIGGER_FILE) 485 487 TWISTD_PID_FILE = os.path.join(c1, "twistd.pid") 486 488 PORTNUM_FILE = os.path.join(c1, "client.port") … … 496 498 # that even if the 'stop' command doesn't work (and the test fails), the client should 497 499 # still terminate. 498 fileutil.write( HOTLINE_FILE, "")500 fileutil.write(exit_trigger_file, "") 499 501 # now it's safe to start the node 500 502 d.addCallback(_cb) … … 507 509 out, err, rc_or_sig = res 508 510 errstr = "cc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err) 509 fileutil.write( HOTLINE_FILE, "")511 fileutil.write(exit_trigger_file, "") 510 512 self.failUnlessEqual(rc_or_sig, 0, errstr) 511 513 self.failUnlessEqual(out, "", errstr) # If you emit noise, you fail this test. … … 537 539 return self.run_bintahoe(["--quiet", "stop", c1]) 538 540 d.addCallback(_stop) 539 d.addBoth(self._remove, HOTLINE_FILE)541 d.addBoth(self._remove, exit_trigger_file) 540 542 return d 541 543 … … 544 546 basedir = self.workdir("test_client") 545 547 c1 = os.path.join(basedir, "c1") 546 HOTLINE_FILE = os.path.join(c1, "suicide_prevention_hotline")548 exit_trigger_file = os.path.join(c1, Client.EXIT_TRIGGER_FILE) 547 549 TWISTD_PID_FILE = os.path.join(c1, "twistd.pid") 548 550 PORTNUM_FILE = os.path.join(c1, "client.port") … … 562 564 # that even if the 'stop' command doesn't work (and the test fails), the client should 563 565 # still terminate. 564 fileutil.write( HOTLINE_FILE, "")566 fileutil.write(exit_trigger_file, "") 565 567 # now it's safe to start the node 566 568 d.addCallback(_cb) … … 572 574 def _cb2(res): 573 575 out, err, rc_or_sig = res 574 fileutil.write( HOTLINE_FILE, "")576 fileutil.write(exit_trigger_file, "") 575 577 errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err) 576 578 self.failUnlessEqual(rc_or_sig, 0, errstr) … … 598 600 self.portnum = fileutil.read(PORTNUM_FILE) 599 601 600 fileutil.write( HOTLINE_FILE, "")602 fileutil.write(exit_trigger_file, "") 601 603 self.failUnless(os.path.exists(TWISTD_PID_FILE)) 602 604 … … 609 611 out, err, rc_or_sig = res 610 612 611 fileutil.write( HOTLINE_FILE, "")613 fileutil.write(exit_trigger_file, "") 612 614 errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err) 613 615 self.failUnlessEqual(rc_or_sig, 0, errstr) … … 628 630 # 'tahoe stop' command takes a while. 629 631 def _stop(res): 630 fileutil.write( HOTLINE_FILE, "")632 fileutil.write(exit_trigger_file, "") 631 633 self.failUnless(os.path.exists(TWISTD_PID_FILE), 632 634 (TWISTD_PID_FILE, … … 638 640 out, err, rc_or_sig = res 639 641 640 fileutil.write( HOTLINE_FILE, "")642 fileutil.write(exit_trigger_file, "") 641 643 # the parent has exited by now 642 644 errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err) … … 649 651 self.failIf(os.path.exists(TWISTD_PID_FILE)) 650 652 d.addCallback(_cb4) 651 d.addBoth(self._remove, HOTLINE_FILE)653 d.addBoth(self._remove, exit_trigger_file) 652 654 return d 653 655
Note: See TracChangeset
for help on using the changeset viewer.