Ejemplo n.º 1
0
class ConsoleLogReader(object):
    def __init__(self, instance_paths):
        self.__stderr_io = FileIO(instance_paths.get_stderr_path())
        self.__message_reader = MessageReader(self.__stderr_io.read, SingleLineParser())

    def wait_for_start_message(self):
        syslog_ng_start_message = ["syslog-ng starting up;"]
        return self.__wait_for_messages_in_console_log(syslog_ng_start_message)

    def wait_for_stop_message(self):
        syslog_ng_stop_message = ["syslog-ng shutting down"]
        return self.__wait_for_messages_in_console_log(syslog_ng_stop_message)

    def wait_for_reload_message(self):
        syslog_ng_reload_messages = [
            "New configuration initialized",
            "Configuration reload request received, reloading configuration",
            "Configuration reload finished",
        ]
        return self.__wait_for_messages_in_console_log(syslog_ng_reload_messages)

    def __wait_for_messages_in_console_log(self, expected_messages):
        if not self.__stderr_io.wait_for_creation():
            raise Exception

        console_log_messages = self.__message_reader.pop_messages(counter=READ_ALL_MESSAGES)
        console_log_content = "".join(console_log_messages)

        result = []
        for expected_message in expected_messages:
            result.append(expected_message in console_log_content)
        return all(result)

    def check_for_unexpected_messages(self, unexpected_messages):
        unexpected_patterns = ["Plugin module not found"]
        console_log_messages = self.__message_reader.peek_messages(counter=READ_ALL_MESSAGES)
        if unexpected_messages is not None:
            unexpected_patterns.append(unexpected_messages)
        for unexpected_pattern in unexpected_patterns:
            for console_log_message in console_log_messages:
                if unexpected_pattern in console_log_message:
                    logger.error("Found unexpected message in console log: {}".format(console_log_message))
                    assert False

    def dump_stderr(self, last_n_lines=10):
        console_log_messages = self.__message_reader.peek_messages(counter=READ_ALL_MESSAGES)
        logger.error("".join(console_log_messages[-last_n_lines:]))

    @staticmethod
    def handle_valgrind_log(valgrind_log_path):
        with open(valgrind_log_path, "r") as valgrind_log:
            valgrind_content = valgrind_log.read()
            assert "Invalid read" not in valgrind_content
            assert "Invalid write" not in valgrind_content
            assert "blocks are definitely lost in loss record" not in valgrind_content
            assert "Uninitialised value was created by a heap allocation" not in valgrind_content
Ejemplo n.º 2
0
class ConsoleLogReader(object):
    def __init__(self, logger_factory, instance_paths):
        self.__logger = logger_factory.create_logger("ConsoleLogReader")
        self.__stderr_io = FileIO(logger_factory, instance_paths.get_stderr_path())
        self.__message_reader = MessageReader(logger_factory, self.__stderr_io.read, SingleLineParser(logger_factory))

    def wait_for_start_message(self):
        syslog_ng_start_message = ["syslog-ng starting up;"]
        return self.__wait_for_messages_in_console_log(syslog_ng_start_message)

    def wait_for_stop_message(self):
        syslog_ng_stop_message = ["syslog-ng shutting down"]
        return self.__wait_for_messages_in_console_log(syslog_ng_stop_message)

    def wait_for_reload_message(self):
        syslog_ng_reload_messages = [
            "New configuration initialized",
            "Configuration reload request received, reloading configuration",
            "Configuration reload finished",
        ]
        return self.__wait_for_messages_in_console_log(syslog_ng_reload_messages)

    def __wait_for_messages_in_console_log(self, expected_messages):
        if not self.__stderr_io.wait_for_creation():
            raise Exception

        console_log_messages = self.__message_reader.pop_messages(counter=0)
        console_log_content = "".join(console_log_messages)

        result = []
        for expected_message in expected_messages:
            result.append(expected_message in console_log_content)
        return all(result)

    def check_for_unexpected_messages(self, unexpected_messages):
        unexpected_patterns = ["Plugin module not found"]
        console_log_messages = self.__message_reader.peek_messages(counter=0)
        if unexpected_messages is not None:
            unexpected_patterns.append(unexpected_messages)
        for unexpected_pattern in unexpected_patterns:
            for console_log_message in console_log_messages:
                if unexpected_pattern in console_log_message:
                    self.__logger.error("Found unexpected message in console log: {}".format(console_log_message))
                    assert False

    def dump_stderr(self, last_n_lines=10):
        console_log_messages = self.__message_reader.peek_messages(counter=0)
        self.__logger.info("".join(console_log_messages[-last_n_lines:]))

    @staticmethod
    def handle_valgrind_log(valgrind_log_path):
        with open(valgrind_log_path, "r") as valgrind_log:
            valgrind_content = valgrind_log.read()
            assert "Invalid read" not in valgrind_content
            assert "Invalid write" not in valgrind_content
Ejemplo n.º 3
0
class ConsoleLogReader(object):
    def __init__(self, instance_paths):
        self.__stderr_io = FileIO(instance_paths.get_stderr_path())
        self.__message_reader = MessageReader(self.__stderr_io.readline,
                                              SingleLineParser())
        self.__console_log_path = instance_paths.get_stderr_path()

    def wait_for_start_message(self):
        syslog_ng_start_message = ["syslog-ng starting up;"]
        return self.wait_for_messages_in_console_log(syslog_ng_start_message)

    def wait_for_stop_message(self):
        syslog_ng_stop_message = ["syslog-ng shutting down"]
        return self.wait_for_messages_in_console_log(syslog_ng_stop_message)

    def wait_for_reload_message(self):
        syslog_ng_reload_messages = [
            "New configuration initialized",
            "Configuration reload request received, reloading configuration",
            "Configuration reload finished",
        ]
        return self.wait_for_messages_in_console_log(syslog_ng_reload_messages)

    def wait_for_message_in_console_log(self, expected_message):
        return self.wait_for_messages_in_console_log(self, [expected_message])

    def wait_for_messages_in_console_log(self, expected_messages):
        if not self.__stderr_io.wait_for_creation():
            raise Exception

        console_log_messages = self.__message_reader.pop_messages(
            counter=READ_ALL_AVAILABLE_MESSAGES)
        console_log_content = "".join(console_log_messages)

        result = []
        for expected_message in expected_messages:
            result.append(expected_message in console_log_content)
        return all(result)

    def check_for_unexpected_messages(self, unexpected_messages):
        unexpected_patterns = ["Plugin module not found", "assertion"]
        with self.__console_log_path.open() as f:
            console_log_messages = f.readlines()
        if unexpected_messages is not None:
            unexpected_patterns.append(unexpected_messages)
        for unexpected_pattern in unexpected_patterns:
            for console_log_message in console_log_messages:
                if unexpected_pattern in console_log_message:
                    logger.error(
                        "Found unexpected message in console log: {}".format(
                            console_log_message))
                    raise Exception("Unexpected error log in console",
                                    console_log_message)

    def dump_stderr(self, last_n_lines=10):
        console_log_messages = self.__message_reader.peek_messages(
            counter=READ_ALL_AVAILABLE_MESSAGES)
        logger.error("".join(console_log_messages[-last_n_lines:]))

    @staticmethod
    def handle_valgrind_log(valgrind_log_path):
        with open(valgrind_log_path, "r") as valgrind_log:
            valgrind_content = valgrind_log.read()
            assert "Invalid read" not in valgrind_content
            assert "Invalid write" not in valgrind_content
            assert "blocks are definitely lost in loss record" not in valgrind_content
            assert "Uninitialised value was created by a heap allocation" not in valgrind_content