Blob Blame History Raw
From c21040a0d9a81b6337ec7849bcee6bec525fdd4c Mon Sep 17 00:00:00 2001
From: Kaleb S. KEITHLEY <kkeithle@redhat.com>
Date: Wed, 17 Jun 2015 11:03:12 -0400
Subject: [PATCH 102/129] common-ha: cluster HA setup sometimes fails

the "s in the VIP_foo="x.x.x.x" lines are problematic now that the
config file isn't sourced.

Revised to also handle names containing '-', e.g. host-11, and FQNs,
e.g. host-11.lab.gluster.org

backport of
>> Change-Id: I1a52afbf398a024cdff851d0c415d8363f699c90
>> BUG: 1232001
>> Signed-off-by: Kaleb S. KEITHLEY <kkeithle@redhat.com>
>> http://review.gluster.org/#/c/11281/
>
> Change-Id: I108eb5f1922a0b6ee41817d901a2ae0e027e5370
> BUG: 1232002
> Signed-off-by: Kaleb S. KEITHLEY <kkeithle@redhat.com>
> http://review.gluster.org/#/c/11282/

Change-Id: I40b45d79d25f8b047081c86bf6b75c07216d5165
BUG: 1227311
Signed-off-by: Kaleb S. KEITHLEY <kkeithle@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/50952
Reviewed-by: Soumya Koduri <skoduri@redhat.com>
---
 extras/ganesha/scripts/ganesha-ha.sh |   27 ++++++++++++++++++++++-----
 1 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/extras/ganesha/scripts/ganesha-ha.sh b/extras/ganesha/scripts/ganesha-ha.sh
index 7c7e9c5..fc2a009 100755
--- a/extras/ganesha/scripts/ganesha-ha.sh
+++ b/extras/ganesha/scripts/ganesha-ha.sh
@@ -343,10 +343,23 @@ setup_create_resources()
 
     while [[ ${1} ]]; do
 
+        # this is variable indirection
+        # from a nvs like 'VIP_host1=10.7.6.5' or 'VIP_host1="10.7.6.5"'
+        # (or VIP_host-1=..., or VIP_host-1.my.domain.name=...)
+        # a variable 'clean_name' is created (e.g. w/ value 'VIP_host_1')
+        # and a clean nvs (e.g. w/ value 'VIP_host_1="10_7_6_5"')
+        # after the `eval ${clean_nvs}` there is a variable VIP_host_1
+        # with the value '10_7_6_5', and the following \$$ magic to
+        # reference it, i.e. `eval tmp_ipaddr=\$${clean_name}` gives us
+        # ${tmp_ipaddr} with 10_7_6_5 and then convert the _s back to .s
+        # to give us ipaddr="10.7.6.5". whew!
         name="VIP_${1}"
+        clean_name=${name//[-.]/_}
         nvs=$(grep "^${name}=" ${HA_CONFDIR}/ganesha-ha.conf)
-        eval ${nvs}
-        eval ipaddr=\$$name
+        clean_nvs=${nvs//[-.]/_}
+        eval ${clean_nvs}
+        eval tmp_ipaddr=\$${clean_name}
+        ipaddr=${tmp_ipaddr//_/.}
 
         pcs -f ${cibfile} resource create ${1}-cluster_ip-1 ocf:heartbeat:IPaddr ip=${ipaddr} cidr_netmask=32 op monitor interval=15s
         if [ $? -ne 0 ]; then
@@ -440,10 +453,15 @@ recreate_resources()
     local cibfile=${1}; shift
 
     while [[ ${1} ]]; do
+        # this is variable indirection
+        # see the comment on the same a few lines up
         name="VIP_${1}"
+        clean_name=${name//[-.]/_}
         nvs=$(grep "^${name}=" ${HA_CONFDIR}/ganesha-ha.conf)
-        eval ${nvs}
-        eval ipaddr=\$$name
+        clean_nvs=${nvs//[-.]/_}
+        eval ${clean_nvs}
+        eval tmp_ipaddr=\$${clean_name}
+        ipaddr=${tmp_ipaddr//_/.}
 
         pcs -f ${cibfile} resource create ${1}-cluster_ip-1 ocf:heartbeat:IPaddr ip=${ipaddr} cidr_netmask=32 op monitor interval=15s
         if [ $? -ne 0 ]; then
@@ -767,7 +785,6 @@ main()
         teardown_resources ${HA_SERVERS}
 
         teardown_cluster ${HA_NAME}
-
         ;;
 
     cleanup | --cleanup)
-- 
1.7.1