Changeset 455:014c632e2629
- Timestamp:
- 08/01/08 16:29:55 (5 months ago)
- Files:
-
- ChangeLog (modified) (1 diff)
- foolscap/test/test_logging.py (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
ChangeLog
r454 r455 1 1 2008-08-01 Brian Warner <warner@lothar.com> 2 3 * foolscap/test/test_logging.py (IncidentGatherer.test_emit): add 4 test coverage for re-classifying existing incidents 2 5 3 6 * foolscap/referenceable.py (RemoteReferenceOnly.getRemoteTubID): foolscap/test/test_logging.py
r451 r455 899 899 return d 900 900 901 def create_incident_gatherer(self, basedir ):901 def create_incident_gatherer(self, basedir, classifiers=[]): 902 902 # create an incident gatherer, which will make its own Tub 903 903 ig_basedir = os.path.join(basedir, "ig") 904 os.makedirs(ig_basedir)905 904 null = StringIO() 906 ig = MyIncidentGathererService(basedir=ig_basedir, stdout=null) 905 ig = MyIncidentGathererService(classifiers=classifiers, 906 basedir=ig_basedir, stdout=null) 907 907 ig.tub_class = GoodEnoughTub 908 908 ig.d = defer.Deferred() 909 ig.setServiceParent(self.parent)910 909 return ig 911 910 … … 924 923 925 924 ig = self.create_incident_gatherer(basedir) 925 ig.setServiceParent(self.parent) 926 926 self.create_connected_tub(ig) 927 927 … … 937 937 938 938 ig = self.create_incident_gatherer(basedir) 939 ig.setServiceParent(self.parent) 939 940 incident_d = defer.Deferred() 940 941 ig.cb_new_incident = incident_d.callback … … 942 943 943 944 d = ig.d 945 944 946 d.addCallback(lambda res: self.logger.msg("boom", level=log.WEIRD)) 945 947 d.addCallback(lambda res: incident_d) … … 959 961 d.addCallback(_new_incident) 960 962 963 # now shut down the gatherer, create a new one with the same basedir 964 # (with some classifier functions), remove the existing 965 # classifications, and start it up. It should reclassify everything 966 # at startup. 967 961 968 # give the call to remote_logport a chance to retire 962 969 d.addCallback(self.stall, 0.5) 963 return d 964 970 d.addCallback(lambda res: ig.disownServiceParent()) 971 972 def _update_classifiers(res): 973 self.remove_classified_incidents(ig) 974 def classify_boom(nodeid_s, (header,events)): 975 if "boom" in header["trigger"].get("message",""): 976 return "boom" 977 def classify_foom(nodeid_s, (header,events)): 978 if "foom" in header["trigger"].get("message",""): 979 return "foom" 980 ig2 = self.create_incident_gatherer(basedir, [classify_boom]) 981 ig2.add_classifier(classify_foom) 982 ig2.setServiceParent(self.parent) 983 984 # incidents should be classified in startService 985 unknowns_fn = os.path.join(ig2.basedir, "classified", "unknown") 986 self.failIf(os.path.exists(unknowns_fn)) 987 booms_fn = os.path.join(ig2.basedir, "classified", "boom") 988 booms = [fn.strip() for fn in open(booms_fn,"r").readlines()] 989 self.failUnlessEqual(len(booms), 1) 990 fooms_fn = os.path.join(ig2.basedir, "classified", "foom") 991 self.failIf(os.path.exists(fooms_fn)) 992 993 return ig2.d 994 d.addCallback(_update_classifiers) 995 996 # give the call to remote_logport a chance to retire 997 d.addCallback(self.stall, 0.5) 998 return d 999 1000 def remove_classified_incidents(self, ig): 1001 classified = os.path.join(ig.basedir, "classified") 1002 for category in os.listdir(classified): 1003 os.remove(os.path.join(classified, category)) 1004 os.rmdir(classified) 965 1005 966 1006 class Gatherer(unittest.TestCase, LogfileReaderMixin, StallMixin, PollMixin):
