Remove syslog-ng tests. Refs #14163

This commit is contained in:
Pedro Algarvio 2014-07-13 00:09:45 +01:00
parent 4232835ee8
commit 7862600683
2 changed files with 0 additions and 451 deletions

View File

@ -1,141 +0,0 @@
# -*- coding: utf-8 -*-
'''
Test module for syslog_ng
'''
# Import Salt Testing libs
import salt
from salttesting import skipIf, TestCase
from salttesting.helpers import ensure_in_syspath
from salttesting.mock import NO_MOCK, NO_MOCK_REASON, MagicMock, patch
ensure_in_syspath('../../')
from salt.modules import syslog_ng
syslog_ng.__salt__ = {}
syslog_ng.__opts__ = {}
_VERSION = "3.6.0alpha0"
_MODULES = ("syslogformat,json-plugin,basicfuncs,afstomp,afsocket,cryptofuncs,"
"afmongodb,dbparser,system-source,affile,pseudofile,afamqp,"
"afsocket-notls,csvparser,linux-kmsg-format,afuser,confgen,afprog")
VERSION_OUTPUT = """syslog-ng {0}
Installer-Version: {0}
Revision:
Compile-Date: Apr 4 2014 20:26:18
Error opening plugin module; module='afsocket-tls', error='/home/tibi/install/syslog-ng/lib/syslog-ng/libafsocket-tls.so: undefined symbol: tls_context_setup_session'
Available-Modules: {1}
Enable-Debug: on
Enable-GProf: off
Enable-Memtrace: off
Enable-IPv6: on
Enable-Spoof-Source: off
Enable-TCP-Wrapper: off
Enable-Linux-Caps: off""".format(_VERSION, _MODULES)
STATS_OUTPUT = """SourceName;SourceId;SourceInstance;State;Type;Number
center;;received;a;processed;0
destination;#anon-destination0;;a;processed;0
destination;#anon-destination1;;a;processed;0
source;s_gsoc2014;;a;processed;0
center;;queued;a;processed;0
global;payload_reallocs;;a;processed;0
global;sdata_updates;;a;processed;0
global;msg_clones;;a;processed;0"""
_SYSLOG_NG_NOT_INSTALLED_RETURN_VALUE = {"retcode": -1, "stderr":
"Unable to execute the command 'syslog-ng'. It is not in the PATH."}
_SYSLOG_NG_CTL_NOT_INSTALLED_RETURN_VALUE = {"retcode": -1, "stderr":
"Unable to execute the command 'syslog-ng-ctl'. It is not in the PATH."}
@skipIf(NO_MOCK, NO_MOCK_REASON)
class SyslogNGTestCase(TestCase):
def test_version(self):
mock_return_value = {"retcode": 0, 'stdout': VERSION_OUTPUT}
expected_output = {"retcode": 0, "stdout": "3.6.0alpha0"}
mock_args = "syslog-ng -V"
self._assert_template(mock_args,
mock_return_value,
function_to_call=syslog_ng.version,
expected_output=expected_output)
def test_stats(self):
mock_return_value = {"retcode": 0, 'stdout': STATS_OUTPUT}
expected_output = {"retcode": 0, "stdout": STATS_OUTPUT}
mock_args = "syslog-ng-ctl stats"
self._assert_template(mock_args,
mock_return_value,
function_to_call=syslog_ng.stats,
expected_output=expected_output)
def test_modules(self):
mock_return_value = {"retcode": 0, 'stdout': VERSION_OUTPUT}
expected_output = {"retcode": 0, "stdout": _MODULES}
mock_args = "syslog-ng -V"
self._assert_template(mock_args,
mock_return_value,
function_to_call=syslog_ng.modules,
expected_output=expected_output)
def test_config_test_ok(self):
mock_return_value = {"retcode": 0, "stderr": "", "stdout": "Syslog-ng startup text..."}
mock_args = "syslog-ng --syntax-only"
self._assert_template(mock_args,
mock_return_value,
function_to_call=syslog_ng.config_test,
expected_output=mock_return_value)
def test_config_test_fails(self):
mock_return_value = {"retcode": 1, 'stderr': "Syntax error...", "stdout": ""}
mock_args = "syslog-ng --syntax-only"
self._assert_template(mock_args,
mock_return_value,
function_to_call=syslog_ng.config_test,
expected_output=mock_return_value)
def test_config_test_cfgfile(self):
cfgfile = "/path/to/syslog-ng.conf"
mock_return_value = {"retcode": 1, 'stderr': "Syntax error...", "stdout": ""}
mock_args = "syslog-ng --syntax-only --cfgfile={0}".format(cfgfile)
self._assert_template(mock_args,
mock_return_value,
function_to_call=syslog_ng.config_test,
function_args={"cfgfile": cfgfile},
expected_output=mock_return_value)
def _assert_template(self,
mock_funtion_args,
mock_return_value,
function_to_call,
expected_output,
function_args=None):
if function_args is None:
function_args = {}
installed = True
if not salt.utils.which("syslog-ng"):
installed = False
if "syslog-ng-ctl" in mock_funtion_args:
expected_output = _SYSLOG_NG_CTL_NOT_INSTALLED_RETURN_VALUE
else:
expected_output = _SYSLOG_NG_NOT_INSTALLED_RETURN_VALUE
mock_function = MagicMock(return_value=mock_return_value)
with patch.dict(syslog_ng.__salt__, {'cmd.run_all': mock_function}):
got = function_to_call(**function_args)
self.assertEqual(expected_output, got)
if installed:
self.assertTrue(mock_function.called)
self.assertEqual(len(mock_function.call_args), 2)
mock_param = mock_function.call_args
self.assertTrue(mock_param[0][0].endswith(mock_funtion_args))
if __name__ == '__main__':
from integration import run_tests
run_tests(SyslogNGTestCase, needs_daemon=False)

View File

@ -1,310 +0,0 @@
# -*- coding: utf-8 -*-
'''
Test module for syslog_ng state
'''
import yaml
import re
import tempfile
import os
from salttesting import skipIf, TestCase
from salttesting.helpers import ensure_in_syspath
from salttesting.mock import NO_MOCK, NO_MOCK_REASON, MagicMock, patch
ensure_in_syspath('../../')
from salt.states import syslog_ng
syslog_ng.__salt__ = {}
SOURCE_1_CONFIG = {
"id": "s_tail",
"config":
"""
source:
- file:
- "/var/log/apache/access.log"
- follow_freq : 1
- flags:
- no-parse
- validate-utf8
"""}
SOURCE_1_EXPECTED = (
"""
source s_tail {
file(
"/var/log/apache/access.log",
follow_freq(1),
flags(no-parse, validate-utf8)
);
};
"""
)
SOURCE_2_CONFIG = {
"id": "s_gsoc2014",
"config": (
"""
source:
- tcp:
- ip: 0.0.0.0
- port: 1234
- flags: no-parse
"""
)
}
SOURCE_2_EXPECTED = (
"""
source s_gsoc2014 {
tcp(
ip("0.0.0.0"),
port(1234),
flags(no-parse)
);
};
"""
)
FILTER_1_CONFIG = {
"id": "f_json",
"config": (
"""
filter:
- match:
- "@json:"
"""
)
}
FILTER_1_EXPECTED = (
"""
filter f_json {
match(
"@json:"
);
};
"""
)
TEMPLATE_1_CONFIG = {
"id": "t_demo_filetemplate",
"config": (
"""
template:
- template:
- "$ISODATE $HOST $MSG\n"
- template_escape:
- "no"
"""
)
}
TEMPLATE_1_EXPECTED = (
"""
template t_demo_filetemplate {
template(
"$ISODATE $HOST $MSG "
);
template_escape(
no
);
};
"""
)
REWRITE_1_CONFIG = {
"id": "r_set_message_to_MESSAGE",
"config": (
"""
rewrite:
- set:
- "${.json.message}"
- value : "$MESSAGE"
"""
)
}
REWRITE_1_EXPECTED = (
"""
rewrite r_set_message_to_MESSAGE {
set(
"${.json.message}",
value("$MESSAGE")
);
};
"""
)
LOG_1_CONFIG = {
"id": "l_gsoc2014",
"config":
"""
log:
- source: s_gsoc2014
- junction:
- channel:
- filter: f_json
- parser: p_json
- rewrite: r_set_json_tag
- rewrite: r_set_message_to_MESSAGE
- destination:
- file:
- "/tmp/json-input.log"
- template: t_gsoc2014
- flags: final
- channel:
- filter: f_not_json
- parser:
- syslog-parser: []
- rewrite: r_set_syslog_tag
- flags: final
- destination:
- file:
- "/tmp/all.log"
- template: t_gsoc2014
"""
}
LOG_1_EXPECTED = (
"""
log {
source(s_gsoc2014);
junction {
channel {
filter(f_json);
parser(p_json);
rewrite(r_set_json_tag);
rewrite(r_set_message_to_MESSAGE);
destination {
file(
"/tmp/json-input.log",
template(t_gsoc2014)
);
};
flags(final);
};
channel {
filter(f_not_json);
parser {
syslog-parser(
);
};
rewrite(r_set_syslog_tag);
flags(final);
};
};
destination {
file(
"/tmp/all.log",
template(t_gsoc2014)
);
};
};
"""
)
OPTIONS_1_CONFIG = {
"id": "global_options",
"config": (
"""
options:
- time_reap: 30
- mark_freq: 10
- keep_hostname: "yes"
"""
)
}
OPTIONS_1_EXPECTED = (
"""
options {
time_reap(30);
mark_freq(10);
keep_hostname(yes);
};
"""
)
def remove_whitespaces(source):
return re.sub(r"\s+", "", source.strip())
@skipIf(NO_MOCK, NO_MOCK_REASON)
#@skipIf(syslog_ng.__virtual__() is False, 'Syslog-ng must be installed')
class SyslogNGTestCase(TestCase):
def test_generate_source_config(self):
self._config_generator_template(SOURCE_1_CONFIG, SOURCE_1_EXPECTED)
def test_generate_log_config(self):
self._config_generator_template(LOG_1_CONFIG, LOG_1_EXPECTED)
def test_generate_tcp_source_config(self):
self._config_generator_template(SOURCE_2_CONFIG, SOURCE_2_EXPECTED)
def test_generate_filter_config(self):
self._config_generator_template(FILTER_1_CONFIG, FILTER_1_EXPECTED)
def test_generate_template_config(self):
self._config_generator_template(TEMPLATE_1_CONFIG, TEMPLATE_1_EXPECTED)
def test_generate_rewrite_config(self):
self._config_generator_template(REWRITE_1_CONFIG, REWRITE_1_EXPECTED)
def test_generate_global_options_config(self):
self._config_generator_template(OPTIONS_1_CONFIG, OPTIONS_1_EXPECTED)
def _config_generator_template(self, yaml_input, expected):
parsed_yaml_config = yaml.load(yaml_input["config"])
id = yaml_input["id"]
got = syslog_ng.config(id, config=parsed_yaml_config, write=False)
config = got["changes"]["new"]
self.assertEqual(remove_whitespaces(expected), remove_whitespaces(config))
self.assertEqual(False, got["result"])
# print("#######################")
# print(yaml_input["config"])
# print("-------")
# print(got)
def test_write_config(self):
yaml_inputs = (SOURCE_2_CONFIG, SOURCE_1_CONFIG, FILTER_1_CONFIG, TEMPLATE_1_CONFIG, REWRITE_1_CONFIG, LOG_1_CONFIG)
expected_outputs = (SOURCE_2_EXPECTED, SOURCE_1_EXPECTED, FILTER_1_EXPECTED, TEMPLATE_1_EXPECTED, REWRITE_1_EXPECTED, LOG_1_EXPECTED)
config_file_fd, config_file_name = tempfile.mkstemp()
os.close(config_file_fd)
syslog_ng.set_config_file(config_file_name)
syslog_ng.write_version("3.6")
syslog_ng.write_config("", config='@include "scl.conf"')
for i in yaml_inputs:
parsed_yaml_config = yaml.load(i["config"])
id = i["id"]
got = syslog_ng.config(id, config=parsed_yaml_config, write=True)
written_config = ""
with open(config_file_name, "r") as f:
written_config = f.read()
for i in expected_outputs:
self.assertIn(i, written_config)
self.assertIn(SOURCE_1_EXPECTED, written_config)
syslog_ng.set_config_file("")
os.remove(config_file_name)
def test_started_state_generate_valid_cli_command(self):
mock_func = MagicMock(return_value={"retcode": 0, "stdout": "", "pid": 1000})
with patch.dict(syslog_ng.__salt__, {'cmd.run_all': mock_func}):
got = syslog_ng.started(user="joe", group="users", enable_core=True)
command = got["changes"]["new"]
self.assertTrue(command.endswith("syslog-ng --user=joe --group=users --enable-core --cfgfile=/etc/syslog-ng.conf"))
if __name__ == '__main__':
from integration import run_tests
run_tests(SyslogNGTestCase, needs_daemon=False)