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 MockItemState((0, 0)):
        # raise MKCounterWrapped anyway, because counters are missing in info
        with pytest.raises(MKCounterWrapped):
            check.run_check("SUMMARY", {}, parsed)
Beispiel #2
0
def run(check_manager, dataset, write=False):
    """Run all possible tests on 'dataset'"""
    print("START: %r" % dataset)
    checklist = checkhandler.get_applicables(dataset.checkname)
    assert checklist, "Found no check plugin for %r" % dataset.checkname

    immu = Immutables()

    with optional_freeze_time(dataset):
        # test the parse function
        if hasattr(dataset, 'info'):
            immu.register(dataset.info, 'info')
        parsed = parse(check_manager, dataset)
        immu.test(' after parse function ')

        immu.register(parsed, 'parsed')

        # get the expected check results, if present
        checks_expected = getattr(dataset, 'checks', {})

        # LOOP OVER ALL (SUB)CHECKS
        for sname in checklist:
            subcheck = (sname + '.').split('.')[1]
            check = check_manager.get_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 MockItemState(mock_is), \
                 MockHostExtraConf(check, mock_hec), \
                 MockHostExtraConf(check, mock_hecm, "host_extra_conf_merged"):
                # test discovery
                d_result = discovery(check, subcheck, dataset, info_arg, immu)
                if write:
                    dataset.discovery[subcheck] = [e.tuple for e in d_result]
                    # test checks
                for dr in d_result:
                    cdr = check_discovered_result(check, dr, info_arg, immu)
                    if write and cdr:
                        dataset.checks.setdefault(subcheck, []).append(cdr)
                if not write:
                    for entry in checks_expected.get(subcheck, []):

                        check_listed_result(check, entry, info_arg, immu)

        immu.test(' at end of subcheck loop %r ' % subcheck)
Beispiel #3
0
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 MockItemState(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))
Beispiel #4
0
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", write_state=False), \
                value_store.context(CheckPluginName("test"), "unit-test"), \
                MockItemState(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, ))