Ejemplo n.º 1
0
    def start(self):
        if self.snmptrapd_proc is not None:
            return

        self.snmptrapd_proc = ProcessExecutor().start(
            [
                "snmptrapd",
                "-f",
                "--disableAuthorization=yes",
                "-C",
                "-m ALL",
                "-A",
                "-Ddump",
                "-On",
                "--doNotLogTraps=no",
                "--authCommunity=log public",
                self.port,
                "-d",
                "-Lf",
                os.path.relpath(str(self.snmptrapd_log)),
                "-F",
                "{}%v\n".format(self.TRAP_LOG_PREFIX),
            ],
            self.snmptrapd_stdout_path,
            self.snmptrapd_stderr_path,
        )
        wait_until_true(self.wait_for_snmptrapd_log_creation)
        wait_until_true(self.wait_for_snmptrapd_startup)
        return self.snmptrapd_proc.is_running()
Ejemplo n.º 2
0
    def wait_file_content(self, content):
        wait_until_true(self.path.exists)

        with self.path.open() as f:
            message_reader = MessageReader(f.readline, SingleLineParser())

            while True:
                msg = message_reader.pop_messages(1)[0]
                if content in msg:
                    return True

            return False
def test_pp_tls_passthrough(config, syslog_ng, port_allocator, loggen,
                            testcase_parameters):
    server_key_path = copy_shared_file(testcase_parameters, "server.key")
    server_cert_path = copy_shared_file(testcase_parameters, "server.crt")

    network_source = config.create_network_source(
        ip="localhost",
        port=port_allocator(),
        transport='"proxied-tls-passthrough"',
        flags="no-parse",
        tls={
            "key-file": server_key_path,
            "cert-file": server_cert_path,
            "peer-verify": '"optional-untrusted"',
        },
    )

    file_destination = config.create_file_destination(file_name="output.log",
                                                      template=TEMPLATE)
    config.create_logpath(statements=[network_source, file_destination])

    syslog_ng.start(config)

    loggen_input_file_path = Path(
        tc_parameters.WORKING_DIR,
        "loggen_input_{}.txt".format(get_unique_id()))
    loggen_input_file = File(loggen_input_file_path)
    loggen_input_file.open(mode="w")
    loggen_input_file.write(INPUT_MESSAGES)
    loggen_input_file.close()

    loggen.start(
        network_source.options["ip"],
        network_source.options["port"],
        number=NUMBER_OF_MESSAGES,
        use_ssl=True,
        proxied_tls_passthrough=True,
        read_file=str(loggen_input_file_path),
        dont_parse=True,
        proxy_src_ip="1.1.1.1",
        proxy_dst_ip="2.2.2.2",
        proxy_src_port="3333",
        proxy_dst_port="4444",
    )

    wait_until_true(
        lambda: loggen.get_sent_message_count() == NUMBER_OF_MESSAGES)
    assert file_destination.read_log() == EXPECTED_MESSAGES
Ejemplo n.º 4
0
    def __wait_for_control_socket_alive(self):
        def is_alive(s):
            if not s.__is_process_running():
                raise Exception("syslog-ng could not start")
            return s.__syslog_ng_ctl.is_control_socket_alive()

        return wait_until_true(is_alive, self)
Ejemplo n.º 5
0
 def wait_for_creation(self):
     file_created = wait_until_true(self.path.exists)
     if file_created:
         logger.debug("File has been created: {}".format(self.path))
     else:
         raise Exception("File was not created in time: {}".format(self.path))
     return file_created
Ejemplo n.º 6
0
 def __wait_for_control_socket_alive(self):
     def is_alive(s):
         if not s.is_process_running():
             self.__process = None
             raise Exception("syslog-ng is not running")
         return s.__syslog_ng_ctl.is_control_socket_alive()
     return wait_until_true(is_alive, self)
Ejemplo n.º 7
0
 def wait_for_creation(self):
     file_created = wait_until_true(self.__is_file_exist)
     if file_created:
         logger.debug("File has been created:\n{}".format(self.__file_path))
     else:
         logger.debug("File not created:\n{}".format(self.__file_path))
     return file_created
Ejemplo n.º 8
0
 def __wait_for_control_socket_alive(self):
     def is_alive(s):
         if not s.is_process_running():
             self.__process = None
             raise Exception("syslog-ng is not running")
         return s.__syslog_ng_ctl.is_control_socket_alive()
     return wait_until_true(is_alive, self)
Ejemplo n.º 9
0
 def pop_messages(self, counter):
     assert wait_until_true(self.__buffer_and_parse, counter) is True
     counter = self.__map_counter(counter)
     required_number_of_messages = self.__parser.msg_list[0:counter]
     self.__parser.msg_list = self.__parser.msg_list[
         counter:]  # remove messages from the beginning of the msg_list, this is why we call it pop
     return required_number_of_messages
def test_pp_with_simple_tcp_connection(config, port_allocator, syslog_ng,
                                       loggen):
    network_source = config.create_network_source(ip="localhost",
                                                  port=port_allocator(),
                                                  transport="proxied-tcp")
    file_destination = config.create_file_destination(file_name="output.log")
    config.create_logpath(statements=[network_source, file_destination])

    syslog_ng.start(config)

    loggen.start(network_source.options["ip"],
                 network_source.options["port"],
                 inet=True,
                 stream=True,
                 number=NUMBER_OF_MESSAGES)
    wait_until_true(
        lambda: loggen.get_sent_message_count() == NUMBER_OF_MESSAGES)

    # We could check the source side stats, too, but it is not yet implemented
    assert not file_destination.get_path().exists()
Ejemplo n.º 11
0
    def start(self):
        if self.snmptrapd_proc is not None:
            return

        self.snmptrapd_proc = ProcessExecutor().start(
            [
                "snmptrapd",
                "-f",
                "--disableAuthorization=yes",
                "-C",
                "-On",
                "--doNotLogTraps=no",
                self.port,
                "-LF",
                "6-6",
                os.path.relpath(str(self.snmptrapd_log)),
            ],
            self.snmptrapd_stdout_path,
            self.snmptrapd_stderr_path,
        )
        wait_until_true(self.wait_for_snmptrapd_log_creation)
        wait_until_true(self.wait_for_snmptrapd_startup)
        return self.snmptrapd_proc.is_running()
Ejemplo n.º 12
0
 def wait_for_control_socket_alive(self):
     return wait_until_true(self.__is_control_socket_alive)
Ejemplo n.º 13
0
def test_wait_until_true_returns_with_result():
    assert wait_until_true(inner_function_add_numbers) == 5
Ejemplo n.º 14
0
def test_wait_until_true_inner_function_returns_false():
    assert wait_until_true(inner_function_return_false) is False
Ejemplo n.º 15
0
def test_wait_until_true_inner_function_returns_true():
    assert wait_until_true(inner_function_return_true)
Ejemplo n.º 16
0
 def peek_messages(self, counter):
     assert wait_until_true(self.__buffer_and_parse, counter) is True
     counter = self.__map_counter(counter)
     required_number_of_messages = self.__parser.msg_list[0:counter]
     return required_number_of_messages