Module: check_mk
Branch: master
Commit: 929cec24c712d42d00c56002f89227af0b99430e
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=929cec24c712d4…
Author: Jukka Aro <ja(a)mathias-kettner.de>
Date: Tue Feb 13 15:29:04 2018 +0100
Windows: new tests for section plugin group
* Test the config option execute = <list of file extensions>.
* Use a dummy exe plugin for testing default plugin extensions.
* Test the execution of PowerShell plugin with interpreter.
---
agents/windows/Makefile.am | 4 +-
agents/windows/build_version | 2 +-
agents/windows/it/MontyPython.cc | 8 +++
agents/windows/it/test_agent_start_parameters.py | 2 +-
agents/windows/it/test_section_plugin_group.py | 88 +++++++++++++++++++-----
5 files changed, 81 insertions(+), 23 deletions(-)
diff --git a/agents/windows/Makefile.am b/agents/windows/Makefile.am
index 363f61f..8d6605b 100644
--- a/agents/windows/Makefile.am
+++ b/agents/windows/Makefile.am
@@ -1,7 +1,7 @@
bin_PROGRAMS = check_mk_agent
check_PROGRAMS = WindowsAgentTest wmitest
noinst_LIBRARIES = libcheck_mk_agent.a
-noinst_PROGRAMS = DummyPlugin
+noinst_PROGRAMS = MontyPython
AUTOMAKE_OPTIONS = foreign
AM_CPPFLAGS = -O2 -Wformat=2 -Werror -Wall -fno-rtti -std=c++17 -gdwarf-2 \
@@ -98,7 +98,7 @@ libcheck_mk_agent_a_SOURCES = \
check_mk_agent_SOURCES = check_mk_agent.cc
-DummyPlugin_SOURCES = it/DummyPlugin.cc
+MontyPython_SOURCES = it/MontyPython.cc
WindowsAgentTest_SOURCES = \
test/EnvironmentTest.cc \
diff --git a/agents/windows/build_version b/agents/windows/build_version
index 2b7c0b1..ab63d70 100644
--- a/agents/windows/build_version
+++ b/agents/windows/build_version
@@ -1 +1 @@
-3102
+3104
diff --git a/agents/windows/it/MontyPython.cc b/agents/windows/it/MontyPython.cc
new file mode 100644
index 0000000..4800b9a
--- /dev/null
+++ b/agents/windows/it/MontyPython.cc
@@ -0,0 +1,8 @@
+// A dummy plugin for testing the execution of binary plugins.
+#include <iostream>
+
+int main(int, char **) {
+ std::cout << "<<<monty_python>>>" <<
std::endl;
+ std::cout << "Monty Python's Flying Circus" << std::endl;
+ return 0;
+}
diff --git a/agents/windows/it/test_agent_start_parameters.py
b/agents/windows/it/test_agent_start_parameters.py
index b1d26bb..89a6d5c 100644
--- a/agents/windows/it/test_agent_start_parameters.py
+++ b/agents/windows/it/test_agent_start_parameters.py
@@ -23,7 +23,7 @@ class Globals(object):
remote_capfile = os.path.join(remotedir, capfile)
plugintype = 'plugins'
pluginnames = ['netstat_an.bat', 'wmic_if.bat']
- binaryplugin = 'DummyPlugin.exe'
+ binaryplugin = 'MontyPython.exe'
sections = ['check_mk', 'fileinfo', 'logfiles',
'logwatch', plugintype]
testfiles = ('basedir', 'monty', [('python',
'flying'), ('circus',
"It's")])
diff --git a/agents/windows/it/test_section_plugin_group.py
b/agents/windows/it/test_section_plugin_group.py
index 783021b..c2745f1 100644
--- a/agents/windows/it/test_section_plugin_group.py
+++ b/agents/windows/it/test_section_plugin_group.py
@@ -4,6 +4,7 @@ import platform
import pytest
import re
import sys
+import time
from remote import (actual_output, assert_subprocess, config, remote_ip,
remotedir, remotetest, remoteuser, sshopts, wait_agent,
write_config)
@@ -13,6 +14,9 @@ class Globals(object):
executionmode = None
pluginname = None
plugintype = None
+ suffixes = None
+ builddir = 'build64'
+ binaryplugin = 'MontyPython.exe'
@pytest.fixture
@@ -20,22 +24,32 @@ def testfile():
return os.path.basename(__file__)
+(a)pytest.fixture(
+ params=["default", "bat ps1"], ids=["default_suffixes",
"bat_ps1"])
+def testconfig_suffixes(request, config):
+ Globals.suffixes = request.param
+ if request.param != "default":
+ config.set("global", "execute", request.param)
+ return config
+
+
@pytest.fixture(params=['sync', 'async', 'async+cached'])
-def testconfig(request, config):
+def testconfig(request, testconfig_suffixes):
Globals.executionmode = request.param
- config.set("global", "sections", Globals.plugintype)
- config.set("global", "crash_debug", "yes")
+ testconfig_suffixes.set("global", "sections",
Globals.plugintype)
+ testconfig_suffixes.set("global", "crash_debug",
"yes")
if request.param != 'sync':
- config.add_section(Globals.plugintype)
- config.set(Globals.plugintype, 'execution %s' % Globals.pluginname,
- 'async')
- config.set(Globals.plugintype, 'timeout %s' % Globals.pluginname,
'10')
+ testconfig_suffixes.add_section(Globals.plugintype)
+ testconfig_suffixes.set(Globals.plugintype,
+ 'execution %s' % Globals.pluginname,
'async')
+ testconfig_suffixes.set(Globals.plugintype,
+ 'timeout %s' % Globals.pluginname, '10')
if request.param == 'async+cached':
- config.set(Globals.plugintype, 'cache_age %s' % Globals.pluginname,
- '300')
- config.set(Globals.plugintype, 'retry_count %s' % Globals.pluginname,
- '3')
- return config
+ testconfig_suffixes.set(Globals.plugintype,
+ 'cache_age %s' % Globals.pluginname,
'300')
+ testconfig_suffixes.set(Globals.plugintype,
+ 'retry_count %s' % Globals.pluginname,
'3')
+ return testconfig_suffixes
@pytest.fixture()
@@ -44,8 +58,15 @@ def expected_output():
re.escape(r'<<<%s>>>' % (Globals.plugintype
if Globals.plugintype == 'local' else
''))
]
- if Globals.pluginname == 'netstat_an.bat':
+ if Globals.suffixes == 'default':
plugin_fixed = [
+ re.escape(r'<<<') + r'monty_python' +
re.escape(r'>>>'),
+ r"Monty Python's Flying Circus"
+ ]
+ else:
+ plugin_fixed = []
+ if Globals.pluginname == 'netstat_an.bat':
+ plugin_fixed += [
re.escape(r'<<<') + r'win_netstat%s' %
(r':cached\(\d+,\d+\)'
if Globals.executionmode == 'async+cached' else r'') +
@@ -67,8 +88,8 @@ def expected_output():
if Globals.plugintype == 'plugins':
netstat_pattern += r'|%s' %
re.escape(r'<<<>>>')
plugin_variadic = repeat(netstat_pattern)
- else:
- plugin_fixed = [
+ elif Globals.pluginname == 'wmic_if.bat':
+ plugin_fixed += [
re.escape(r'<<<') + r'winperf_if:sep\(44\)%s' %
(r':cached\(\d+,\d+\)'
if Globals.executionmode == 'async+cached' else r'') +
@@ -80,6 +101,19 @@ def expected_output():
r'|^$'
r'%s' % (r'|%s' %
re.escape(r'<<<>>>')
if Globals.plugintype == 'plugins' else ''))
+ elif Globals.pluginname == 'windows_if.ps1':
+ plugin_fixed += [
+ re.escape(r'<<<') + r'winperf_if:sep\(9\)%s' %
+ (r':cached\(\d+,\d+\)'
+ if Globals.executionmode == 'async+cached' else r'') +
+ re.escape(r'>>>'),
+ (r'Node\s+MACAddress\s+Name\s+NetConnectionID\s+NetConnectionStatus'
+ r'\s+Speed\s+GUID'),
+ (r'[^\t]+\s+([0-9A-Fa-f]{2}(:[0-9A-Fa-f]{2}){5})?\s+[^\t]+\s+[^\t]*'
+ r'\s+\d*\s+\d*\s+\{[0-9A-F]+(\-[0-9A-F]+)+\}')
+ ]
+ plugin_variadic = []
+
return chain(main_label, plugin_fixed, plugin_variadic)
@@ -92,11 +126,15 @@ def plugindir(request):
return sourcedir, targetdir
-(a)pytest.fixture(params=['netstat_an.bat'bat', 'wmic_if.bat'], autouse=True)
+(a)pytest.fixture(
+ params=['netstat_an.bat', 'wmic_if.bat', 'windows_if.ps1'],
autouse=True)
def manage_plugins(request, plugindir):
Globals.pluginname = request.param
targetdir = plugindir[1].replace('/', '\\')
if platform.system() != 'Windows':
+ fullbuilddir = os.path.join(
+ os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
+ Globals.builddir)
cmds = [[
'ssh', sshopts,
'%s@%s' % (remoteuser, remote_ip),
@@ -105,16 +143,28 @@ def manage_plugins(request, plugindir):
'scp', sshopts,
os.path.join(plugindir[0], request.param),
'%s@%s:%s' % (remoteuser, remote_ip, plugindir[1])
+ ], [
+ 'scp', sshopts,
+ os.path.join(fullbuilddir, Globals.binaryplugin),
+ '%s@%s:%s' % (remoteuser, remote_ip, plugindir[1])
]]
for cmd in cmds:
assert_subprocess(cmd)
yield
if platform.system() == 'Windows':
- os.unlink(os.path.join(targetdir, request.param))
+ for plugin in [request.param, Globals.binaryplugin]:
+ for i in range(0, 5):
+ try:
+ os.unlink(os.path.join(targetdir, plugin))
+ break
+ except WindowsError as e:
+ # For some reason, the exe plugin remains locked for a short
+ # while every now and then. Just sleep 1 s and retry.
+ sys.stderr.write("%s\n" % str(e))
+ time.sleep(1)
def test_section_plugin_group(request, testconfig, expected_output,
actual_output, testfile):
# request.node.name gives test name
- remotetest(expected_output, actual_output, testfile,
- request.node.name)
+ remotetest(expected_output, actual_output, testfile, request.node.name)