Changeset 455:014c632e2629

Show
Ignore:
Timestamp:
08/01/08 16:29:55 (5 months ago)
Author:
"Brian Warner <warner@lothar.com>"
branch:
default
Message:

test_logging: add coverage for reclassifying existing incidents

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • ChangeLog

    r454 r455  
    112008-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 
    25 
    36        * foolscap/referenceable.py (RemoteReferenceOnly.getRemoteTubID): 
  • foolscap/test/test_logging.py

    r451 r455  
    899899        return d 
    900900 
    901     def create_incident_gatherer(self, basedir): 
     901    def create_incident_gatherer(self, basedir, classifiers=[]): 
    902902        # create an incident gatherer, which will make its own Tub 
    903903        ig_basedir = os.path.join(basedir, "ig") 
    904         os.makedirs(ig_basedir) 
    905904        null = StringIO() 
    906         ig = MyIncidentGathererService(basedir=ig_basedir, stdout=null) 
     905        ig = MyIncidentGathererService(classifiers=classifiers, 
     906                                       basedir=ig_basedir, stdout=null) 
    907907        ig.tub_class = GoodEnoughTub 
    908908        ig.d = defer.Deferred() 
    909         ig.setServiceParent(self.parent) 
    910909        return ig 
    911910 
     
    924923 
    925924        ig = self.create_incident_gatherer(basedir) 
     925        ig.setServiceParent(self.parent) 
    926926        self.create_connected_tub(ig) 
    927927 
     
    937937 
    938938        ig = self.create_incident_gatherer(basedir) 
     939        ig.setServiceParent(self.parent) 
    939940        incident_d = defer.Deferred() 
    940941        ig.cb_new_incident = incident_d.callback 
     
    942943 
    943944        d = ig.d 
     945 
    944946        d.addCallback(lambda res: self.logger.msg("boom", level=log.WEIRD)) 
    945947        d.addCallback(lambda res: incident_d) 
     
    959961        d.addCallback(_new_incident) 
    960962 
     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 
    961968        # give the call to remote_logport a chance to retire 
    962969        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) 
    9651005 
    9661006class Gatherer(unittest.TestCase, LogfileReaderMixin, StallMixin, PollMixin):