Beispiel #1
0
 def _run_profile(self, profile):
     process = profile.get_process(self.hook)
     if not process:
         self.logger.debug(
             "%s process skipped." % self.hook.capitalize()
         )
         return
     
     self.logger.debug("Running profile '%s'...", profile.name)
     protocol = Protocol(profile.name)
     # run the configured checks
     for name, config, interp in process.checks:
         self.logger.debug("Loading check %s...", name)
         check = self.checks.fetch(name, self.transaction)
         self.logger.debug("Starting check %s...", name)
         entry = check.run(config, interp)
         self.logger.debug(
             "Check %s finished with %s.", name, entry.result
         )
         protocol.append(entry)
         
         # run the configured handlers when a message was returned 
         if entry.msg:
             self.logger.debug(
                 "Running handler after check %s...", entry.check
             )
             self.handlers.singularize(self.transaction, process, entry)
             self.logger.debug(
                 "Handler after check %s finished.", entry.check
             )
         
         # cancel the _process chain when an abortonerror was detected.
         if interp == constants.ABORTONERROR and not protocol.success:
             msg = "Profile %s aborted after check %s."
             self.logger.debug(msg, profile.name, entry.check)
             break
     
     # cumulativ execution of all handlers.
     self.logger.debug("Running handler summarize...")
     self.handlers.summarize(self.transaction, process, protocol)
     self.logger.debug("Handler summarize finished.")
     
     if not protocol.success:
         self.result = constants.ERROR
     self.logger.debug("Profile %s finished.", profile.name)
Beispiel #2
0
    def _run_profile(self, profile):
        process = profile.get_process(self.hook)
        if not process:
            self.logger.debug("%s process skipped." % self.hook.capitalize())
            return

        self.logger.debug("Running profile '%s'...", profile.name)
        protocol = Protocol(profile.name)
        # run the configured checks
        for name, config, interp in process.checks:
            self.logger.debug("Loading check %s...", name)
            check = self.checks.fetch(name, self.transaction)
            self.logger.debug("Starting check %s...", name)
            entry = check.run(config, interp)
            self.logger.debug("Check %s finished with %s.", name, entry.result)
            protocol.append(entry)

            # run the configured handlers when a message was returned
            if entry.msg:
                self.logger.debug("Running handler after check %s...",
                                  entry.check)
                self.handlers.singularize(self.transaction, process, entry)
                self.logger.debug("Handler after check %s finished.",
                                  entry.check)

            # cancel the _process chain when an abortonerror was detected.
            if interp == constants.ABORTONERROR and not protocol.success:
                msg = "Profile %s aborted after check %s."
                self.logger.debug(msg, profile.name, entry.check)
                break

        # cumulativ execution of all handlers.
        self.logger.debug("Running handler summarize...")
        self.handlers.summarize(self.transaction, process, protocol)
        self.logger.debug("Handler summarize finished.")

        if not protocol.success:
            self.result = constants.ERROR
        self.logger.debug("Profile %s finished.", profile.name)
Beispiel #3
0
 def setup_method(self, _):
     self._protocol = Protocol("test")
     self._entry = ProtocolEntry("dummy", dict(), constants.SUCCESS, "dummy")
     self._protocol.append(self._entry)
Beispiel #4
0
class TestProtocol(object):
    
    def setup_method(self, _):
        self._protocol = Protocol("test")
        self._entry = ProtocolEntry("dummy", dict(), constants.SUCCESS, "dummy")
        self._protocol.append(self._entry)
    
    def test_properties(self):
        assert self._protocol.success == True
        assert self._protocol.result == constants.SUCCESS
        
        entry = ProtocolEntry("dummy", dict(), constants.ERROR,"dummy")
        self._protocol.append(entry)
        assert self._protocol.success == False
        
        entry = ProtocolEntry("dummy", dict(), constants.SUCCESS,"dummy")
        self._protocol.append(entry)
        assert self._protocol.success == False
        
        assert self._protocol.errors == 1
        assert self._protocol.successors == 2
        assert self._protocol.warnings == 0
        assert self._protocol.exceptions == 0
        assert self._protocol.result == constants.ERROR
        assert str(self._protocol) != None

    def test_filter(self):
        assert len(self._protocol.filter(None, None)) == 1
        assert len(self._protocol.filter(["dummy"], None)) == 1
        assert len(self._protocol.filter(None, ["dummy"])) == 0
        assert len(self._protocol.filter(["dummy"], list())) == 1
        assert len(self._protocol.filter(list(), ["dummy"])) == 0
        assert len(self._protocol.filter(list(), list())) == 0
        
    def test_clear(self):
        assert len(self._protocol) == 1
        
        self._protocol.clear()
        assert len(self._protocol) == 0