From 1df28faad6a06f48a81dc4f2d6dd3a8380bb9438 Mon Sep 17 00:00:00 2001 From: Matt Clay Date: Thu, 22 Apr 2021 10:18:23 -0700 Subject: [PATCH] [stable-2.11] Fix ansible-test docker container IP detection.. (cherry picked from commit 14ff5e213cd084480d628ec0562200b174b6fa79) Co-authored-by: Matt Clay --- .../fragments/ansible-test-docker-network-detect.yml | 2 ++ test/lib/ansible_test/_internal/docker_util.py | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/ansible-test-docker-network-detect.yml diff --git a/changelogs/fragments/ansible-test-docker-network-detect.yml b/changelogs/fragments/ansible-test-docker-network-detect.yml new file mode 100644 index 00000000000..620fdc28976 --- /dev/null +++ b/changelogs/fragments/ansible-test-docker-network-detect.yml @@ -0,0 +1,2 @@ +bugfixes: + - ansible-test - Fix docker container IP address detection. The ``bridge`` network is no longer assumed to be the default. diff --git a/test/lib/ansible_test/_internal/docker_util.py b/test/lib/ansible_test/_internal/docker_util.py index 3ad771bd41c..ed8fb479811 100644 --- a/test/lib/ansible_test/_internal/docker_util.py +++ b/test/lib/ansible_test/_internal/docker_util.py @@ -112,7 +112,13 @@ def get_docker_container_ip(args, container_id): networks = network_settings.get('Networks') if networks: - network_name = get_docker_preferred_network_name(args) or 'bridge' + network_name = get_docker_preferred_network_name(args) + + if not network_name: + # Sort networks and use the first available. + # This assumes all containers will have access to the same networks. + network_name = sorted(networks.keys()).pop(0) + ipaddress = networks[network_name]['IPAddress'] else: # podman doesn't provide Networks, fall back to using IPAddress