Changeset 450:cc102304fe0e
- Timestamp:
- 08/01/08 15:03:16 (5 months ago)
- Files:
-
- ChangeLog (modified) (1 diff)
- foolscap/logging/gatherer.py (modified) (9 diffs)
- foolscap/test/test_logging.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
ChangeLog
r449 r450 1 1 2008-08-01 Brian Warner <warner@lothar.com> 2 3 * foolscap/logging/gatherer.py (IncidentGathererService): get 4 control over stdout, so we can exercise more code during tests 5 (IncidentGathererService.startService): oops, this needs to be 6 startService instead of start 7 8 * foolscap/test/test_logging.py (IncidentGatherer): basic test of 9 an incident gatherer, just setup and connection so far 2 10 3 11 * foolscap/test/common.py (StallMixin): factor stall() out into a foolscap/logging/gatherer.py
r444 r450 294 294 implements(RILogObserver) 295 295 296 def __init__(self, basedir, nodeid_s, gatherer, publisher ):296 def __init__(self, basedir, nodeid_s, gatherer, publisher, stdout): 297 297 if not os.path.isdir(basedir): 298 298 os.makedirs(basedir) … … 301 301 self.gatherer = gatherer 302 302 self.publisher = publisher 303 self.stdout = stdout 304 self.caught_up_d = defer.Deferred() 303 305 304 306 def connect(self): … … 311 313 except EnvironmentError: 312 314 pass 313 print "connected to %s, last known incident is %s" % (self.nodeid_s,314 latest)315 print >>self.stdout, "connected to %s, last known incident is %s" \ 316 % (self.nodeid_s, latest) 315 317 # now subscribe to everything since then 316 318 d = self.publisher.callRemote("subscribe_to_incidents", self, 317 319 catch_up=True, since=latest) 320 # for testing, we arrange for this Deferred (which governs the return 321 # from remote_logport) to not fire until we've finished catching up 322 # on all incidents. 323 d.addCallback(lambda res: self.caught_up_d) 318 324 return d 319 325 320 326 def remote_new_incident(self, name, trigger): 321 print "got incident", name327 print >>self.stdout, "got incident", name 322 328 # name= should look like "incident-2008-07-29-204211-aspkxoi". We 323 329 # prevent name= from containing path metacharacters like / or : by … … 357 363 358 364 def remote_done_with_incident_catchup(self): 365 self.caught_up_d.callback(None) 359 366 return None 360 367 … … 386 393 tacFile = "incident-gatherer.tac" 387 394 388 def __init__(self, classifiers=[], basedir=None ):395 def __init__(self, classifiers=[], basedir=None, stdout=None): 389 396 GatheringBase.__init__(self, basedir) 390 397 self.classifiers = [] 391 398 self.classifiers.extend(classifiers) 399 self.stdout = stdout 392 400 393 401 def addClassifier(self, f): … … 395 403 396 404 397 def start (self, res):405 def startService(self): 398 406 indir = os.path.join(self.basedir, "incidents") 399 407 if not os.path.isdir(indir): … … 403 411 os.makedirs(outputdir) 404 412 self.classify_stored_incidents(indir) 405 return GatheringBase.start(self, res)413 GatheringBase.startService(self) 406 414 407 415 def classify_stored_incidents(self, indir): 408 print "No classified/ directory: reclassifying stored incidents" 416 stdout = self.stdout or sys.stdout 417 print >>stdout, "No classified/ directory: reclassifying stored incidents" 409 418 # now classify all stored incidents 410 419 for nodeid_s in os.listdir(indir): … … 438 447 raise BadTubID("%s is not a valid base32-encoded Tub ID" % tubid_s) 439 448 basedir = os.path.join(self.basedir, "incidents", tubid_s) 440 o = IncidentObserver(basedir, tubid_s, self, publisher) 449 stdout = self.stdout or sys.stdout 450 o = IncidentObserver(basedir, tubid_s, self, publisher, stdout) 441 451 d = o.connect() 442 452 d.addCallback(lambda res: None) … … 444 454 445 455 def new_incident(self, abs_fn, rel_fn, nodeid_s, incident): 446 print "NEW INCIDENT", rel_fn 456 stdout = self.stdout or sys.stdout 457 print >>stdout, "NEW INCIDENT", rel_fn 447 458 self.classify_incident(rel_fn, nodeid_s, incident) 448 459 foolscap/test/test_logging.py
r448 r450 14 14 from foolscap import Referenceable 15 15 from foolscap.tokens import NoLocationError 16 from foolscap.test.common import PollMixin, GoodEnoughTub16 from foolscap.test.common import PollMixin, StallMixin, GoodEnoughTub 17 17 18 18 … … 866 866 test_subscribe.timeout = 20 867 867 868 class Gatherer(PollMixin, unittest.TestCase, LogfileReaderMixin): 868 class MyIncidentGathererService(gatherer.IncidentGathererService): 869 verbose = False 870 871 def remote_logport(self, nodeid, publisher): 872 d = gatherer.IncidentGathererService.remote_logport(self, 873 nodeid, publisher) 874 d.addCallback(lambda res: self.d.callback(publisher)) 875 return d 876 877 class IncidentGatherer(unittest.TestCase, 878 PollMixin, StallMixin, LogfileReaderMixin): 879 def setUp(self): 880 self.parent = service.MultiService() 881 self.parent.startService() 882 self.logger = log.FoolscapLogger() 883 884 def tearDown(self): 885 d = defer.succeed(None) 886 d.addCallback(lambda res: self.parent.stopService()) 887 d.addCallback(flushEventualQueue) 888 return d 889 890 def test_incident_gatherer(self): 891 basedir = "logging/IncidentGatherer/incident_gatherer" 892 os.makedirs(basedir) 893 self.logger.setLogDir(basedir) 894 895 # create an incident gatherer, which will make its own Tub 896 ig_basedir = os.path.join(basedir, "ig") 897 os.makedirs(ig_basedir) 898 null = StringIO() 899 ig = MyIncidentGathererService(basedir=ig_basedir, stdout=null) 900 ig.tub_class = GoodEnoughTub 901 ig.d = defer.Deferred() 902 ig.setServiceParent(self.parent) 903 904 t = GoodEnoughTub() 905 t.logger = self.logger 906 t.setServiceParent(self.parent) 907 l = t.listenOn("tcp:0:interface=127.0.0.1") 908 t.setLocation("127.0.0.1:%d" % l.getPortnum()) 909 t.setOption("log-gatherer-furl", ig.my_furl) 910 911 d = ig.d 912 913 # give the call to remote_logport a chance to retire 914 d.addCallback(self.stall, 0.5) 915 916 return d 917 918 919 class Gatherer(unittest.TestCase, LogfileReaderMixin, StallMixin, PollMixin): 869 920 def setUp(self): 870 921 self.parent = service.MultiService() … … 878 929 return d 879 930 880 881 def stall(self, res, delay=1.0):882 d = defer.Deferred()883 reactor.callLater(delay, d.callback, res)884 return d885 931 886 932 def _emit_messages_and_flush(self, res, t):
