Browse code

[stable-2.9] Fix ansible-test docker container IP detection. (#74390)

(cherry picked from commit 14ff5e213cd084480d628ec0562200b174b6fa79)

Co-authored-by: Matt Clay <matt@mystile.com>

Matt Clay authored on 2021/04/27 00:07:35
Showing 2 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,2 @@
0
+bugfixes:
1
+  - ansible-test - Fix docker container IP address detection. The ``bridge`` network is no longer assumed to be the default.
... ...
@@ -106,7 +106,13 @@ def get_docker_container_ip(args, container_id):
106 106
     networks = network_settings.get('Networks')
107 107
 
108 108
     if networks:
109
-        network_name = get_docker_preferred_network_name(args) or 'bridge'
109
+        network_name = get_docker_preferred_network_name(args)
110
+
111
+        if not network_name:
112
+            # Sort networks and use the first available.
113
+            # This assumes all containers will have access to the same networks.
114
+            network_name = sorted(networks.keys()).pop(0)
115
+
110 116
         ipaddress = networks[network_name]['IPAddress']
111 117
     else:
112 118
         # podman doesn't provide Networks, fall back to using IPAddress