Stabilize gate: Fix CONTROLLER_IP is .1 issue

There is still a bug in determining the host IP in a gate run
if it ends with .1 - this is due to the fact that the variable
has spaces in it so the -z test for a missing IP does not return
true.

This has been changed to ignore spaces.

Change-Id: I70701f1d3985b0347fd2aa796e712ead73ea9635
Closes-Bug: 1668674
This commit is contained in:
Peter Stachowski 2017-02-28 16:07:46 +00:00
parent bc49fd25b2
commit be540c58cd

View File

@ -1283,29 +1283,29 @@ function cmd_dsvm_gate_tests() {
exclaim "Running cmd_dsvm_gate_tests ..."
# Sometimes in the gate the ACTUAL_HOSTNAME is blank - this code attempts to debug it
if [[ -z "${CONTROLLER_IP}" ]]; then
if [[ -z "${CONTROLLER_IP// }" ]]; then
echo "*** CONTROLLER_IP is blank, trying to determine actual hostname"
local hostname_part=$(hostname -I)
echo "Hostname pass 1: $hostname_part"
echo "Hostname pass 1: '$hostname_part'"
hostname_part=$(echo $hostname_part | sed 's/[0-9a-z][0-9a-z]*:.*:[0-9a-z][0-9a-z]*//g')
echo "Hostname pass 2: $hostname_part"
echo "Hostname pass 2: '$hostname_part'"
hostname_part_no_ip6=$hostname_part
hostname_part=$(echo $hostname_part | sed 's/[0-9]*\.[0-9]*\.[0-9]*\.1\b//g')
echo "Hostname pass 3: $hostname_part"
if [[ -z "${hostname_part}" ]]; then
echo "Hostname pass 3: '$hostname_part'"
if [[ -z "${hostname_part// }" ]]; then
# This seems to occur when the actual hostname ends with '.1'
# If this happens, take the first one that doesn't start with '192' or '172'
hostname_part=$(echo $hostname_part_no_ip6 | sed 's/1[79]2\.[0-9]*\.[0-9]*\.1\b//g')
echo "Hostname pass 3a: $hostname_part"
echo "Hostname pass 3a: '$hostname_part'"
fi
hostname_part=$(echo $hostname_part | sed 's/ /\n/g')
echo "Hostname pass 4: $hostname_part"
echo "Hostname pass 4: '$hostname_part'"
hostname_part=$(echo $hostname_part | sed '/^$/d')
echo "Hostname pass 5: $hostname_part"
echo "Hostname pass 5: '$hostname_part'"
hostname_part=$(echo $hostname_part | sort -bu)
echo "Hostname pass 6: $hostname_part"
echo "Hostname pass 6: '$hostname_part'"
hostname_part=$(echo $hostname_part | head -1)
echo "Hostname pass 7: $hostname_part"
echo "Hostname pass 7: '$hostname_part'"
CONTROLLER_IP=$hostname_part
echo "*** CONTROLLER_IP was blank (CONTROLLER_IP now set to '$CONTROLLER_IP')"
fi