Ejemplo n.º 1
0
async def _start_and_wait_for_dynamic_services_ready(
    director_v2_client: httpx.AsyncClient,
    user_id: UserID,
    workbench_dynamic_services: Dict[str, Node],
    current_study: ProjectAtDB,
) -> Dict[str, str]:
    # start dynamic services
    await asyncio.gather(
        *(
            assert_start_service(
                director_v2_client=director_v2_client,
                user_id=user_id,
                project_id=str(current_study.uuid),
                service_key=node.key,
                service_version=node.version,
                service_uuid=service_uuid,
                basepath=f"/x/{service_uuid}" if is_legacy(node) else None,
            )
            for service_uuid, node in workbench_dynamic_services.items()
        )
    )

    dynamic_services_urls: Dict[str, str] = {}

    for service_uuid in workbench_dynamic_services:
        dynamic_service_url = await patch_dynamic_service_url(
            # pylint: disable=protected-access
            app=director_v2_client._transport.app,
            node_uuid=service_uuid,
        )
        dynamic_services_urls[service_uuid] = dynamic_service_url

    await assert_all_services_running(
        director_v2_client, workbench=workbench_dynamic_services
    )

    await assert_services_reply_200(
        director_v2_client=director_v2_client,
        workbench=workbench_dynamic_services,
    )

    return dynamic_services_urls
async def test_legacy_and_dynamic_sidecar_run(
    dy_static_file_server_project: ProjectAtDB,
    user_db: Dict,
    services_endpoint: Dict[str, URL],
    simcore_services_ready_and_change_director_env: None,
    director_v2_client: httpx.AsyncClient,
    ensure_services_stopped: None,
):
    """
    The test will start 3 dynamic services in the same project and check
    that the legacy and the 2 new dynamic-sidecar boot properly.

    Creates a project containing the following services:
    - dy-static-file-server (legacy)
    - dy-static-file-server-dynamic-sidecar  (sidecared w/ std config)
    - dy-static-file-server-dynamic-sidecar-compose (sidecared w/ docker-compose)
    """
    # FIXME: ANE can you instead parametrize this test?
    # why do we need to run all these services at the same time? it would be simpler one by one

    await asyncio.gather(*(
        assert_start_service(
            director_v2_client=director_v2_client,
            # context
            user_id=user_db["id"],
            project_id=str(dy_static_file_server_project.uuid),
            # service
            service_key=node.key,
            service_version=node.version,
            service_uuid=node_id,
            # extra config (legacy)
            basepath=f"/x/{node_id}" if is_legacy(node) else None,
        )
        for node_id, node in dy_static_file_server_project.workbench.items()))

    for node_id, node in dy_static_file_server_project.workbench.items():
        if is_legacy(node):
            continue

        await patch_dynamic_service_url(
            # pylint: disable=protected-access
            app=director_v2_client._transport.app,
            node_uuid=node_id,
        )

    assert len(dy_static_file_server_project.workbench) == 3

    await assert_all_services_running(
        director_v2_client,
        workbench=dy_static_file_server_project.workbench,
    )

    # query the service directly and check if it responding accordingly
    await assert_services_reply_200(
        director_v2_client=director_v2_client,
        workbench=dy_static_file_server_project.workbench,
    )

    # finally stop the started services
    await asyncio.gather(*(assert_stop_service(
        director_v2_client=director_v2_client,
        service_uuid=service_uuid,
    ) for service_uuid in dy_static_file_server_project.workbench))