Skip to content

Commit

Permalink
debugging the test
Browse files Browse the repository at this point in the history
  • Loading branch information
ahsimb committed Apr 2, 2024
1 parent edb06bb commit 78648cd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 22 deletions.
11 changes: 8 additions & 3 deletions exasol/nb_connector/itde_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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]:
Expand Down
23 changes: 4 additions & 19 deletions test/integration/test_itde_manager_in_docker_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()"
Expand Down

0 comments on commit 78648cd

Please sign in to comment.