Exemple #1
0
    def test_getting_existing_commandhandlers(self):
        """ If any of the two known command handlers are configured, an instance
        of the named command handler should be returned by get_command_handler
        """

        mock_file = self.mox.CreateMockAnything()
        mock_file.closed = False
        mock_file.name = "foobar"

        self.mox.StubOutWithMock(SafeConfigParser, "get")

        config = ConfigurationParser()
        config.parse(mock_file)

        # case this one wierdly just to make sure that character casing is taken
        # into consideration when parsing the string..
        config.get("general", "handler").AndReturn("rEstrIctEd")

        config.get("general", "handler").AndReturn("pAssthrU")

        self.mox.ReplayAll()

        expected_type = commandhandlers.RestrictedCommandHandler()
        self.assertEquals(type(get_command_handler()),
                          type(expected_type))

        expected_type = commandhandlers.UnsafeCommandHandler()
        self.assertEquals(type(get_command_handler()),
                          type(expected_type))
Exemple #2
0
    def test_getting_nonexisting_commandhandler(self):
        """ If the command handler returned by the configuration is unknown to
        get_command_handler, an UnknownHandler exception should be raised. """

        mock_file = self.mox.CreateMockAnything()
        mock_file.closed = False
        mock_file.name = "foobar"

        self.mox.StubOutWithMock(SafeConfigParser, "get")

        config = ConfigurationParser()
        config.parse(mock_file)

        config.get("general", "handler").AndReturn("foobar")

        self.mox.ReplayAll()

        self.assertRaises(UnknownHandler, get_command_handler)
Exemple #3
0
    def test_getting_commandhandler_undefined_in_config(self):
        """ If either the section or the option that details the command handler
        is missing, an UnknownHandler exception should be raised. """

        mock_file = self.mox.CreateMockAnything()
        mock_file.closed = False
        mock_file.name = "foobar"

        self.mox.StubOutWithMock(SafeConfigParser, "get")

        config = ConfigurationParser()
        config.parse(mock_file)

        config.get("general", "handler").AndRaise(NoSectionError("general"))
        config.get("general", "handler").AndRaise(NoOptionError("general",
                                                                "handler"))

        self.mox.ReplayAll()

        self.assertRaises(UnknownHandler, get_command_handler)
        self.assertRaises(UnknownHandler, get_command_handler)
Exemple #4
0
    def __init__(self):
        self.__command = None
        self.__interval = None

        self.__previous_result = None

        parser = ConfigurationParser()

        logger = logging.getLogger()

        if parser.has_section("status"):
            try:
                logger.info("reading configured status command")

                self.__command = parser.get("status", "command")
                self.__interval = int(parser.get("status", "interval"))

                logger.info("executing '%s' every %d sec" % (self.__command,
                                                             self.__interval))
            except NoOptionError:
                pass
Exemple #5
0
    def __get_pidfile():
        """ Helper method that reads an (optionally) configured pidfile from the
        configuration file. """

        config = ConfigurationParser()

        try:
            pidfile = config.get("general", "pidfile")
        except (NoOptionError, NoSectionError):
            pidfile = None

        if not pidfile:
            pidfile = "/tmp/xmppmote.pid"

        return pidfile