Refactoring: Changed all check parameters starting with an 'o' to the new rulespec...
[check_mk.git] / tests / unit / checks / test_nfsmounts_and_cifsmounts_check.py
blob685ba4b13c27eae5d6694103650df9d8524ff7de
1 import pytest # type: ignore
2 from checktestlib import BasicCheckResult, PerfValue, DiscoveryResult, assertDiscoveryResultsEqual
4 # since both nfsmounts and cifsmounts use the parse, inventory
5 # and check functions from network_fs.include unchanged we test
6 # both checks here.
8 pytestmark = pytest.mark.checks
11 @pytest.mark.parametrize("info,discovery_expected,check_expected", [
12 ( # no info
13 [],
14 [],
15 (['', None, BasicCheckResult(3, ' not mounted', None)],)
17 ( # single mountpoint with data
18 [[u'/ABCshare', u'ok', u'491520', u'460182', u'460182', u'65536']],
19 [('/ABCshare', {})],
20 [('/ABCshare', {}, BasicCheckResult(0, "6.4% used (1.91 GB of 30.00 GB)", None)),
21 ('/ZZZshare', {}, BasicCheckResult(3, "/ZZZshare not mounted", None))]
23 ( # two mountpoints with empty data
24 [[u'/AB', u'ok', u'-', u'-', u'-', u'-'],
25 [u'/ABC', u'ok', u'-', u'-', u'-', u'-']],
26 [('/AB', {}),
27 ('/ABC', {})],
28 [('/AB', {}, BasicCheckResult(0, "Mount seems OK", None)),
29 ('/ABC', {}, BasicCheckResult(0, "Mount seems OK", None))]
31 ( # Mountpoint with spaces and permission denied
32 [[u'/var/dba', u'export', u'Permission', u'denied'],
33 [u'/var/dbaexport', u'ok', u'201326592', u'170803720', u'170803720', u'32768']],
34 [('/var/dbaexport', {}),
35 ('/var/dba export', {})],
36 [('/var/dba export', {}, BasicCheckResult(2, 'Permission denied', None)),
37 ('/var/dbaexport', {}, BasicCheckResult(0, '15.2% used (931.48 GB of 6.00 TB)', None))]
39 ( # with perfdata
40 [[u'/PERFshare', u'ok', u'491520', u'460182', u'460182', u'65536']],
41 [('/PERFshare', {})],
42 [('/PERFshare', {'has_perfdata': True},
43 BasicCheckResult(0, "6.4% used (1.91 GB of 30.00 GB)", [
44 PerfValue('fs_size', 491520 * 65536), PerfValue('fs_used', 491520 * 65536 - 460182 * 65536)
45 ]))]
47 ( # state == 'hanging'
48 [[u'/test', u'hanging', u'hanging', u'0', u'0', u'0', u'0']],
49 [('/test hanging', {})],
50 [('/test hanging', {'has_perfdata': True},
51 BasicCheckResult(2, "Server not responding", None))]
53 ( # unknown state
54 [[u'/test', u'unknown', u'unknown', u'1', u'1', u'1', u'1']],
55 [('/test unknown', {})],
56 [('/test unknown', {}, BasicCheckResult(2, "Unknown state", None))]
58 ( # zero block size
59 [[u'/test', u'perfdata', u'ok', u'0', u'460182', u'460182', u'0']],
60 [('/test perfdata', {})],
61 [('/test perfdata', {'has_perfdata': True},
62 # TODO: display a better error message
63 #BasicCheckResult(0, "server is responding", [PerfValue('fs_size', 0), PerfValue('fs_used', 0)]))]
64 BasicCheckResult(2, "Stale fs handle", None))]
67 def test_nfsmounts(check_manager, info, discovery_expected, check_expected):
68 check_nfs = check_manager.get_check("nfsmounts")
69 check_cifs = check_manager.get_check("cifsmounts")
71 # assure that the code of both checks is identical
72 assert (check_nfs.info['parse_function'].func_code.co_code ==
73 check_cifs.info['parse_function'].func_code.co_code)
74 assert (check_nfs.info['inventory_function'].func_code.co_code ==
75 check_cifs.info['inventory_function'].func_code.co_code)
76 assert (check_nfs.info['check_function'].func_code.co_code ==
77 check_cifs.info['check_function'].func_code.co_code)
79 parsed = check_nfs.run_parse(info)
81 assertDiscoveryResultsEqual(check_nfs,
82 DiscoveryResult(check_nfs.run_discovery(parsed)), #
83 DiscoveryResult(discovery_expected))
85 for item, params, result_expected in check_expected:
86 result = BasicCheckResult(*check_nfs.run_check(item, params, parsed))
87 assert result == result_expected