From 14ff5e213cd084480d628ec0562200b174b6fa79 Mon Sep 17 00:00:00 2001 From: Matt Clay Date: Thu, 22 Apr 2021 10:18:23 -0700 Subject: [PATCH] Fix ansible-test docker container IP detection. --- .../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 75893e5dd14..5672ca1c801 100644 --- a/test/lib/ansible_test/_internal/docker_util.py +++ b/test/lib/ansible_test/_internal/docker_util.py @@ -423,7 +423,13 @@ class DockerInspect: def get_ip_address(self): # type: () -> t.Optional[str] """Return the IP address of the container for the preferred docker network.""" if self.networks: - network_name = get_docker_preferred_network_name(self.args) or 'bridge' + network_name = get_docker_preferred_network_name(self.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(self.networks.keys()).pop(0) + ipaddress = self.networks[network_name]['IPAddress'] else: ipaddress = self.network_settings['IPAddress']