Module: check_mk
Branch: master
Commit: 47f2d9f973b76735bfe544fca278a099a0ce87e9
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=47f2d9f973b767…
Author: Konstantin Büttner <kb(a)mathias-kettner.de>
Date: Fri Jan 19 12:08:25 2018 +0100
statgrab_cpu: Add basic perfdata test
Change-Id: I81d00620a8b20fff9984027e623a139ddf1ee003
---
tests/checks/checktestlib.py | 25 ++++++++++++++++---------
tests/checks/test_statgrab_cpu_check.py | 22 +++++++++++++---------
2 files changed, 29 insertions(+), 18 deletions(-)
diff --git a/tests/checks/checktestlib.py b/tests/checks/checktestlib.py
index 3a30989..e0288f9 100644
--- a/tests/checks/checktestlib.py
+++ b/tests/checks/checktestlib.py
@@ -28,18 +28,25 @@ class PerfValue(object):
self.maximum = maximum
def __eq__(self, other_value):
- return all([
- self.key == other_value.key,
- self.value == other_value.value,
- self.warn == other_value.warn,
- self.crit == other_value.crit,
- self.minimum == other_value.minimum,
- self.maximum == other_value.maximum,
- ])
+ if isinstance(other_value, self.__class__):
+ return all([
+ self.key == other_value.key,
+ self.value == other_value.value,
+ self.warn == other_value.warn,
+ self.crit == other_value.crit,
+ self.minimum == other_value.minimum,
+ self.maximum == other_value.maximum,
+ ])
+ elif type(other_value) == tuple:
+ return all(x==y for x, y in zip(other_value, self.tuple))
def __ne__(self, other_value):
return not self.__eq__(other_value)
+ @property
+ def tuple(self):
+ return (self.key, self.value, self.warn, self.crit, self.minimum, self.maximum)
+
class BasicCheckResult(object):
"""
@@ -98,7 +105,7 @@ class CheckResult(object):
else:
self.subresults = [ BasicCheckResult(*result) ]
- # TODO: @property this
+ @property
def perfdata(self):
perfdata = []
for subresult in self.subresults:
diff --git a/tests/checks/test_statgrab_cpu_check.py
b/tests/checks/test_statgrab_cpu_check.py
index cfec920..e43b017 100644
--- a/tests/checks/test_statgrab_cpu_check.py
+++ b/tests/checks/test_statgrab_cpu_check.py
@@ -7,18 +7,21 @@ pytestmark = pytest.mark.checks
info_statgrab_cpu_hpux = lambda t: [[u'idle', u'%d' % int(t*5)],
- [u'iowait', u'%d' % int(t*10)],
- [u'kernel', u'%d' % int(t*10)],
- [u'nice', u'%d' % int(t*20)],
+ [u'iowait', u'%d' % int(t*5)],
+ [u'kernel', u'%d' % int(t*5)],
+ [u'nice', u'%d' % int(t*5)],
[u'swap', u'0'],
- [u'systime', u'%d' % int(t*25)],
- [u'total', u'%d' % int(t*100)],
- [u'user', u'%d' % int(t*30)]]
+ [u'systime', u'%d' % int(t*5)],
+ [u'total', u'%d' % int(t*30)],
+ [u'user', u'%d' % int(t*5)]]
-(a)pytest.mark.parametrize("time_to_info,params,expected_result"sult", [
-(info_statgrab_cpu_hpux, {}, {}),
+(a)pytest.mark.parametrize("time_to_info,params,predicate"cate", [
+(info_statgrab_cpu_hpux, {}, lambda cr: ("user", 40.0) in cr.perfdata and
# TODO: This only represents the status quo - check whether this even makes sense.
+ ("system", 20.0) in cr.perfdata and
# Note that systime and total are being ignored entirely by the check.
+ ("wait", 20.0) in cr.perfdata
+ ),
])
-def test_statgrab_cpu_check(check_manager, monkeypatch, time_to_info, params,
expected_result):
+def test_statgrab_cpu_check(check_manager, monkeypatch, time_to_info, params,
predicate):
import time
check = check_manager.get_check("statgrab_cpu")
try:
@@ -27,3 +30,4 @@ def test_statgrab_cpu_check(check_manager, monkeypatch, time_to_info,
params, ex
pass
monkeypatch.setattr("time.time", lambda: 60)
result = checktestlib.CheckResult(check.run_check(None, params, time_to_info(60)))
+ assert predicate(result)