From 775620733bc2d848e5eeac3e18a2b0734e750a83 Mon Sep 17 00:00:00 2001
From: Mark Goddard <mark@stackhpc.com>
Date: Mon, 22 Mar 2021 19:50:01 +0000
Subject: [PATCH] CI: Fix IP address detection in baremetal compute test

The 'openstack server show <server> -f value -c addresses' command
previously had output like this:

    <network name>=<IP>

Now it shows a Python output like this:

    {'<network name>': ['IP']}

This broke the parsing of the command output when determining which IP
address to use to access a bare metal instance via SSH.

This change fixes the issue by querying the server's port in Neutron,
and using the fixed IP address.

Change-Id: I55b5f185fb7136d3c6fa565aa46598f21c94eb43
---
 dev/functions | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/dev/functions b/dev/functions
index fccdf0b4..019c54fd 100644
--- a/dev/functions
+++ b/dev/functions
@@ -505,7 +505,12 @@ function overcloud_test {
     # Test SSH connectivity. For servers attached directly to the external
     # network, use the fixed IP. Otherwise add a floating IP.
     if [[ $network = provision-net ]]; then
-        ip=$(openstack server show "$name" -f value -c addresses | sed -e "s/${network}=//")
+        port_id=$(openstack port list --server $name --network $network -f value -c ID)
+        echo "port $port_id"
+        fixed_ips=$(openstack port show $port_id -f json -c fixed_ips)
+        echo "fixed_ips $fixed_ips"
+        ip=$(echo $fixed_ips | python3 -c "import json,sys; print(json.load(sys.stdin)['fixed_ips'][0]['ip_address'])")
+        echo "ip $ip"
     else
         echo "$name: Attaching floating IP"
         if is_ironic_enabled; then
-- 
GitLab