tripleo-upgrade/templates/l3_agent_start_ping.sh.j2
Sergii Golovatiuk 15be9e74e2 Refactor FIP extraction
"openstack server list" produces different output for different OSP
versions.

This change gets the very last IP from "openstack server list" which
will be the last IP of last active network and uses it for finding
correspondent Floating IP. Regexp extract IPv4 or IPv6 IP allowing to
have diffent formats of output.

Change-Id: I2a0706ed55fd99458d43ec34406ea6398dfe5c1d
(cherry picked from commit 12671705b2)
2023-04-03 23:16:53 +02:00

43 lines
1.9 KiB
Django/Jinja

#!/bin/bash
#
# Script which start an ICMP connectivity check on the first in use
# floating IP during upgrade
if [ -f {{ working_dir }}/vm_ip.sh ]; then
source {{ working_dir }}/vm_ip.sh
else
{% if workload_sriov | bool %}
echo export VM_IP=$(openstack server list -f json | jq -r -c '.[0]["Networks"]' | cut -d"=" -f2) > {{ working_dir }}/vm_ip.sh
{% else %}
#openstack server list --status ACTIVE -c Networks -f value produces different results in different OSP versions
#OSP10,13,16
#openstack server list --status ACTIVE -c Networks -f value
#internal_net_6f58c1ef02=192.168.0.13, 10.0.0.159
#internal_net_7c845f5f18=192.168.0.13, 10.0.0.173
#OSP17+
#{'internal_net_93bd647902': ['192.168.0.22', '10.0.0.159']}
#{'internal_net_7c845a1e74': ['192.168.0.13', '10.0.0.173']}
#IPv6 IPs are also possible
#
#Next line extracts last ip from all active networks and finds correspondant floating IP
echo export VM_IP=$(openstack floating ip list -c 'Floating IP Address' -f value | \
grep "$(openstack server list --status ACTIVE -c Networks -f value | \
grep -Eo '(([0-9a-fA-F]{1,4}:+){3,7}[0-9a-fA-F]{1,4})|(([0-9]{1,3}[\.]){3}[0-9]{1,3})' | tail -1)") > {{ working_dir }}/vm_ip.sh
{% endif %}
source {{ working_dir }}/vm_ip.sh
fi
# NOTE: the &>> is necessary as if we don't redirect both
# stdout and stderr we will make any script using this one to
# hang until ping finishes. Meaning if some script crashes
# and should fail in CI it will get stuck if we don't redirect
# both outputs.
# bash
# \ bash <script>
# \ &| awk blah
# If script runs l3 start test and than runs something that fails
# we will make the awk wait until this ping exits as it will hold
# the output pipes. So again &>> instead of >> is necessary.
ping -D ${VM_IP} &>> ~/ping_results_$(date +%Y%m%d%H%M%S).log &