Example #1
0
class TestProtocolEntry(object):
        
    def setup_method(self, _):
        self._entry = ProtocolEntry("dummy", dict(), constants.ERROR,"dummy")
        
    def test_properties(self):
        assert self._entry.duration == 0
        assert self._entry.check == "dummy"
        assert self._entry.msg == "dummy"
        assert self._entry.config == dict()
        assert self._entry.result == constants.ERROR
        assert self._entry.success == False
        assert str(self._entry) != None
        
    def test_is_included(self):
        assert self._entry.is_included(None, None) == True
        assert self._entry.is_included(["dummy"], None) == True
        assert self._entry.is_included(None, ["dummy"]) == False
        assert self._entry.is_included(["dummy"], list()) == True
        assert self._entry.is_included(list(), ["dummy"]) == False
        assert self._entry.is_included(list(), list()) == False
        
    def test_duration(self):
        self._entry.start_time = 0.5
        self._entry.end_time = 1.5
        assert self._entry.duration == 1000
Example #2
0
    def run(self, config, interp=constants.ABORTONERROR, debug=False):
        """
        The singularize method calls the implemented check. It initializes all 
        nessessary values and returns the check result as a C{ProtocolEntry}.
        
        :param config: The check configuration that has to be used.
        :type config: C{Section}
        
        :param interp: Defines how the check result has to be interpreted.
        :type interp: - C{constants.WARNING}
                      - C{constants.DELAYONERROR}
                      - C{constants.ABORTONERROR}
                      
        :param debug: Returns an exception instead of translation in a log msg.
        :type debug: C{boolean}
                      
        :return: Returns the result of the check as a C{ProtocolEntry}.
        :rtype: C{ProtocolEntry}
        """

        name = self.__class__.__name__
        config = self.__config__.from_config(config)
        entry = ProtocolEntry(name, config)
        try:
            entry.start()
            entry.result, entry.msg = self._run(config)
            entry.end()
        except Exception, exc:
            if debug:
                raise exc

            entry.result = constants.EXCEPTION
            entry.msg = "Exception in check '%s': %s" % (name, str(exc))
            self.logger.exception(entry.msg)
Example #3
0
 def run(self, config, interp=constants.ABORTONERROR, debug=False):
     """
     The singularize method calls the implemented check. It initializes all 
     nessessary values and returns the check result as a C{ProtocolEntry}.
     
     :param config: The check configuration that has to be used.
     :type config: C{Section}
     
     :param interp: Defines how the check result has to be interpreted.
     :type interp: - C{constants.WARNING}
                   - C{constants.DELAYONERROR}
                   - C{constants.ABORTONERROR}
                   
     :param debug: Returns an exception instead of translation in a log msg.
     :type debug: C{boolean}
                   
     :return: Returns the result of the check as a C{ProtocolEntry}.
     :rtype: C{ProtocolEntry}
     """
     
     name = self.__class__.__name__
     config = self.__config__.from_config(config)
     entry = ProtocolEntry(name, config)
     try:
         entry.start()
         entry.result, entry.msg = self._run(config)
         entry.end()
     except Exception, exc:
         if debug:
             raise exc
         
         entry.result = constants.EXCEPTION
         entry.msg = "Exception in check '%s': %s" % (name, str(exc))
         self.logger.exception(entry.msg) 
Example #4
0
 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
Example #5
0
 def setup_method(self, _):
     self._entry = ProtocolEntry("dummy", dict(), constants.ERROR,"dummy")
Example #6
0
 def setup_method(self, _):
     self._protocol = Protocol("test")
     self._entry = ProtocolEntry("dummy", dict(), constants.SUCCESS, "dummy")
     self._protocol.append(self._entry)