Example #1
0
def test_store_piggyback_raw_data_second_source():
    time_settings = {(None, "max_cache_age"): piggyback_max_cachefile_age}

    piggyback.store_piggyback_raw_data(
        "source2", {"test-host": [
            u"<<<check_mk>>>",
            u"lulu",
        ]})

    for raw_data_info in piggyback.get_piggyback_raw_data(
            "test-host", time_settings):
        assert raw_data_info.source_hostname in ["source1", "source2"]
        if raw_data_info.source_hostname == "source1":
            assert raw_data_info.file_path.endswith('/test-host/source1')
            assert raw_data_info.successfully_processed is True
            assert raw_data_info.reason.startswith(
                "Successfully processed from source 'source1'")
            assert raw_data_info.reason_status == 0
            assert raw_data_info.raw_data == '<<<check_mk>>>\nlala\n'

        else:  # source2
            assert raw_data_info.file_path.endswith('/test-host/source2')
            assert raw_data_info.successfully_processed is True
            assert raw_data_info.reason.startswith(
                "Successfully processed from source 'source2'")
            assert raw_data_info.reason_status == 0
            assert raw_data_info.raw_data == '<<<check_mk>>>\nlulu\n'
Example #2
0
def test_store_piggyback_raw_data_new_host():
    piggyback.store_piggyback_raw_data("source2", {"pig": [
        u"<<<check_mk>>>",
        u"lulu",
    ]})

    assert piggyback.get_piggyback_raw_data(piggyback_max_cachefile_age, "pig") == [
        ('source2', '<<<check_mk>>>\nlulu\n'),
    ]
Example #3
0
def test_get_piggyback_raw_data_source_not_sending_anymore():
    assert piggyback.get_piggyback_raw_data(piggyback_max_cachefile_age,
                                            "test-host") == [
                                                ('source1',
                                                 '<<<check_mk>>>\nlala\n')
                                            ]
    piggyback.store_piggyback_raw_data("source1", {})
    assert piggyback.get_piggyback_raw_data(piggyback_max_cachefile_age,
                                            "test-host") == []
Example #4
0
def test_store_piggyback_raw_data_second_source():
    piggyback.store_piggyback_raw_data("source2", {"test-host": [
        u"<<<check_mk>>>",
        u"lulu",
    ]})

    assert sorted(piggyback.get_piggyback_raw_data(piggyback_max_cachefile_age,
                                                   "test-host")) == sorted([
                                                       ('source1', '<<<check_mk>>>\nlala\n'),
                                                       ('source2', '<<<check_mk>>>\nlulu\n'),
                                                   ],)
Example #5
0
def test_get_piggyback_raw_data_outdate_old_pigs():
    assert piggyback.get_piggyback_raw_data(piggyback_max_cachefile_age,
                                            "test-host") == [('source1', '<<<check_mk>>>\nlala\n')]

    # Fake age the test-host piggyback file
    os.utime(str(cmk.utils.paths.piggyback_dir / "test-host" / "source1"),
             (time.time() - 10, time.time() - 10))

    piggyback.store_piggyback_raw_data("source1", {"test-host2": [
        u"<<<check_mk>>>",
        u"lulu",
    ]})

    assert piggyback.get_piggyback_raw_data(piggyback_max_cachefile_age, "test-host") == []
Example #6
0
def test_store_piggyback_raw_data_new_host():
    time_settings = {(None, "max_cache_age"): piggyback_max_cachefile_age}

    piggyback.store_piggyback_raw_data("source2",
                                       {"pig": [
                                           u"<<<check_mk>>>",
                                           u"lulu",
                                       ]})

    for raw_data_info in piggyback.get_piggyback_raw_data(
            "pig", time_settings):
        assert raw_data_info.source_hostname == "source2"
        assert raw_data_info.file_path.endswith('/pig/source2')
        assert raw_data_info.successfully_processed is True
        assert raw_data_info.reason.startswith(
            "Successfully processed from source 'source2'")
        assert raw_data_info.reason_status == 0
        assert raw_data_info.raw_data == '<<<check_mk>>>\nlulu\n'
Example #7
0
def test_get_source_and_piggyback_hosts():
    cmk.utils.paths.piggyback_source_dir.mkdir(parents=True, exist_ok=True)  # pylint: disable=no-member

    piggyback.store_piggyback_raw_data(
        "source1", {
            "test-host2": [
                u"<<<check_mk>>>",
                u"source1",
            ],
            "test-host": [
                u"<<<check_mk>>>",
                u"source1",
            ]
        })

    # Fake age the test-host piggyback file
    os.utime(str(cmk.utils.paths.piggyback_dir / "test-host" / "source1"),
             (time.time() - 10, time.time() - 10))

    piggyback.store_piggyback_raw_data(
        "source1", {"test-host2": [
            u"<<<check_mk>>>",
            u"source1",
        ]})

    piggyback.store_piggyback_raw_data(
        "source2", {
            "test-host2": [
                u"<<<check_mk>>>",
                u"source2",
            ],
            "test-host": [
                u"<<<check_mk>>>",
                u"source2",
            ]
        })

    assert sorted(
        list(
            piggyback.get_source_and_piggyback_hosts(
                piggyback_max_cachefile_age))) == sorted([
                    ('source1', 'test-host2'),
                    ('source2', 'test-host'),
                    ('source2', 'test-host2'),
                ])