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 start(
        self, target, port, inet=None, unix=None, stream=None, dgram=None, use_ssl=None, dont_parse=None, read_file=None, skip_tokens=None, loop_reading=None,
        rate=None, interval=None, permanent=None, syslog_proto=None, proxied=None, sdata=None, no_framing=None, active_connections=None,
        idle_connections=None, ipv6=None, debug=None, number=None, csv=None, quiet=None,
    ):

        if self.loggen_proc is not None and self.loggen_proc.is_running():
            raise Exception("Loggen is already running, you shouldn't call start")

        instanceIndex = Loggen.__get_new_instance_index()
        self.loggen_stdout_path = Path(tc_parameters.WORKING_DIR, "loggen_stdout_{}".format(instanceIndex))
        self.loggen_stderr_path = Path(tc_parameters.WORKING_DIR, "loggen_stderr_{}".format(instanceIndex))

        self.parameters = self.__decode_start_parameters(
            inet, unix, stream, dgram, use_ssl, dont_parse, read_file, skip_tokens, loop_reading,
            rate, interval, permanent, syslog_proto, proxied, sdata, no_framing, active_connections,
            idle_connections, ipv6, debug, number, csv, quiet,
        )

        self.loggen_proc = ProcessExecutor().start(
            [self.loggen_bin_path] + self.parameters + [target, port],
            self.loggen_stdout_path,
            self.loggen_stderr_path,
        )

        return self.loggen_proc
Ejemplo n.º 3
0
def test_start_stop_process(tmpdir):
    stdout_file = tmpdir.join("stdout.log")
    stderr_file = tmpdir.join("stderr.log")
    process_executor = ProcessExecutor()
    process_command = ["ls"]
    process_executor.start(process_command, stdout_file, stderr_file)
    assert process_executor.process is not None
    assert process_executor.process.pid is not None
def test_start_stop_process(tc_unittest):
    process_executor = ProcessExecutor(tc_unittest.get_fake_logger_factory())
    process_command = ["python", "-c", "import time; time.sleep(3)"]
    stdout_file = tc_unittest.get_temp_file()
    stderr_file = tc_unittest.get_temp_file()

    process_executor.start(process_command, stdout_file, stderr_file)
    assert process_executor.process is not None
    assert process_executor.process.pid is not None
Ejemplo n.º 5
0
class SNMPtrapd(object):
    def __init__(self, port):
        self.snmptrapd_proc = None
        self.port = port

        self.snmptrapd_log = Path(tc_parameters.WORKING_DIR, "snmptrapd_log")
        self.snmptrapd_stdout_path = Path(tc_parameters.WORKING_DIR,
                                          "snmptrapd_stdout")
        self.snmptrapd_stderr_path = Path(tc_parameters.WORKING_DIR,
                                          "snmptrapd_stderr")

    def wait_for_snmptrapd_log_creation(self):
        return self.snmptrapd_log.exists()

    def wait_for_snmptrapd_startup(self):
        return "NET-SNMP version" in self.snmptrapd_log.read_text()

    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()

    def stop(self):
        if self.snmptrapd_proc is None:
            return

        self.snmptrapd_proc.terminate()
        try:
            self.snmptrapd_proc.wait(4)
        except TimeoutExpired:
            self.snmptrapd_proc.kill()

        self.snmptrapd_proc = None

    def get_port(self):
        return self.port

    def get_logs(self):
        file_reader = DestinationReader(FileIO)
        return file_reader.read_all_logs(self.snmptrapd_log)
Ejemplo n.º 6
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,
        )
        return self.snmptrapd_proc.is_running()
Ejemplo n.º 7
0
 def __init__(self, logger_factory, instance_paths):
     self.__instance_paths = instance_paths
     self.__process_executor = ProcessExecutor(logger_factory)
     self.__command_executor = CommandExecutor(logger_factory)
Ejemplo n.º 8
0
class SyslogNgExecutor(object):
    def __init__(self, logger_factory, instance_paths):
        self.__instance_paths = instance_paths
        self.__process_executor = ProcessExecutor(logger_factory)
        self.__command_executor = CommandExecutor(logger_factory)

    def run_process(self):
        return self.__process_executor.start(
            command=self.__construct_syslog_ng_process(),
            stdout_path=self.__instance_paths.get_stdout_path(),
            stderr_path=self.__instance_paths.get_stderr_path(),
        )

    def run_process_with_valgrind(self):
        valgrind_command_args = [
            "valgrind",
            "--show-leak-kinds=all",
            "--track-origins=yes",
            "--tool=memcheck",
            "--leak-check=full",
            "--keep-stacktraces=alloc-and-free",
            "--read-var-info=yes",
            "--error-limit=no",
            "--num-callers=40",
            "--verbose",
            "--log-file={}".format(
                self.__instance_paths.get_valgrind_log_path()),
        ]
        full_command_args = valgrind_command_args + self.__construct_syslog_ng_process(
        )
        return self.__process_executor.start(
            command=full_command_args,
            stdout_path=self.__instance_paths.get_stdout_path(),
            stderr_path=self.__instance_paths.get_stderr_path(),
        )

    def run_command(self, command_short_name, command):
        return self.__command_executor.run(
            command=self.__construct_syslog_ng_command(command),
            stdout_path=self.__instance_paths.get_stdout_path_with_postfix(
                postfix=command_short_name),
            stderr_path=self.__instance_paths.get_stderr_path_with_postfix(
                postfix=command_short_name),
        )

    def get_backtrace_from_core(self, core_file):
        gdb_command_args = [
            "gdb",
            "-ex",
            "bt full",
            "--batch",
            self.__instance_paths.get_syslog_ng_bin(),
            "--core",
            core_file,
        ]
        core_postfix = "gdb_core_{}".format(get_unique_id())
        return self.__command_executor.run(
            command=gdb_command_args,
            stdout_path=self.__instance_paths.get_stdout_path_with_postfix(
                postfix=core_postfix),
            stderr_path=self.__instance_paths.get_stderr_path_with_postfix(
                postfix=core_postfix),
        )

    def __construct_syslog_ng_process(
        self,
        stderr=True,
        debug=True,
        trace=True,
        verbose=True,
        startup_debug=True,
        no_caps=True,
        config_path=None,
        persist_path=None,
        pid_path=None,
        control_socket_path=None,
    ):
        syslog_ng_process_args = [self.__instance_paths.get_syslog_ng_bin()]
        syslog_ng_process_args += ["--foreground", "--enable-core"]
        if stderr:
            syslog_ng_process_args += ["--stderr"]
        if debug:
            syslog_ng_process_args += ["--debug"]
        if trace:
            syslog_ng_process_args += ["--trace"]
        if verbose:
            syslog_ng_process_args += ["--verbose"]
        if startup_debug:
            syslog_ng_process_args += ["--startup-debug"]
        if no_caps:
            syslog_ng_process_args += ["--no-caps"]
        if config_path is None:
            config_path = self.__instance_paths.get_config_path()
        syslog_ng_process_args += ["--cfgfile={}".format(config_path)]
        if persist_path is None:
            persist_path = self.__instance_paths.get_persist_path()
        syslog_ng_process_args += ["--persist-file={}".format(persist_path)]
        if pid_path is None:
            pid_path = self.__instance_paths.get_pid_path()
        syslog_ng_process_args += ["--pidfile={}".format(pid_path)]
        if control_socket_path is None:
            control_socket_path = self.__instance_paths.get_control_socket_path(
            )
        syslog_ng_process_args += ["--control={}".format(control_socket_path)]
        return syslog_ng_process_args

    def __construct_syslog_ng_command(self, command):
        syslog_ng_command_args = [self.__instance_paths.get_syslog_ng_bin()]
        syslog_ng_command_args += command
        return syslog_ng_command_args
Ejemplo n.º 9
0
 def __init__(self, instance_paths):
     self.__instance_paths = instance_paths
     self.__process_executor = ProcessExecutor()
     self.__command_executor = CommandExecutor()
Ejemplo n.º 10
0
class Loggen(object):

    instanceIndex = -1

    @staticmethod
    def __get_new_instance_index():
        Loggen.instanceIndex += 1
        return Loggen.instanceIndex

    def __init__(self):
        self.loggen_proc = None
        self.loggen_bin_path = tc_parameters.INSTANCE_PATH.get_loggen_bin()

    def __decode_start_parameters(
        self,
        inet,
        unix,
        stream,
        dgram,
        use_ssl,
        dont_parse,
        read_file,
        skip_tokens,
        loop_reading,
        rate,
        interval,
        permanent,
        syslog_proto,
        proxied,
        sdata,
        no_framing,
        active_connections,
        idle_connections,
        ipv6,
        debug,
        number,
        csv,
        quiet,
        size,
        reconnect,
        proxied_tls_passthrough,
        proxy_src_ip,
        proxy_dst_ip,
        proxy_src_port,
        proxy_dst_port,
    ):

        start_parameters = []

        if inet is True:
            start_parameters.append("--inet")

        if unix is True:
            start_parameters.append("--unix")

        if stream is True:
            start_parameters.append("--stream")

        if dgram is True:
            start_parameters.append("--dgram")

        if use_ssl is True:
            start_parameters.append("--use-ssl")

        if dont_parse is True:
            start_parameters.append("--dont-parse")

        if read_file is not None:
            start_parameters.append("--read-file={}".format(read_file))

        if skip_tokens is not None:
            start_parameters.append("--skip-tokens={}".format(skip_tokens))

        if loop_reading is True:
            start_parameters.append("--loop-reading")

        if rate is not None:
            start_parameters.append("--rate={}".format(rate))

        if interval is not None:
            start_parameters.append("--interval={}".format(interval))

        if permanent is True:
            start_parameters.append("--permanent")

        if syslog_proto is True:
            start_parameters.append("--syslog-proto")

        if proxied is True:
            start_parameters.append("--proxied")

        if proxy_src_ip is not None:
            start_parameters.append("--proxy-src-ip={}".format(proxy_src_ip))

        if proxy_dst_ip is not None:
            start_parameters.append("--proxy-dst-ip={}".format(proxy_dst_ip))

        if proxy_src_port is not None:
            start_parameters.append(
                "--proxy-src-port={}".format(proxy_src_port))

        if proxy_dst_port is not None:
            start_parameters.append(
                "--proxy-dst-port={}".format(proxy_dst_port))

        if proxied_tls_passthrough is True:
            start_parameters.append("--proxied-tls-passthrough")

        if sdata is True:
            start_parameters.append("--sdata")

        if no_framing is True:
            start_parameters.append("--no-framing")

        if active_connections is not None:
            start_parameters.append(
                "--active-connections={}".format(active_connections))

        if idle_connections is not None:
            start_parameters.append(
                "--idle-connections={}".format(idle_connections))

        if ipv6 is True:
            start_parameters.append("--ipv6")

        if debug is True:
            start_parameters.append("--debug")

        if number is not None:
            start_parameters.append("--number={}".format(number))

        if csv is True:
            start_parameters.append("--csv")

        if quiet is True:
            start_parameters.append("--quiet")

        if size is not None:
            start_parameters.append("--size={}".format(size))

        if reconnect is True:
            start_parameters.append("--reconnect")

        return start_parameters

    def start(
        self,
        target,
        port,
        inet=None,
        unix=None,
        stream=None,
        dgram=None,
        use_ssl=None,
        dont_parse=None,
        read_file=None,
        skip_tokens=None,
        loop_reading=None,
        rate=None,
        interval=None,
        permanent=None,
        syslog_proto=None,
        proxied=None,
        sdata=None,
        no_framing=None,
        active_connections=None,
        idle_connections=None,
        ipv6=None,
        debug=None,
        number=None,
        csv=None,
        quiet=None,
        size=None,
        reconnect=None,
        proxied_tls_passthrough=None,
        proxy_src_ip=None,
        proxy_dst_ip=None,
        proxy_src_port=None,
        proxy_dst_port=None,
    ):

        if self.loggen_proc is not None and self.loggen_proc.is_running():
            raise Exception(
                "Loggen is already running, you shouldn't call start")

        instanceIndex = Loggen.__get_new_instance_index()
        self.loggen_stdout_path = Path(
            tc_parameters.WORKING_DIR,
            "loggen_stdout_{}".format(instanceIndex))
        self.loggen_stderr_path = Path(
            tc_parameters.WORKING_DIR,
            "loggen_stderr_{}".format(instanceIndex))

        self.parameters = self.__decode_start_parameters(
            inet,
            unix,
            stream,
            dgram,
            use_ssl,
            dont_parse,
            read_file,
            skip_tokens,
            loop_reading,
            rate,
            interval,
            permanent,
            syslog_proto,
            proxied,
            sdata,
            no_framing,
            active_connections,
            idle_connections,
            ipv6,
            debug,
            number,
            csv,
            quiet,
            size,
            reconnect,
            proxied_tls_passthrough,
            proxy_src_ip,
            proxy_dst_ip,
            proxy_src_port,
            proxy_dst_port,
        )

        self.loggen_proc = ProcessExecutor().start(
            [self.loggen_bin_path] + self.parameters + [target, port],
            self.loggen_stdout_path,
            self.loggen_stderr_path,
        )

        return self.loggen_proc

    def stop(self):
        if self.loggen_proc is None:
            return

        self.loggen_proc.terminate()
        try:
            self.loggen_proc.wait(4)
        except TimeoutExpired:
            self.loggen_proc.kill()

        self.loggen_proc = None

    def get_sent_message_count(self):
        if not self.loggen_stderr_path.exists():
            return 0

        # loggen puts the count= messages to the stderr
        f = open(str(self.loggen_stderr_path), "r")
        content = f.read()
        f.close()

        start_pattern = "count="
        if start_pattern not in content:
            return 0
        index_start = content.rindex(start_pattern) + len(start_pattern)

        end_pattern = ", "
        if end_pattern not in content:
            return 0
        index_end = content.find(end_pattern, index_start)

        return int(content[index_start:index_end])
Ejemplo n.º 11
0
class SyslogNgExecutor(object):
    def __init__(self, instance_paths):
        self.__instance_paths = instance_paths
        self.__process_executor = ProcessExecutor()
        self.__command_executor = CommandExecutor()

    def run_process(self, stderr, debug, trace, verbose, startup_debug, no_caps, config_path, persist_path, pid_path, control_socket_path):
        return self.__process_executor.start(
            command=self.__construct_syslog_ng_process(stderr, debug, trace, verbose, startup_debug, no_caps, config_path, persist_path, pid_path, control_socket_path),
            stdout_path=self.__instance_paths.get_stdout_path(),
            stderr_path=self.__instance_paths.get_stderr_path(),
        )

    def run_process_with_external_tool(self, external_tool):
        self.__instance_paths.register_external_tool_output_path(external_tool)
        if external_tool == "valgrind":
            return self.run_process_with_valgrind()
        elif external_tool == "strace":
            return self.run_process_with_strace()
        else:
            raise Exception("Unknown external tool was selected: {}".format(external_tool))

    def run_process_with_valgrind(self):
        valgrind_command_args = [
            "valgrind",
            "--show-leak-kinds=all",
            "--track-origins=yes",
            "--tool=memcheck",
            "--leak-check=full",
            "--keep-stacktraces=alloc-and-free",
            "--read-var-info=yes",
            "--error-limit=no",
            "--num-callers=40",
            "--verbose",
            "--log-file={}".format(self.__instance_paths.get_external_tool_output_path("valgrind")),
        ]
        full_command_args = valgrind_command_args + self.__construct_syslog_ng_process()
        return self.__process_executor.start(
            command=full_command_args,
            stdout_path=self.__instance_paths.get_stdout_path(),
            stderr_path=self.__instance_paths.get_stderr_path(),
        )

    def run_process_with_strace(self):
        strace_command_args = [
            "strace",
            "-s",
            "4096",
            "-tt",
            "-T",
            "-ff",
            "-o",
            self.__instance_paths.get_external_tool_output_path("strace"),
        ]
        full_command_args = strace_command_args + self.__construct_syslog_ng_process()
        return self.__process_executor.start(
            command=full_command_args,
            stdout_path=self.__instance_paths.get_stdout_path(),
            stderr_path=self.__instance_paths.get_stderr_path(),
        )

    def run_command(self, command_short_name, command):
        return self.__command_executor.run(
            command=self.__construct_syslog_ng_command(command),
            stdout_path=self.__instance_paths.get_stdout_path_with_postfix(postfix=command_short_name),
            stderr_path=self.__instance_paths.get_stderr_path_with_postfix(postfix=command_short_name),
        )

    def get_backtrace_from_core(self, core_file):
        gdb_command_args = [
            "gdb",
            "-ex",
            "bt full",
            "--batch",
            self.__instance_paths.get_syslog_ng_bin(),
            "--core",
            core_file,
        ]
        core_postfix = "gdb_core_{}".format(get_unique_id())
        return self.__command_executor.run(
            command=gdb_command_args,
            stdout_path=self.__instance_paths.get_stdout_path_with_postfix(postfix=core_postfix),
            stderr_path=self.__instance_paths.get_stderr_path_with_postfix(postfix=core_postfix),
        )

    def __construct_syslog_ng_process(
        self,
        stderr,
        debug,
        trace,
        verbose,
        startup_debug,
        no_caps,
        config_path,
        persist_path,
        pid_path,
        control_socket_path,
    ):
        syslog_ng_process_args = [self.__instance_paths.get_syslog_ng_bin()]
        syslog_ng_process_args += ["--foreground", "--enable-core"]
        if stderr:
            syslog_ng_process_args += ["--stderr"]
        if debug:
            syslog_ng_process_args += ["--debug"]
        if trace:
            syslog_ng_process_args += ["--trace"]
        if verbose:
            syslog_ng_process_args += ["--verbose"]
        if startup_debug:
            syslog_ng_process_args += ["--startup-debug"]
        if no_caps:
            syslog_ng_process_args += ["--no-caps"]
        if config_path is None:
            config_path = self.__instance_paths.get_config_path()
        syslog_ng_process_args += ["--cfgfile={}".format(config_path)]
        if persist_path is None:
            persist_path = self.__instance_paths.get_persist_path()
        syslog_ng_process_args += ["--persist-file={}".format(persist_path)]
        if pid_path is None:
            pid_path = self.__instance_paths.get_pid_path()
        syslog_ng_process_args += ["--pidfile={}".format(pid_path)]
        if control_socket_path is None:
            control_socket_path = self.__instance_paths.get_control_socket_path()
        syslog_ng_process_args += ["--control={}".format(control_socket_path)]
        return syslog_ng_process_args

    def __construct_syslog_ng_command(self, command):
        syslog_ng_command_args = [self.__instance_paths.get_syslog_ng_bin()]
        syslog_ng_command_args += command
        return syslog_ng_command_args
Ejemplo n.º 12
0
class SNMPtrapd(object):
    TRAP_LOG_PREFIX = 'LIGHT_TEST_SNMP_TRAP_RECEIVED:'

    def __init__(self, port):
        self.snmptrapd_proc = None
        self.port = port

        self.snmptrapd_log = Path(tc_parameters.WORKING_DIR, "snmptrapd_log")
        self.snmptrapd_stdout_path = Path(tc_parameters.WORKING_DIR,
                                          "snmptrapd_stdout")
        self.snmptrapd_stderr_path = Path(tc_parameters.WORKING_DIR,
                                          "snmptrapd_stderr")

    def wait_for_snmptrapd_log_creation(self):
        return self.snmptrapd_log.exists()

    def wait_for_snmptrapd_startup(self):
        return "NET-SNMP version" in self.snmptrapd_log.read_text()

    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()

    def stop(self):
        if self.snmptrapd_proc is None:
            return

        self.snmptrapd_proc.terminate()
        try:
            self.snmptrapd_proc.wait(4)
        except TimeoutExpired:
            self.snmptrapd_proc.kill()

        self.snmptrapd_proc = None

    def get_port(self):
        return self.port

    def get_traps(self):
        file_reader = DestinationReader(FileIO)
        logs = file_reader.read_all_logs(self.snmptrapd_log)
        trap_list = []
        for log_line in logs:
            res = re.match('({})(.*)'.format(self.TRAP_LOG_PREFIX), log_line)
            if (res):
                trap_list += res.group(2).rstrip().split("\t")
        return sorted(trap_list)

    def get_raw_traps(self):
        file_reader = DestinationReader(FileIO)
        return file_reader.read_all_logs(self.snmptrapd_log)
Ejemplo n.º 13
0
class SyslogNgExecutor(object):
    def __init__(self, logger_factory, instance_paths):
        self.__instance_paths = instance_paths
        self.__process_executor = ProcessExecutor(logger_factory)
        self.__command_executor = CommandExecutor(logger_factory)

    def run_process(self):
        return self.__process_executor.start(
            command=self.__construct_syslog_ng_process(),
            stdout_path=self.__instance_paths.get_stdout_path(),
            stderr_path=self.__instance_paths.get_stderr_path(),
        )

    def run_command(self, command_short_name, command):
        return self.__command_executor.run(
            command=self.__construct_syslog_ng_command(command),
            stdout_path=self.__instance_paths.get_stdout_path_with_postfix(postfix=command_short_name),
            stderr_path=self.__instance_paths.get_stderr_path_with_postfix(postfix=command_short_name),
        )

    def __construct_syslog_ng_process(
        self,
        stderr=True,
        debug=True,
        trace=True,
        verbose=True,
        startup_debug=True,
        no_caps=True,
        config_path=None,
        persist_path=None,
        pid_path=None,
        control_socket_path=None,
    ):
        syslog_ng_process_args = [self.__instance_paths.get_syslog_ng_bin()]
        syslog_ng_process_args += ["--foreground", "--enable-core"]
        if stderr:
            syslog_ng_process_args += ["--stderr"]
        if debug:
            syslog_ng_process_args += ["--debug"]
        if trace:
            syslog_ng_process_args += ["--trace"]
        if verbose:
            syslog_ng_process_args += ["--verbose"]
        if startup_debug:
            syslog_ng_process_args += ["--startup-debug"]
        if no_caps:
            syslog_ng_process_args += ["--no-caps"]
        if config_path is None:
            config_path = self.__instance_paths.get_config_path()
        syslog_ng_process_args += ["--cfgfile={}".format(config_path)]
        if persist_path is None:
            persist_path = self.__instance_paths.get_persist_path()
        syslog_ng_process_args += ["--persist-file={}".format(persist_path)]
        if pid_path is None:
            pid_path = self.__instance_paths.get_pid_path()
        syslog_ng_process_args += ["--pidfile={}".format(pid_path)]
        if control_socket_path is None:
            control_socket_path = self.__instance_paths.get_control_socket_path()
        syslog_ng_process_args += ["--control={}".format(control_socket_path)]
        return syslog_ng_process_args

    def __construct_syslog_ng_command(self, command):
        syslog_ng_command_args = [self.__instance_paths.get_syslog_ng_bin()]
        syslog_ng_command_args += command
        return syslog_ng_command_args
Ejemplo n.º 14
0
 def __init__(self, instance_paths):
     self.__instance_paths = instance_paths
     self.__process_executor = ProcessExecutor()
     self.__command_executor = CommandExecutor()
Ejemplo n.º 15
0
class SyslogNgExecutor(object):
    def __init__(self, instance_paths):
        self.__instance_paths = instance_paths
        self.__process_executor = ProcessExecutor()
        self.__command_executor = CommandExecutor()

    def run_process(self):
        return self.__process_executor.start(
            command=self.__construct_syslog_ng_process(),
            stdout_path=self.__instance_paths.get_stdout_path(),
            stderr_path=self.__instance_paths.get_stderr_path(),
        )

    def run_process_with_valgrind(self):
        valgrind_command_args = [
            "valgrind",
            "--show-leak-kinds=all",
            "--track-origins=yes",
            "--tool=memcheck",
            "--leak-check=full",
            "--keep-stacktraces=alloc-and-free",
            "--read-var-info=yes",
            "--error-limit=no",
            "--num-callers=40",
            "--verbose",
            "--log-file={}".format(self.__instance_paths.get_valgrind_log_path()),
        ]
        full_command_args = valgrind_command_args + self.__construct_syslog_ng_process()
        return self.__process_executor.start(
            command=full_command_args,
            stdout_path=self.__instance_paths.get_stdout_path(),
            stderr_path=self.__instance_paths.get_stderr_path(),
        )

    def run_command(self, command_short_name, command):
        return self.__command_executor.run(
            command=self.__construct_syslog_ng_command(command),
            stdout_path=self.__instance_paths.get_stdout_path_with_postfix(postfix=command_short_name),
            stderr_path=self.__instance_paths.get_stderr_path_with_postfix(postfix=command_short_name),
        )

    def get_backtrace_from_core(self, core_file):
        gdb_command_args = [
            "gdb",
            "-ex",
            "bt full",
            "--batch",
            self.__instance_paths.get_syslog_ng_bin(),
            "--core",
            core_file,
        ]
        core_postfix = "gdb_core_{}".format(get_unique_id())
        return self.__command_executor.run(
            command=gdb_command_args,
            stdout_path=self.__instance_paths.get_stdout_path_with_postfix(postfix=core_postfix),
            stderr_path=self.__instance_paths.get_stderr_path_with_postfix(postfix=core_postfix),
        )

    def __construct_syslog_ng_process(
        self,
        stderr=True,
        debug=True,
        trace=True,
        verbose=True,
        startup_debug=True,
        no_caps=True,
        config_path=None,
        persist_path=None,
        pid_path=None,
        control_socket_path=None,
    ):
        syslog_ng_process_args = [self.__instance_paths.get_syslog_ng_bin()]
        syslog_ng_process_args += ["--foreground", "--enable-core"]
        if stderr:
            syslog_ng_process_args += ["--stderr"]
        if debug:
            syslog_ng_process_args += ["--debug"]
        if trace:
            syslog_ng_process_args += ["--trace"]
        if verbose:
            syslog_ng_process_args += ["--verbose"]
        if startup_debug:
            syslog_ng_process_args += ["--startup-debug"]
        if no_caps:
            syslog_ng_process_args += ["--no-caps"]
        if config_path is None:
            config_path = self.__instance_paths.get_config_path()
        syslog_ng_process_args += ["--cfgfile={}".format(config_path)]
        if persist_path is None:
            persist_path = self.__instance_paths.get_persist_path()
        syslog_ng_process_args += ["--persist-file={}".format(persist_path)]
        if pid_path is None:
            pid_path = self.__instance_paths.get_pid_path()
        syslog_ng_process_args += ["--pidfile={}".format(pid_path)]
        if control_socket_path is None:
            control_socket_path = self.__instance_paths.get_control_socket_path()
        syslog_ng_process_args += ["--control={}".format(control_socket_path)]
        return syslog_ng_process_args

    def __construct_syslog_ng_command(self, command):
        syslog_ng_command_args = [self.__instance_paths.get_syslog_ng_bin()]
        syslog_ng_command_args += command
        return syslog_ng_command_args