diff --git a/exasol/nb_connector/itde_manager.py b/exasol/nb_connector/itde_manager.py index 502c7b1..799e09b 100644 --- a/exasol/nb_connector/itde_manager.py +++ b/exasol/nb_connector/itde_manager.py @@ -70,7 +70,7 @@ def bring_itde_up(conf: Secrets) -> None: db_info = env_info.database_info container_info = db_info.container_info - # _add_current_container_to_db_network(container_info.network_info.network_name) + _add_current_container_to_db_network(container_info.network_info.network_name) conf.save(AILabConfig.itde_container, container_info.container_name) conf.save(AILabConfig.itde_volume, container_info.volume_name) @@ -105,10 +105,15 @@ def _add_current_container_to_db_network(network_name: str) -> None: if not container: return network = _get_docker_network(docker_client, network_name) - if network and (container not in network.containers): + if network and not _is_container_connected_to_network(container, network): network.connect(container.id) +def _is_container_connected_to_network(container, network) -> bool: + network.reload() + return container in network.containers + + def _is_current_container_visible(network_name: str) -> bool: """ For the Docker Edition returns True if the current (AI-Lab) container @@ -123,7 +128,7 @@ def _is_current_container_visible(network_name: str) -> bool: network = _get_docker_network(docker_client, network_name) if not network: return False - return container in network.containers + return _is_container_connected_to_network(container, network) def _get_docker_network(docker_client: docker.DockerClient, network_name: str) -> Optional[Network]: diff --git a/test/integration/test_itde_manager_in_docker_container.py b/test/integration/test_itde_manager_in_docker_container.py index 1b5023d..6943dfe 100644 --- a/test/integration/test_itde_manager_in_docker_container.py +++ b/test/integration/test_itde_manager_in_docker_container.py @@ -209,38 +209,23 @@ def run_test(): bring_itde_up(secrets) status = get_itde_status(secrets) - # ----- Debugging ------ - if status is ItdeContainerStatus.RUNNING: - from exasol.nb_connector.itde_manager import _get_current_container, _get_docker_network - with ContextDockerClient() as docker_client: - container = _get_current_container(docker_client) - assert container is not None, 'Cannot find the calling container.' - network_name = secrets.get(AILabConfig.itde_network) - assert network_name, 'Network name is not in the configuration store.' - network = _get_docker_network(docker_client, network_name) - assert network is not None, 'Cannot find the Docker-DB network.' - err_code = network.connect(container.id) - network.reload() - in_network = container in network.containers - connected_containers = [cont.name for cont in network.containers] - assert in_network, f'Container is not connected to the Docker DB network. Error code: {err_code}. Containers: {connected_containers}' - assert status is ItdeContainerStatus.READY, f'The status after bringing itde up is {status}' + assert status is ItdeContainerStatus.READY, f'The status after bringing itde up is {status.name}' # Disconnect calling container from Docker-DB network _remove_current_container_from_db_network(secrets) status = get_itde_status(secrets) - assert status is ItdeContainerStatus.RUNNING, f'The status after disconnecting the container is {status}' + assert status is ItdeContainerStatus.RUNNING, f'The status after disconnecting the container is {status.name}' # Stop the Docker-DB container. container_name = secrets.get(AILabConfig.itde_container) with ContextDockerClient() as docker_client: docker_client.api.stop(container_name) status = get_itde_status(secrets) - assert status is ItdeContainerStatus.STOPPED, f'The status after stopping ITDE is {status}' + assert status is ItdeContainerStatus.STOPPED, f'The status after stopping ITDE is {status.name}' restart_itde(secrets) status = get_itde_status(secrets) - assert status is ItdeContainerStatus.READY, f'The status after restarting ITDE is {status}' + assert status is ItdeContainerStatus.READY, f'The status after restarting ITDE is {status.name}' function_source_code = textwrap.dedent(dill.source.getsource(run_test)) source_code = f"{function_source_code}\nrun_test()"