1#!/usr/bin/env python
2#############################################################################
3# Copyright (c) 2015-2018 Balabit
4#
5# This program is free software; you can redistribute it and/or modify it
6# under the terms of the GNU General Public License version 2 as published
7# by the Free Software Foundation, or (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program; if not, write to the Free Software
16# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17#
18# As an additional exemption you are allowed to compile & link against the
19# OpenSSL libraries as published by the OpenSSL project. See the file
20# COPYING for details.
21#
22#############################################################################
23from src.syslog_ng.console_log_reader import ConsoleLogReader
24from src.syslog_ng.syslog_ng_cli import SyslogNgCli
25
26
27class SyslogNg(object):
28    def __init__(self, instance_paths, testcase_parameters):
29        self.instance_paths = instance_paths
30        self.__syslog_ng_cli = SyslogNgCli(instance_paths, testcase_parameters)
31
32    def start(self, config, 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):
33        return self.__syslog_ng_cli.start(config, stderr, debug, trace, verbose, startup_debug, no_caps, config_path, persist_path, pid_path, control_socket_path)
34
35    def stop(self, unexpected_messages=None):
36        self.__syslog_ng_cli.stop(unexpected_messages)
37
38    def reload(self, config):
39        self.__syslog_ng_cli.reload(config)
40
41    def restart(self, config):
42        self.__syslog_ng_cli.stop()
43        self.__syslog_ng_cli.start(config)
44
45    def get_version(self):
46        return self.__syslog_ng_cli.get_version()
47
48    def is_process_running(self):
49        return self.__syslog_ng_cli.is_process_running()
50
51    def wait_for_messages_in_console_log(self, expected_messages):
52        assert issubclass(type(expected_messages), list)
53        console_log_reader = ConsoleLogReader(self.instance_paths)
54        return console_log_reader.wait_for_messages_in_console_log(expected_messages)
55
56    def wait_for_message_in_console_log(self, expected_message):
57        return self.wait_for_messages_in_console_log([expected_message])
58