def test_uuid_link_manager_create_link_and_target_dir(): 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=True) 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)
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)
def test_uuid_link_manager_create_link_to_different_uuid(): hostname = "my-hostname" raw_uuid_old = "59e631e9-de89-40d6-9662-ba54569a24fb" raw_uuid_new = "db1ea77f-330e-4fb5-b59e-925f55290533" 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_old), create_target_dir=False) uuid_link_manager.create_link(hostname, UUID(raw_uuid_new), create_target_dir=False) 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_new) assert link.target == data_source_push_agent_dir.joinpath(hostname)
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)