summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMatt Clay <matt@mystile.com>2024-11-19 19:49:24 +0100
committerGitHub <noreply@github.com>2024-11-19 19:49:24 +0100
commit95e3af3e0f6a054988591913a46c95b6aff94cb5 (patch)
treee17154ae84463b05c294427c15a63d486f24bfce /test
parentdnf5 - consolidate package resolving settings (#84335) (diff)
downloadansible-95e3af3e0f6a054988591913a46c95b6aff94cb5.tar.xz
ansible-95e3af3e0f6a054988591913a46c95b6aff94cb5.zip
ansible-test - Improve container network detection (#84323)
When detection of the current container network fails, a warning is now issued and execution continues. This simplifies usage in cases where the current container cannot be inspected, such as when running in GitHub Codespaces.
Diffstat (limited to 'test')
-rw-r--r--test/lib/ansible_test/_internal/containers.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/test/lib/ansible_test/_internal/containers.py b/test/lib/ansible_test/_internal/containers.py
index 92a40a4806..79c8cd6b39 100644
--- a/test/lib/ansible_test/_internal/containers.py
+++ b/test/lib/ansible_test/_internal/containers.py
@@ -292,10 +292,13 @@ def get_docker_preferred_network_name(args: EnvironmentConfig) -> t.Optional[str
current_container_id = get_docker_container_id()
if current_container_id:
- # Make sure any additional containers we launch use the same network as the current container we're running in.
- # This is needed when ansible-test is running in a container that is not connected to Docker's default network.
- container = docker_inspect(args, current_container_id, always=True)
- network = container.get_network_name()
+ try:
+ # Make sure any additional containers we launch use the same network as the current container we're running in.
+ # This is needed when ansible-test is running in a container that is not connected to Docker's default network.
+ container = docker_inspect(args, current_container_id, always=True)
+ network = container.get_network_name()
+ except ContainerNotFoundError:
+ display.warning('Unable to detect the network for the current container. Use the `--docker-network` option if containers are unreachable.')
# The default docker behavior puts containers on the same network.
# The default podman behavior puts containers on isolated networks which don't allow communication between containers or network disconnect.