def test_df_check(): item_1st = 'VMFS_01' params = {'flex_levels': 'irrelevant'} check = Check("hp_msa_volume.df") parsed = { u'VMFS_01': { u'durable-id': u'V3', u'virtual-disk-name': u'A', u'total-size-numeric': u'4296482816', u'allocated-size-numeric': u'2484011008', u'raidtype': u'RAID0', }, u'VMFS_02': { u'durable-id': u'V4', u'virtual-disk-name': u'A', u'total-size-numeric': u'4296286208', u'allocated-size-numeric': u'3925712896', u'raidtype': u'RAID0', } } expected_result = ( 0, '57.81% used (1.16 of 2.00 TB), trend: +2.43 TB / 24 hours', [ ('fs_used', 1212896, 1678313.6, 1888102.8, 0, 2097892), ('fs_size', 2097892), ('fs_used_percent', 57.81498761614039), ('growth', 1329829.766497462), ('trend', 2551581.1594836353, None, None, 0, 87412.16666666667), ]) with freezegun.freeze_time("2020-07-31 07:00:00"), mock_item_state( (1596100000, 42)): _, trend_result = check.run_check(item_1st, params, parsed) assertCheckResultsEqual(CheckResult(trend_result), CheckResult(expected_result))
def test_check_temperature_called(test_case): check = Check('acme_temp') check_temperature = check.context['check_temperature'] time = dt.datetime(2014, 1, 1, 0, 0, 0) state = { 'temp.foo.delta': (unix_ts(time), test_case.reading), 'temp.foo.trend': (0, 0) } with mock_item_state(state): with freezegun.freeze_time(time + dt.timedelta(seconds=test_case.seconds_elapsed)): # Assuming atmospheric pressure... result = check_temperature( test_case.reading + test_case.growth, { 'device_level_handling': 'dev', 'trend_compute': test_case.wato_dict, }, 'foo', dev_unit='c', dev_levels=(100, 100), # don't boil dev_levels_lower=(0, 0), # don't freeze over ) assertCheckResultsEqual(CheckResult(result), CheckResult(test_case.expected))
def test_statgrab_cpu_check(info, mockstate, expected_result): check = Check("statgrab_cpu") # set up mocking of `get_item_state` with mock_item_state(mockstate): result = CheckResult(check.run_check(None, {}, info)) assertCheckResultsEqual(result, expected_result)
def test_statgrab_cpu_check_error(info, mockstate): check = Check("statgrab_cpu") with mock_item_state(mockstate): # the mock values are designed to raise an exception. # to make sure it is raised, use this: with assertMKCounterWrapped('Too short time difference since last check'): CheckResult(check.run_check(None, {}, info))
def test_docker_container_diskstat_wrapped(): check = Check('docker_container_diskstat') parsed = check.run_parse(INFO_MISSING_COUNTERS) with pytest.raises(MKCounterWrapped): check.run_check("SUMMARY", {}, parsed) with mock_item_state((0, 0)): # raise MKCounterWrapped anyway, because counters are missing in info with pytest.raises(MKCounterWrapped): check.run_check("SUMMARY", {}, parsed)
def test_check_temperature_trend(test_case): check = Check('acme_temp') check_trend = check.context['check_temperature_trend'] time = dt.datetime(2014, 1, 1, 0, 0, 0) state = { 'temp.foo.delta': (unix_ts(time), test_case.reading), 'temp.foo.trend': (0, 0) } with mock_item_state(state): with freezegun.freeze_time(time + dt.timedelta(seconds=test_case.seconds_elapsed)): result = check_trend(test_case.reading + test_case.growth, test_case.wato_dict, 'c', 100, # crit, don't boil 0, # crit_lower, don't freeze over 'foo') assertCheckResultsEqual(CheckResult(result), CheckResult(test_case.expected))
def run(check_info, dataset, write=False): """Run all possible tests on 'dataset'""" print("START: %r" % (dataset, )) checklist = checkhandler.get_applicables(dataset.checkname, check_info) assert checklist, "Found no check plugin for %r" % (dataset.checkname, ) immu = Immutables() with optional_freeze_time(dataset): parsed = run_test_on_parse(dataset, immu) # LOOP OVER ALL (SUB)CHECKS for sname in checklist: subcheck = (sname + '.').split('.')[1] check = Check(sname) info_arg = get_info_argument(dataset, subcheck, parsed) immu.test(' after get_info_argument ') immu.register(info_arg, 'info_arg') mock_is, mock_hec, mock_hecm = get_mock_values(dataset, subcheck) with \ current_host("non-existent-testhost"), \ mock_item_state(mock_is), \ MockHostExtraConf(check, mock_hec), \ MockHostExtraConf(check, mock_hecm, "host_extra_conf_merged"): run_test_on_discovery(check, subcheck, dataset, info_arg, immu, write) run_test_on_checks(check, subcheck, dataset, info_arg, immu, write) immu.test(' at end of subcheck loop %r ' % (subcheck, ))