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.
pull/74103/head
Matt Clay 4 days ago committed by GitHub
parent c99493eb3f
commit 95e3af3e0f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,3 @@
minor_changes:
- ansible-test - 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.

@ -292,10 +292,13 @@ def get_docker_preferred_network_name(args: EnvironmentConfig) -> t.Optional[str
current_container_id = get_docker_container_id() current_container_id = get_docker_container_id()
if current_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. try:
# This is needed when ansible-test is running in a container that is not connected to Docker's default network. # Make sure any additional containers we launch use the same network as the current container we're running in.
container = docker_inspect(args, current_container_id, always=True) # This is needed when ansible-test is running in a container that is not connected to Docker's default network.
network = container.get_network_name() 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 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. # The default podman behavior puts containers on isolated networks which don't allow communication between containers or network disconnect.

Loading…
Cancel
Save