Example #1
0
def test_piggyback_default_time_settings():
    time_settings = [(None, "max_cache_age", piggyback_max_cachefile_age)]
    piggybacked_hostname = "test-host"
    piggyback.get_piggyback_raw_data(piggybacked_hostname, time_settings)
    piggyback.get_source_and_piggyback_hosts(time_settings)
    piggyback.has_piggyback_raw_data(piggybacked_hostname, time_settings)
    piggyback.cleanup_piggyback_files(time_settings)
Example #2
0
def test_get_source_and_piggyback_hosts():
    time_settings: piggyback.PiggybackTimeSettings = [
        (None, "max_cache_age", piggyback_max_cachefile_age)
    ]
    cmk.utils.paths.piggyback_source_dir.mkdir(parents=True, exist_ok=True)

    piggyback.store_piggyback_raw_data(
        HostName("source1"),
        {
            HostName("test-host2"): [
                b"<<<check_mk>>>",
                b"source1",
            ],
            HostName("test-host"): [
                b"<<<check_mk>>>",
                b"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(
        HostName("source1"),
        {HostName("test-host2"): [
             b"<<<check_mk>>>",
             b"source1",
         ]},
    )

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

    assert sorted(list(
        piggyback.get_source_and_piggyback_hosts(time_settings))) == sorted([
            (HostName("source1"), HostName("test-host2")),
            (HostName("source2"), HostName("test-host")),
            (HostName("source2"), HostName("test-host2")),
        ])
Example #3
0
def test_get_source_and_piggyback_hosts():
    time_settings = [(None, "max_cache_age", piggyback_max_cachefile_age)
                     ]  # type: piggyback.PiggybackTimeSettings
    cmk.utils.paths.piggyback_source_dir.mkdir(parents=True, exist_ok=True)

    piggyback.store_piggyback_raw_data(
        "source1", {
            "test-host2": [
                b"<<<check_mk>>>",
                b"source1",
            ],
            "test-host": [
                b"<<<check_mk>>>",
                b"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": [
            b"<<<check_mk>>>",
            b"source1",
        ]})

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

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