Exemple #1
0
    def test_getting_defined_restricted_set(self):
        """ Make sure that properly formed commands are parsed into a list of
        command tuples. """

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

        self.mox.StubOutWithMock(SafeConfigParser, "has_section")
        self.mox.StubOutWithMock(SafeConfigParser, "items")

        config = ConfigurationParser()
        config.parse(mock_file)

        config.has_section("commands").AndReturn(True)
        config.items("commands").AndReturn([
            ("foo", "ls::List files"),
            ("bar", "df:-h:Disk space usage (human readable)"),
            ("baz", "du:-sh .:"),
            ("foz", "pwd")
        ])

        self.mox.ReplayAll()

        self.assertEquals(restricted_set(), [
            ("ls", None, "List files"),
            ("df", ["-h"], "Disk space usage (human readable)"),
            ("du", ["-sh ."], ""),
            ("pwd", None, "")
        ])
Exemple #2
0
    def test_restricted_set_missing_section(self):
        """ If there is no commands section in the configuration file, an empty
        list should be returned. """

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

        self.mox.StubOutWithMock(SafeConfigParser, "has_section")
        self.mox.StubOutWithMock(SafeConfigParser, "items")

        config = ConfigurationParser()
        config.parse(mock_file)

        config.has_section("commands").AndReturn(False)

        self.mox.ReplayAll()

        self.assertEquals(restricted_set(), [])
Exemple #3
0
    def test_getting_malformed_restricted_set(self):
        """ If there is a malformed command defined in the commands section, a
        MalformedCommand should be raised. """

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

        self.mox.StubOutWithMock(SafeConfigParser, "has_section")
        self.mox.StubOutWithMock(SafeConfigParser, "items")

        config = ConfigurationParser()
        config.parse(mock_file)

        config.has_section("commands").AndReturn(True)
        config.items("commands").AndReturn([("foo", "")])

        self.mox.ReplayAll()

        self.assertRaises(MalformedCommand, restricted_set)
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