Skip to content
Permalink
Browse files

[CMK-2192] [CMK-2162] - integration tests: webservices, eventlog(disa…

…bled)

- fixed error in Windows Agent eventlog Section: now non-monitored eventlogs save their last position on every kick in the state file(more or less compatible with LWA and saves traffic)
- eventlog integration test is postponed

Change-Id: I7a14a155d537abcca7647d5d23690639a7cdf900
  • Loading branch information...
Sergey Kipnis
Sergey Kipnis committed Jun 11, 2019
1 parent 13014bf commit 5bb43ea1ff8553a8e089e87dcbb3ee868f2599c8
@@ -6,8 +6,8 @@
import os
import platform
import re
from local import (actual_output, assert_subprocess, make_ini_config, src_exec_dir, local_test,
wait_agent, write_config)
from local import (actual_output, assert_subprocess, make_yaml_config, user_dir, local_test,
wait_agent, write_config, host)
import sys

import pytest
@@ -25,8 +25,8 @@ class Globals:
state_pattern = re.compile(r'^(?P<logtype>[^\|]+)\|(?P<record>\d+)$')
section = 'logwatch'
alone = True
statedir = os.path.join(src_exec_dir, 'state')
statefile = 'eventstate___1.txt'
statedir = os.path.join(user_dir, 'state')
statefile = 'eventstate_127_0_0_1.txt' # local test uses ipv4
testlog = 'Application'
testsource = 'Test source'
testeventtype = 'Warning'
@@ -104,33 +104,27 @@ def testfile():


@pytest.fixture(params=['alone', 'with_systemtime'])
def testconfig_sections(request, make_ini_config):
def testconfig_sections(request, make_yaml_config):
Globals.alone = request.param == 'alone'
if Globals.alone:
make_ini_config.set('global', 'sections', Globals.section)
make_yaml_config['global']['sections'] = Globals.section
else:
make_ini_config.set('global', 'sections', '%s systemtime' % Globals.section)
return make_ini_config
make_yaml_config['global']['sections'] = [Globals.section, "systemtime"]
return make_yaml_config


@pytest.fixture(params=['yes', 'no'], ids=['vista_api=yes', 'vista_api=no'])
def testconfig(request, testconfig_sections):
testconfig_sections.set('global', 'crash_debug', 'yes')
testconfig_sections.add_section(Globals.section)
testconfig_sections.set(Globals.section, 'vista_api', request.param)
testconfig_sections.set(Globals.section, 'logfile %s' % Globals.testlog, 'warn')
# Ignore security and system logs as SSH agent and COM may emit something
# there while tests run
testconfig_sections.set(Globals.section, 'logfile Security', 'off')
testconfig_sections.set(Globals.section, 'logfile System', 'off')
log_files = [{Globals.testlog: 'warn'}, {'Security': 'off'}, {'System': 'off'}]
testconfig_sections[Globals.section] = {'vista_api': request.param, 'logfile': log_files}

return testconfig_sections


@pytest.fixture
def expected_output_no_events():
if platform.system() == 'Windows':
expected = [re.escape(r'<<<%s>>>' % Globals.section)] + [logtitle(l) for l in logs]
expected = [re.escape(r'<<<%s>>>' % Globals.section), re.escape(r'[[[Application]]]')]
if not Globals.alone:
expected += [re.escape(r'<<<systemtime>>>'), r'\d+']
return expected
@@ -154,7 +148,7 @@ def expected_output_application_events():

def last_records():
if platform.system() == 'Windows':
return {logtype: get_last_record(logtype) for logtype in logs}
return {logtype: get_last_record(logtype) for logtype in ['Application']}


@pytest.fixture
@@ -199,15 +193,19 @@ def verify_eventstate():
state_tolerance))


"""
# disabled tests
@pytest.mark.usefixtures('no_statefile')
def test_section_eventlog__no_statefile__no_events(request, testconfig, expected_output_no_events,
actual_output, testfile):
# request.node.name gives test name
return
local_test(expected_output_no_events, actual_output, testfile, request.node.name)

@pytest.mark.usefixtures('with_statefile', 'create_events')
def test_section_eventlog__application_warnings(
request, testconfig, expected_output_application_events, actual_output, testfile):
# request.node.name gives test name
return
local_test(expected_output_application_events, actual_output, testfile, request.node.name)
"""
@@ -4,7 +4,7 @@
import os
import pytest
import re
from local import actual_output, make_ini_config, local_test, wait_agent, write_config
from local import actual_output, make_yaml_config, local_test, wait_agent, write_config


class Globals(object):
@@ -17,20 +17,15 @@ def testfile():


@pytest.fixture(
params=[('webservices', True), ('wmi_webservices', True), ('webservices', False),
('wmi_webservices', False)],
ids=[
'sections=webservices', 'sections=wmi_webservices', 'sections=webservices_systemtime',
'sections=wmi_webservices_systemtime'
])
def testconfig(request, make_ini_config):
params=[('wmi_webservices', True), ('wmi_webservices', False)],
ids=['sections=wmi_webservices', 'sections=wmi_webservices_systemtime'])
def testconfig(request, make_yaml_config):
Globals.alone = request.param[1]
if Globals.alone:
make_ini_config.set('global', 'sections', request.param[0])
make_yaml_config['global']['sections'] = request.param[0]
else:
make_ini_config.set('global', 'sections', '%s systemtime' % request.param[0])
make_ini_config.set('global', 'crash_debug', 'yes')
return make_ini_config
make_yaml_config['global']['sections'] = [request.param[0], '%s systemtime']
return make_yaml_config


@pytest.fixture
@@ -278,8 +278,13 @@ void SaveEventlogOffsets(const std::string& FileName,
}

for (const auto& state : States) {
if (state.name_ != std::string("*"))
ofs << state.name_ << "|" << state.pos_ << std::endl;
if (state.name_ == std::string("*")) continue;

auto pos = state.pos_;

if (pos == cma::cfg::kInitialPos) pos = 0;

ofs << state.name_ << "|" << pos << std::endl;
}
}
}
@@ -453,9 +458,19 @@ std::vector<std::filesystem::path> LogWatchEvent::makeStateFilesTable() const {
std::string GenerateOutputFromStates(bool VistaApi, StateVector& States) {
std::string out;
for (auto& state : States) {
if (state.level_ == cma::cfg::EventLevels::kOff) continue;
if (state.level_ == cma::cfg::EventLevels::kOff) {
// if (state.pos_ == cma::cfg::kInitialPos) {
// update pos to last one
bool unused = false;

// updates position in state file for every(!) log presented
// even if the log is disabled
ReadDataFromLog(VistaApi, state, unused);
continue;
}
#if 0
// This Legacy Agent mode AB says this is NOT valid approach
// left te,porary as a reference
if (state.presented_) {
out += "[[[" + state.name_ + "]]]\n";
out += ReadDataFromLog(state);

0 comments on commit 5bb43ea

Please sign in to comment.
You can’t perform that action at this time.