From 7862c678cddbbf36489bba9d99ab2abfada9e13a Mon Sep 17 00:00:00 2001
From: Utz-Uwe Haus <uhaus@cray.com>
Date: Fri, 2 Oct 2020 13:11:46 +0200
Subject: [PATCH] adapt MIO config creation to sage mero config query tool hctl

---
 tests/Makefile.am            |  2 +-
 tests/generate-mio-config.sh | 13 +++++++++++--
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 6ea867ed..eed692c8 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -196,7 +196,7 @@ mio-config-PM1.yaml: generate-mio-config.sh
 	./generate-mio-config.sh 102 && mv mio-config.yaml $@
 mio-config-PM2.yaml: generate-mio-config.sh
 	./generate-mio-config.sh 103 && mv mio-config.yaml $@
-mio-config-PM2.yaml: generate-mio-config.sh
+mio-config-PM3.yaml: generate-mio-config.sh
 	./generate-mio-config.sh 104 && mv mio-config.yaml $@
 mio-config-C1.yaml: generate-mio-config.sh
 	./generate-mio-config.sh 105 && mv mio-config.yaml $@
diff --git a/tests/generate-mio-config.sh b/tests/generate-mio-config.sh
index b0fbcfc8..a20deb46 100755
--- a/tests/generate-mio-config.sh
+++ b/tests/generate-mio-config.sh
@@ -8,9 +8,18 @@ if test $# -ne 1; then
 	exit 1
 fi
 
-MERO_HA_IP=`grep 'M0_CST_HA' /etc/mero/conf.xc |sed -s 's/^.*@M0_CST_HA.* "\([^"]*\)".*$/\1/'`
-CLOVIS_IP=`grep 'M0_CST_CONFD' /etc/mero/conf.xc |sed -s 's/^.*@M0_CST_CONFD.* "\([^"]*\)".*$/\1/'|sed -s "s/\(.*\):1$/\1:$1/"`
 HOSTNAME=`hostname`
+if test -f /etc/mero/conf.xc; then
+	# fetch from file (mainly for single-host installation)
+	MERO_HA_IP=`grep 'M0_CST_HA' /etc/mero/conf.xc |sed -s 's/^.*@M0_CST_HA.* "\([^"]*\)".*$/\1/'`
+	CLOVIS_IP=`grep 'M0_CST_CONFD' /etc/mero/conf.xc |sed -s 's/^.*@M0_CST_CONFD.* "\([^"]*\)".*$/\1/'|sed -s "s/\(.*\):1$/\1:$1/"`
+else
+	# find the full address of the CST_HA service on the host we're running on
+	MERO_HA_IP=`hctl mero status | grep -2 CST_HA|grep -2 "$HOSTNAME" |head -2|tail -1|sed -e 's/^.*\[[^]]\+] [^ ]\+:[^ ]\+ \+\([^ ]\+\).*$/\1/'`
+	# find the part of the local clovis service address that we stick our mero-id onto
+	CLOVIS_IP=`hctl mero status | grep -A10 "$HOSTNAME" |grep -A1 CST_RMS|grep -v CST_RMS|head -1|sed -e 's/^.*\[[^]]\+] [^ ]\+:[^ ]\+ \+\([^ ]\+\).*$/\1/' | sed -e 's/\(.*\):[0-9]\+ $/\1:$1/'`
+endif
+
 
 cat >mio-config.yaml <<EOF
 # auto-generated MIO config file for $HOSTNAME 
-- 
GitLab