From c4941c962a803dde9193c2757d8e8878c792c515 Mon Sep 17 00:00:00 2001 From: Jamo Luhrsen Date: Wed, 17 Jan 2018 09:06:10 -0800 Subject: [PATCH] Add common-functions.sh bash lib tired of looking at duplicated code and having to remember to search for all instances of it. This can be the start of some cleanup, if others agree it's a good idea. first round: - move the Java vars setup code to a common function. - move some common vars to common location as well - added "export" to some vars to get around local tox shellcheck error Change-Id: If03949e16aae3561ac8636bc4de0b1a17dad01ae Signed-off-by: Jamo Luhrsen --- jjb/integration/common-functions.sh | 35 +++++++++++++++++++ .../integration-configure-clustering.sh | 30 ++-------------- .../integration-deploy-controller-run-test.sh | 25 ++----------- jjb/integration/integration-macros.yaml | 8 +++-- 4 files changed, 45 insertions(+), 53 deletions(-) create mode 100644 jjb/integration/common-functions.sh diff --git a/jjb/integration/common-functions.sh b/jjb/integration/common-functions.sh new file mode 100644 index 0000000000..7e3b3b648e --- /dev/null +++ b/jjb/integration/common-functions.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +# Basic controller configuration settings +export MAVENCONF=/tmp/${BUNDLEFOLDER}/etc/org.ops4j.pax.url.mvn.cfg +export FEATURESCONF=/tmp/${BUNDLEFOLDER}/etc/org.apache.karaf.features.cfg +export CUSTOMPROP=/tmp/${BUNDLEFOLDER}/etc/custom.properties +export LOGCONF=/tmp/${BUNDLEFOLDER}/etc/org.ops4j.pax.logging.cfg +export MEMCONF=/tmp/${BUNDLEFOLDER}/bin/setenv +export CONTROLLERMEM="2048m" + +# Cluster specific configuration settings +export AKKACONF=/tmp/${BUNDLEFOLDER}/configuration/initial/akka.conf +export MODULESCONF=/tmp/${BUNDLEFOLDER}/configuration/initial/modules.conf +export MODULESHARDSCONF=/tmp/${BUNDLEFOLDER}/configuration/initial/module-shards.conf + +# Setup JAVA_HOME and MAX_MEM Value in ODL startup config file +function set_java_vars() { + + echo "Configure java home and max memory..." + sed -ie 's%^# export JAVA_HOME%export JAVA_HOME="\${JAVA_HOME:-${JAVA_HOME}}"%g' ${MEMCONF} + sed -ie 's/JAVA_MAX_MEM="2048m"/JAVA_MAX_MEM="${CONTROLLERMEM}"/g' ${MEMCONF} + cat ${MEMCONF} + + echo "Set Java version" + sudo /usr/sbin/alternatives --install /usr/bin/java java ${JAVA_HOME}/bin/java 1 + sudo /usr/sbin/alternatives --set java ${JAVA_HOME}/bin/java + echo "JDK default version ..." + java -version + + echo "Set JAVA_HOME" + export JAVA_HOME="${JAVA_HOME}" + # shellcheck disable=SC2037 + JAVA_RESOLVED=\`readlink -e "\${JAVA_HOME}/bin/java"\` + echo "Java binary pointed at by JAVA_HOME: \${JAVA_RESOLVED}" +} # set_java_vars() diff --git a/jjb/integration/integration-configure-clustering.sh b/jjb/integration/integration-configure-clustering.sh index 3c679d156c..89dd8e9aa1 100644 --- a/jjb/integration/integration-configure-clustering.sh +++ b/jjb/integration/integration-configure-clustering.sh @@ -9,20 +9,9 @@ echo "#################################################" echo "## Configure Cluster and Start ##" echo "#################################################" -AKKACONF=/tmp/${BUNDLEFOLDER}/configuration/initial/akka.conf -MODULESCONF=/tmp/${BUNDLEFOLDER}/configuration/initial/modules.conf -MODULESHARDSCONF=/tmp/${BUNDLEFOLDER}/configuration/initial/module-shards.conf -MAVENCONF=/tmp/${BUNDLEFOLDER}/etc/org.ops4j.pax.url.mvn.cfg -FEATURESCONF=/tmp/${BUNDLEFOLDER}/etc/org.apache.karaf.features.cfg -CUSTOMPROP=/tmp/${BUNDLEFOLDER}/etc/custom.properties -LOGCONF=/tmp/${BUNDLEFOLDER}/etc/org.ops4j.pax.logging.cfg -MEMCONF=/tmp/${BUNDLEFOLDER}/bin/setenv -CONTROLLERMEM="2048m" - - if [ ${CONTROLLERSCOPE} == 'all' ]; then ACTUALFEATURES="odl-integration-compatible-with-all,${CONTROLLERFEATURES}" - CONTROLLERMEM="3072m" + export CONTROLLERMEM="3072m" else ACTUALFEATURES="odl-infrautils-ready,${CONTROLLERFEATURES}" fi @@ -110,22 +99,7 @@ if [ "${ODL_ENABLE_L3_FWD}" == "yes" ]; then cat ${CUSTOMPROP} fi -echo "Configure java home and max memory..." -sed -ie 's%^# export JAVA_HOME%export JAVA_HOME="\${JAVA_HOME:-${JAVA_HOME}}"%g' ${MEMCONF} -sed -ie 's/JAVA_MAX_MEM="2048m"/JAVA_MAX_MEM="${CONTROLLERMEM}"/g' ${MEMCONF} -cat ${MEMCONF} - -echo "Set Java version" -sudo /usr/sbin/alternatives --install /usr/bin/java java ${JAVA_HOME}/bin/java 1 -sudo /usr/sbin/alternatives --set java ${JAVA_HOME}/bin/java -echo "JDK default version ..." -java -version - -echo "Set JAVA_HOME" -export JAVA_HOME="${JAVA_HOME}" -# Did you know that in HERE documents, single quote is an ordinary character, but backticks are still executing? -JAVA_RESOLVED=\`readlink -e "\${JAVA_HOME}/bin/java"\` -echo "Java binary pointed at by JAVA_HOME: \${JAVA_RESOLVED}" +set_java_vars # Copy shard file if exists if [ -f /tmp/custom_shard_config.txt ]; then diff --git a/jjb/integration/integration-deploy-controller-run-test.sh b/jjb/integration/integration-deploy-controller-run-test.sh index a81b9aec44..b56e4958af 100644 --- a/jjb/integration/integration-deploy-controller-run-test.sh +++ b/jjb/integration/integration-deploy-controller-run-test.sh @@ -5,12 +5,6 @@ # shellcheck source=${ROBOT_VENV}/bin/activate disable=SC1091 source ${ROBOT_VENV}/bin/activate -MAVENCONF=/tmp/${BUNDLEFOLDER}/etc/org.ops4j.pax.url.mvn.cfg -FEATURESCONF=/tmp/${BUNDLEFOLDER}/etc/org.apache.karaf.features.cfg -CUSTOMPROP=/tmp/${BUNDLEFOLDER}/etc/custom.properties -LOGCONF=/tmp/${BUNDLEFOLDER}/etc/org.ops4j.pax.logging.cfg -MEMCONF=/tmp/${BUNDLEFOLDER}/bin/setenv -CONTROLLERMEM="2048m" if [ "${ENABLE_HAPROXY_FOR_NEUTRON}" == "yes" ]; then echo "Configure cluster" @@ -21,7 +15,7 @@ fi if [ ${CONTROLLERSCOPE} == 'all' ]; then ACTUALFEATURES="odl-integration-compatible-with-all,${CONTROLLERFEATURES}" - CONTROLLERMEM="3072m" + export CONTROLLERMEM="3072m" COOLDOWN_PERIOD="180" else ACTUALFEATURES="odl-infrautils-ready,${CONTROLLERFEATURES}" @@ -106,26 +100,11 @@ if [ -n "${CONTROLLERDEBUGMAP}" ]; then fi cat ${LOGCONF} -echo "Configure java home and max memory..." -sed -ie 's%^# export JAVA_HOME%export JAVA_HOME="\${JAVA_HOME:-${JAVA_HOME}}"%g' ${MEMCONF} -sed -ie 's/JAVA_MAX_MEM="2048m"/JAVA_MAX_MEM="${CONTROLLERMEM}"/g' ${MEMCONF} -cat ${MEMCONF} +set_java_vars echo "Listing all open ports on controller system..." netstat -pnatu -echo "Set Java version" -sudo /usr/sbin/alternatives --install /usr/bin/java java ${JAVA_HOME}/bin/java 1 -sudo /usr/sbin/alternatives --set java ${JAVA_HOME}/bin/java -echo "JDK default version..." -java -version - -echo "Set JAVA_HOME" -export JAVA_HOME="${JAVA_HOME}" -# Did you know that in HERE documents, single quote is an ordinary character, but backticks are still executing? -JAVA_RESOLVED=\`readlink -e "\${JAVA_HOME}/bin/java"\` -echo "Java binary pointed at by JAVA_HOME: \${JAVA_RESOLVED}" - if [ "${ENABLE_HAPROXY_FOR_NEUTRON}" == "yes" ]; then # Copy shard file if exists diff --git a/jjb/integration/integration-macros.yaml b/jjb/integration/integration-macros.yaml index 7fa75f3c22..4e2ccf0de9 100644 --- a/jjb/integration/integration-macros.yaml +++ b/jjb/integration/integration-macros.yaml @@ -374,7 +374,9 @@ - builder: name: integration-deploy-controller-run-test builders: - - shell: !include-raw: integration-deploy-controller-run-test.sh + - shell: !include-raw: + - common-functions.sh + - integration-deploy-controller-run-test.sh # Macro: integration-configure-clustering # Operation: this macro configures the clustering @@ -383,7 +385,9 @@ - builder: name: integration-configure-clustering builders: - - shell: !include-raw: integration-configure-clustering.sh + - shell: !include-raw: + - common-functions.sh + - integration-configure-clustering.sh # Macro: integration-start-cluster-run-test # Operation: this macro starts the 3-node cluster and runs test -- 2.36.6