예제 #1
0
def test_uuid_link_manager_update_links_no_links_yet():
    uuid_link_manager = UUIDLinkManager(
        received_outputs_dir=received_outputs_dir,
        data_source_dir=data_source_push_agent_dir,
    )
    uuid_link_manager.update_links({})

    assert not received_outputs_dir.exists()
    assert not data_source_push_agent_dir.exists()
예제 #2
0
def test_uuid_link_manager_update_links_no_host():
    hostname = "my-hostname"
    raw_uuid = "59e631e9-de89-40d6-9662-ba54569a24fb"

    uuid_link_manager = UUIDLinkManager(
        received_outputs_dir=received_outputs_dir,
        data_source_dir=data_source_push_agent_dir,
    )
    uuid_link_manager.create_link(hostname, UUID(raw_uuid), create_target_dir=False)
    uuid_link_manager.update_links({})

    assert list(received_outputs_dir.iterdir()) == []
    assert not data_source_push_agent_dir.exists()
예제 #3
0
def test_uuid_link_manager_update_links_host_no_push():
    hostname = "my-hostname"
    raw_uuid = "59e631e9-de89-40d6-9662-ba54569a24fb"

    uuid_link_manager = UUIDLinkManager(
        received_outputs_dir=received_outputs_dir,
        data_source_dir=data_source_push_agent_dir,
    )
    uuid_link_manager.create_link(hostname, UUID(raw_uuid), create_target_dir=False)
    uuid_link_manager.update_links({hostname: {}})

    assert len(list(received_outputs_dir.iterdir())) == 1
    assert not data_source_push_agent_dir.exists()

    link = next(iter(uuid_link_manager))

    assert link.source == received_outputs_dir.joinpath(raw_uuid)
    assert link.target == data_source_push_agent_dir.joinpath(hostname)
예제 #4
0
def test_uuid_link_manager_update_links_host_push(create_target_dir: bool) -> None:
    hostname = "my-hostname"
    raw_uuid = "59e631e9-de89-40d6-9662-ba54569a24fb"

    uuid_link_manager = UUIDLinkManager(
        received_outputs_dir=received_outputs_dir,
        data_source_dir=data_source_push_agent_dir,
    )
    # During link creation the cmk_agent_connection could possibly not be calculated yet,
    # ie. push-agent or other.
    # During links update the target dirs are created for push hosts.
    uuid_link_manager.create_link(hostname, UUID(raw_uuid), create_target_dir=create_target_dir)
    uuid_link_manager.update_links({hostname: {"cmk_agent_connection": "push-agent"}})

    assert len(list(received_outputs_dir.iterdir())) == 1
    assert len(list(data_source_push_agent_dir.iterdir())) == 1

    link = next(iter(uuid_link_manager))

    assert link.source == received_outputs_dir.joinpath(raw_uuid)
    assert link.target == data_source_push_agent_dir.joinpath(hostname)
예제 #5
0
def test_uuid_link_manager_update_links_no_host_but_ready_or_discoverable(
    folder: Path,
    has_link: bool,
) -> None:
    hostname = "my-hostname"
    raw_uuid = "59e631e9-de89-40d6-9662-ba54569a24fb"

    folder.mkdir(parents=True, exist_ok=True)
    with get_r4r_filepath(folder, UUID(raw_uuid)).open("w") as f:
        f.write("")

    uuid_link_manager = UUIDLinkManager(
        received_outputs_dir=received_outputs_dir,
        data_source_dir=data_source_push_agent_dir,
    )
    uuid_link_manager.create_link(hostname, UUID(raw_uuid), create_target_dir=False)
    uuid_link_manager.update_links({})

    if has_link:
        assert len(list(received_outputs_dir.iterdir())) == 1
    else:
        assert list(received_outputs_dir.iterdir()) == []

    assert not data_source_push_agent_dir.exists()