Module: check_mk
Branch: master
Commit: 6a86babb79ddd16d5654a3b676f823ea49378eed
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=6a86babb79ddd1…
Author: Florian Kromer <fk(a)mathias-kettner.de>
Date: Tue Dec 4 18:15:43 2018 +0100
add regression tests for alcatel checks
CMK-1188
Change-Id: I765924021449a656851ad8b3546d739cd30e01b8
---
tests/unit/checks/test_alcatel_cpu.py | 36 +++++++++++++++++++++++
tests/unit/checks/test_alcatel_fans.py | 33 +++++++++++++++++++++
tests/unit/checks/test_alcatel_power.py | 52 +++++++++++++++++++++++++++++++++
tests/unit/checks/test_alcatel_temp.py | 39 +++++++++++++++++++++++++
4 files changed, 160 insertions(+)
diff --git a/tests/unit/checks/test_alcatel_cpu.py
b/tests/unit/checks/test_alcatel_cpu.py
new file mode 100644
index 0000000..422d295
--- /dev/null
+++ b/tests/unit/checks/test_alcatel_cpu.py
@@ -0,0 +1,36 @@
+import pytest
+
+pytestmark = pytest.mark.checks
+
+CHECK_NAME = "alcatel_cpu"
+
+
+(a)pytest.mark.parametrize("info;info, result_expected", [
+ ([[u'doesnt matter', u'doesent matter'], [u'doesnt matter']],
[(None,
+
"alcatel_cpu_default_levels")]),
+])
+def test_inventory_function(check_manager, info, result_expected):
+ check = check_manager.get_check(CHECK_NAME)
+ result = check.run_discovery(info)
+ result = [r for r in result]
+ assert result == result_expected
+
+
+(a)pytest.mark.parametrize("parameterseters, info, state_expected, infotext_expected,
perfdata_expected", [
+ ((30, 40), [[u'29']], 0, 'total: 29.0%', [('util', 29, 30,
40, 0, 100)]),
+ ((30, 40), [[u'31']], 1, 'total: 31.0% (warn/crit at 30.0%/40.0%)',
[('util', 31, 30, 40, 0,
+ 100)]),
+ ((30, 40), [[u'41']], 2, 'total: 41.0% (warn/crit at 30.0%/40.0%)',
[('util', 41, 30, 40, 0,
+ 100)]),
+])
+def test_check_function(check_manager, parameters, info, state_expected,
infotext_expected,
+ perfdata_expected):
+ """
+ Verifies if check function asserts warn and crit CPU levels.
+ """
+ check = check_manager.get_check(CHECK_NAME)
+ item = None
+ state, infotext, perfdata = check.run_check(item, parameters, info)
+ assert state == state_expected
+ assert infotext == infotext_expected
+ assert perfdata == perfdata_expected
diff --git a/tests/unit/checks/test_alcatel_fans.py
b/tests/unit/checks/test_alcatel_fans.py
new file mode 100644
index 0000000..7d29d6d
--- /dev/null
+++ b/tests/unit/checks/test_alcatel_fans.py
@@ -0,0 +1,33 @@
+import pytest
+
+pytestmark = pytest.mark.checks
+
+CHECK_NAME = "alcatel_fans"
+
+
+(a)pytest.mark.parametrize("info;info, result_expected", [
+ ([[u'doesnt matter']], [(1, None)]),
+ ([[u'doesnt matter', u'doesent matter'], [u'doesnt matter']],
[(1, None), (2, None)]),
+])
+def test_inventory_function(check_manager, info, result_expected):
+ check = check_manager.get_check(CHECK_NAME)
+ result = check.run_discovery(info)
+ result = [r for r in result]
+ assert result == result_expected
+
+
+(a)pytest.mark.parametrize(
+ "parameters, item, info, state_expected, infotext_expected,
perfdata_expected", [
+ ((0, 0), 1, [[u'0']], 2, 'Fan has no status', None),
+ ((0, 0), 1, [[u'1']], 2, 'Fan not running', None),
+ ((0, 0), 1, [[u'2']], 0, 'Fan running', None),
+ ])
+def test_check_function(check_manager, parameters, item, info, state_expected,
infotext_expected,
+ perfdata_expected):
+ """
+ Verifies if check function asserts warn and crit Board and CPU temperature levels.
+ """
+ check = check_manager.get_check(CHECK_NAME)
+ state, infotext = check.run_check(item, parameters, info)
+ assert state == state_expected
+ assert infotext_expected in infotext
diff --git a/tests/unit/checks/test_alcatel_power.py
b/tests/unit/checks/test_alcatel_power.py
new file mode 100644
index 0000000..d85f1d8
--- /dev/null
+++ b/tests/unit/checks/test_alcatel_power.py
@@ -0,0 +1,52 @@
+import pytest
+
+pytestmark = pytest.mark.checks
+
+CHECK_NAME = "alcatel_power"
+
+
+# info: oid end, status, device type, power type
+(a)pytest.mark.parametrize(
+ "info, result_expected",
+ [
+ ([[u'1', u'0', u'0x35000001', u'0']],
[('1', None)
+ ]), # item is oid in case of proper device
type
+ ([[u'1', u'0', u'0x45000002', u'0']],
[('1', None)
+ ]), # item is oid in case of proper device
type
+ ([[u'1', u'0', u'0x45000004', u'0']],
[('1', None)
+ ]), # item is oid in case of proper device
type
+ ([[u'1', u'0', u'0x45000008', u'0']],
[('1', None)
+ ]), # item is oid in case of proper device
type
+ ([[u'1', u'0', u'0x45000009', u'0']],
[('1', None)
+ ]), # item is oid in case of proper device
type
+ ([[u'1', u'0', u'0', u'0']],
+ []), # no item is oid in case of inproper device type and inproper power type
+ ([[u'1', u'0', u'0', u'1']], [('1',
None)]), # item is oid in case of proper power type
+ ])
+def test_inventory_function(check_manager, info, result_expected):
+ check = check_manager.get_check(CHECK_NAME)
+ result = check.run_discovery(info)
+ result = [r for r in result]
+ assert result == result_expected
+
+
+# info: oid end, status, device type, power type
+(a)pytest.mark.parametrize(
+ "parameters, item, info, state_expected, infotext_expected",
+ [
+ ((0, 0), u'1', [[u'1', u'1', u'0x35000001',
u'1']], 0,
+ 'Supply status OK'), # status == 1, proper ac power type
+ ((0, 0), u'1', [[u'1', u'1', u'0x35000001',
u'2']], 0,
+ 'Supply status OK'), # status == 1, proper dc power type
+ ((0, 0), u'1', [[u'1', u'1', u'0x35000001',
u'0']], 3,
+ 'No Power supply connected to this port'), # status == 1, power type no
power supply
+ ((0, 0), u'1', [[u'1', u'2', u'0x35000001',
u'1']], 2,
+ 'Supply in error condition'), # state != 1
+ ((0, 0), u'2', [[u'1', u'1', u'0x35000001',
u'1']], 3,
+ 'Supply not found'), # mismatch of item and oid end
+ ])
+def test_check_function(check_manager, parameters, item, info, state_expected,
infotext_expected):
+ check = check_manager.get_check(CHECK_NAME)
+ state, infotext = check.run_check(item, parameters, info)
+ assert state == state_expected
+ assert infotext_expected in infotext
diff --git a/tests/unit/checks/test_alcatel_temp.py
b/tests/unit/checks/test_alcatel_temp.py
new file mode 100644
index 0000000..9a66a99
--- /dev/null
+++ b/tests/unit/checks/test_alcatel_temp.py
@@ -0,0 +1,39 @@
+import pytest
+
+pytestmark = pytest.mark.checks
+
+
+(a)pytest.mark.parametrize("info;info, item_expected, data_expected", [
+ ([[u'29', u'0']], 'Board', {}),
+ ([[u'0', u'29']], 'CPU', {}),
+])
+def test_inventory_function(check_manager, info, item_expected, data_expected):
+ """
+ Verifies if the item is detected corresponding to info content.
+ """
+ check = check_manager.get_check("alcatel_temp")
+ result = check.run_discovery(info)
+ result = [r for r in result]
+ assert result[0][0] == item_expected
+ assert result[0][1] == data_expected
+
+
+(a)pytest.mark.parametrize(
+ "parameters, item, info, state_expected, infotext_expected,
perfdata_expected", [
+ ((30, 40), u'Slot 1 Board', [[u'29', u'0']], 0,
'29', [('temp', 29, 30, 40)]),
+ ((30, 40), u'Slot 1 Board', [[u'31', u'0']], 1,
'31', [('temp', 31, 30, 40)]),
+ ((30, 40), u'Slot 1 Board', [[u'41', u'0']], 2,
'41', [('temp', 41, 30, 40)]),
+ ((30, 40), u'Slot 1 CPU', [[u'0', u'29']], 0,
'29', [('temp', 29, 30, 40)]),
+ ((30, 40), u'Slot 1 CPU', [[u'0', u'31']], 1,
'31', [('temp', 31, 30, 40)]),
+ ((30, 40), u'Slot 1 CPU', [[u'0', u'41']], 2,
'41', [('temp', 41, 30, 40)]),
+ ])
+def test_check_function(check_manager, parameters, item, info, state_expected,
infotext_expected,
+ perfdata_expected):
+ """
+ Verifies if check function asserts warn and crit Board and CPU temperature levels.
+ """
+ check = check_manager.get_check("alcatel_temp")
+ state, infotext, perfdata = check.run_check(item, parameters, info)
+ assert state == state_expected
+ assert infotext_expected in infotext
+ assert perfdata == perfdata_expected