Allow for multiple forbidden paths
[releng/builder.git] / jjb / integration / common-functions.sh
index 143b830fefe258430e3d768e9124f06c2123a302..801aa9c84ce44c7de20d713c4e62e4bd876a6fdc 100644 (file)
@@ -10,7 +10,7 @@ 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"
+export CONTROLLERMEM=${CONTROLLERMAXMEM}
 
 # Cluster specific configuration settings
 export AKKACONF=/tmp/${BUNDLEFOLDER}/configuration/initial/akka.conf
@@ -83,10 +83,8 @@ function configure_karaf_log() {
     echo "Configuring the karaf log... karaf_version: ${karaf_version}, logapi: ${logapi}"
     if [ "${logapi}" == "log4j2" ]; then
         # FIXME: Make log size limit configurable from build parameter.
-        # From Neon the default karaf file size is 64 MB
+        # Increase default log file size to 1GB
         sed -ie 's/log4j2.appender.rolling.policies.size.size = 64MB/log4j2.appender.rolling.policies.size.size = 1GB/g' "${LOGCONF}"
-        # Flourine still uses 16 MB
-        sed -ie 's/log4j2.appender.rolling.policies.size.size = 16MB/log4j2.appender.rolling.policies.size.size = 1GB/g' "${LOGCONF}"
         orgmodule="org.opendaylight.yangtools.yang.parser.repo.YangTextSchemaContextResolver"
         orgmodule_="${orgmodule//./_}"
         echo "${logapi}.logger.${orgmodule_}.name = WARN" >> "${LOGCONF}"
@@ -223,9 +221,10 @@ function get_test_suites() {
         testplan_filepath="${WORKSPACE}/test/csit/testplans/${TESTPLAN}"
     fi
 
-    add_test="integration/test/csit/suites/integration/Create_JVM_Plots.robot" # we should always add for preparing JVM monitoring
-    echo >> "$testplan_filepath"
-    echo "${add_test}" >> "$testplan_filepath"
+    if [ "${ELASTICSEARCHATTRIBUTE}" != "disabled" ]; then
+        add_test="integration/test/csit/suites/integration/Create_JVM_Plots.robot"
+        echo "${add_test}" >> "$testplan_filepath"
+    fi
 
     echo "Changing the testplan path..."
     sed "s:integration:${WORKSPACE}:" "${testplan_filepath}" > testplan.txt
@@ -289,22 +288,122 @@ function run_plan() {
 # Run scripts to support JVM monitoring.
 function add_jvm_support()
 {
-    # TODO unite short and long version to one script and parametrize the input: short/long/any number
-    if [ "${ELASTICSEARCHATTRIBUTE}" == "short" ]; then
-        run_script="${WORKSPACE}/test/csit/scripts/set_elasticsearch_attribute_short.sh"
-    else
-        run_script="${WORKSPACE}/test/csit/scripts/set_elasticsearch_attribute_long.sh"
+    if [ "${ELASTICSEARCHATTRIBUTE}" != "disabled" ]; then
+        set_elasticsearch_attribute "${ELASTICSEARCHATTRIBUTE}"
+        set_jvm_common_attribute
     fi
-    printf "Executing %s...\\n" "${run_script}"
-    # shellcheck source=${line} disable=SC1091
-    source "${run_script}"
-
-    run_script="${WORKSPACE}/test/csit/scripts/set_jvm_common_attribute.sh"
-    printf "Executing %s...\\n" "${run_script}"
-    # shellcheck source=${line} disable=SC1091
-    source "${run_script}"
 } # function add_jvm_support()
 
+#Expected input parameter: long/short/a number
+function set_elasticsearch_attribute()
+{
+short=5000
+long=120000
+default=$short
+
+case $1 in
+short)
+  period=$short
+  ;;
+long)
+  period=$long
+  ;;
+*)
+  # shellcheck disable=SC2166
+  if [[ "$1" =~ ^[0-9]+$ ]] && [ "$1" -ge $short -a "$1" -le $long ]; then
+      period=$1
+  else
+      period=$default
+  fi
+  ;;
+esac
+
+cat > "${WORKSPACE}"/org.apache.karaf.decanter.scheduler.simple.cfg <<EOF
+period=$period
+
+EOF
+
+echo "Copying config files to ODL Controller folder"
+
+# shellcheck disable=SC2086
+for i in $(seq 1 ${NUM_ODL_SYSTEM})
+do
+        CONTROLLERIP=ODL_SYSTEM_${i}_IP
+        echo "Set Decanter Polling Period to ${!CONTROLLERIP}"
+        # shellcheck disable=SC2029
+        ssh "${!CONTROLLERIP}" "mkdir -p \"/tmp/${BUNDLEFOLDER}/etc/opendaylight/karaf/\""
+        scp "${WORKSPACE}"/org.apache.karaf.decanter.scheduler.simple.cfg "${!CONTROLLERIP}":/tmp/"${BUNDLEFOLDER}"/etc/
+done
+} #function set_elasticsearch_attribute
+
+function set_jvm_common_attribute()
+{
+cat > "${WORKSPACE}"/org.apache.karaf.decanter.collector.jmx-local.cfg <<EOF
+type=jmx-local
+url=local
+object.name=java.lang:type=*,name=*
+
+EOF
+
+cat > "${WORKSPACE}"/org.apache.karaf.decanter.collector.jmx-others.cfg <<EOF
+type=jmx-local
+url=local
+object.name=java.lang:type=*
+
+EOF
+
+# shellcheck disable=SC2086
+for i in $(seq 1 ${NUM_ODL_SYSTEM})
+do
+    CONTROLLERIP=ODL_SYSTEM_${i}_IP
+
+    cat > "${WORKSPACE}"/elasticsearch.yml <<EOF
+    discovery.zen.ping.multicast.enabled: false
+
+EOF
+
+    cat > "${WORKSPACE}"/elasticsearch_startup.sh <<EOF
+    cd /tmp/elasticsearch/elasticsearch-1.7.5
+    ls -al
+
+    if [ -d "data" ]; then
+        echo "data directory exists, deleting...."
+        rm -r data
+    else
+        echo "data directory does not exist"
+    fi
+
+    cd /tmp/elasticsearch
+    ls -al
+
+    echo "Starting Elasticsearch node"
+    sudo /tmp/elasticsearch/elasticsearch-1.7.5/bin/elasticsearch > /dev/null 2>&1 &
+    ls -al /tmp/elasticsearch/elasticsearch-1.7.5/bin/elasticsearch
+
+EOF
+    echo "Setup ODL_SYSTEM_IP specific config files for ${!CONTROLLERIP} "
+    cat "${WORKSPACE}"/org.apache.karaf.decanter.collector.jmx-local.cfg
+    cat "${WORKSPACE}"/org.apache.karaf.decanter.collector.jmx-others.cfg
+    cat "${WORKSPACE}"/elasticsearch.yml
+
+
+    echo "Copying config files to ${!CONTROLLERIP}"
+    scp "${WORKSPACE}"/org.apache.karaf.decanter.collector.jmx-local.cfg "${!CONTROLLERIP}":/tmp/"${BUNDLEFOLDER}"/etc/
+    scp "${WORKSPACE}"/org.apache.karaf.decanter.collector.jmx-others.cfg "${!CONTROLLERIP}":/tmp/"${BUNDLEFOLDER}"/etc/
+    scp "${WORKSPACE}"/elasticsearch.yml "${!CONTROLLERIP}":/tmp/
+
+    ssh "${!CONTROLLERIP}" "sudo ls -al /tmp/elasticsearch/"
+    ssh "${!CONTROLLERIP}" "sudo mv /tmp/elasticsearch.yml /tmp/elasticsearch/elasticsearch-1.7.5/config/"
+    ssh "${!CONTROLLERIP}" "cat /tmp/elasticsearch/elasticsearch-1.7.5/config/elasticsearch.yml"
+
+    echo "Copying the elasticsearch_startup script to ${!CONTROLLERIP}"
+    cat "${WORKSPACE}"/elasticsearch_startup.sh
+    scp "${WORKSPACE}"/elasticsearch_startup.sh "${!CONTROLLERIP}":/tmp
+    ssh "${!CONTROLLERIP}" 'bash /tmp/elasticsearch_startup.sh'
+    ssh "${!CONTROLLERIP}" 'ps aux | grep elasticsearch'
+done
+} #function set_jvm_common_attribute
+
 # Return elapsed time. Usage:
 # - Call first time with no arguments and a new timer is returned.
 # - Next call with the first argument as the timer and the elapsed time is returned.
@@ -363,6 +462,7 @@ DISTROSTREAM: ${DISTROSTREAM}
 BUNDLE_URL: ${BUNDLE_URL}
 CONTROLLERFEATURES: ${CONTROLLERFEATURES}
 CONTROLLERDEBUGMAP: ${CONTROLLERDEBUGMAP}
+CONTROLLERMAXMEM: ${CONTROLLERMAXMEM}
 SCRIPTPLAN: ${SCRIPTPLAN}
 CONFIGPLAN: ${CONFIGPLAN}
 STREAMTESTPLAN: ${STREAMTESTPLAN}
@@ -395,6 +495,7 @@ CREATE_INITIAL_NETWORKS: ${CREATE_INITIAL_NETWORKS}
 LBAAS_SERVICE_PROVIDER: ${LBAAS_SERVICE_PROVIDER}
 ODL_SFC_DRIVER: ${ODL_SFC_DRIVER}
 ODL_SNAT_MODE: ${ODL_SNAT_MODE}
+GROUP_ADD_MOD_ENABLED: ${GROUP_ADD_MOD_ENABLED}
 
 EOF
 }
@@ -570,7 +671,7 @@ EOF
         echo "collect_logs: for opendaylight controller ip: ${!CONTROLLERIP}"
         NODE_FOLDER="odl_${i}"
         mkdir -p "${NODE_FOLDER}"
-        echo "Lets's take the karaf thread dump again..."
+        echo "Let's take the karaf thread dump again..."
         ssh "${!CONTROLLERIP}" "sudo ps aux" > "${WORKSPACE}"/ps_after.log
         pid=$(grep org.apache.karaf.main.Main "${WORKSPACE}"/ps_after.log | grep -v grep | tr -s ' ' | cut -f2 -d' ')
         echo "karaf main: org.apache.karaf.main.Main, pid:${pid}"
@@ -755,14 +856,25 @@ function get_nodes_list() {
 
 function get_features() {
     if [ "${CONTROLLERSCOPE}" == 'all' ]; then
-        ACTUALFEATURES="odl-integration-compatible-with-all,${CONTROLLERFEATURES}"
-        export CONTROLLERMEM="3072m"
+        if [ "$KARAF_PROJECT" == "integration" ]; then
+            ACTUALFEATURES="odl-integration-compatible-with-all,${CONTROLLERFEATURES}"
+        else
+            ACTUALFEATURES="odl-infrautils-ready,${CONTROLLERFEATURES}"
+        fi
+        # if CONTROLLERMEM still is the default 2G and was not overridden by a
+        # custom job, then we need to make sure to increase it because "all"
+        # features can be heavy
+        if [ "${CONTROLLERMEM}" == "2048m" ]; then
+            export CONTROLLERMEM="3072m"
+        fi
     else
         ACTUALFEATURES="odl-infrautils-ready,${CONTROLLERFEATURES}"
     fi
 
-    # Add decanter features to allow JVM monitoring
-    ACTUALFEATURES="${ACTUALFEATURES},decanter-collector-jmx,decanter-appender-elasticsearch"
+    if [ "${ELASTICSEARCHATTRIBUTE}" != "disabled" ]; then
+        # Add decanter features to allow JVM monitoring
+        ACTUALFEATURES="${ACTUALFEATURES},decanter-collector-jmx,decanter-appender-elasticsearch-rest"
+    fi
 
     # Some versions of jenkins job builder result in feature list containing spaces
     # and ending in newline. Remove all that.
@@ -802,15 +914,19 @@ if [[ "$USEFEATURESBOOT" == "True" ]]; then
     sed -ie "s/\\(featuresBoot=\\|featuresBoot =\\)/featuresBoot = ${ACTUALFEATURES},/g" ${FEATURESCONF}
 fi
 
-FEATURE_TEST_STRING="features-integration-test"
-KARAF_VERSION=${KARAF_VERSION:-karaf4}
-if [[ "$KARAF_VERSION" == "karaf4" ]]; then
-    FEATURE_TEST_STRING="features-test"
+FEATURE_TEST_STRING="features-test"
+FEATURE_TEST_VERSION="$BUNDLE_VERSION"
+if [[ "$KARAF_ARTIFACT" == "opendaylight" ]]; then
+    FEATURE_TEST_VERSION="$(sed -r "s%^([0-9]+)\.([0-9]+)\.0(.*)%0.\1.\2\3%" <<<"$BUNDLE_VERSION")"
 fi
+KARAF_VERSION=${KARAF_VERSION:-karaf4}
 
-sed -ie "s%\\(featuresRepositories=\\|featuresRepositories =\\)%featuresRepositories = mvn:org.opendaylight.integration/\${FEATURE_TEST_STRING}/${BUNDLE_VERSION}/xml/features,mvn:org.apache.karaf.decanter/apache-karaf-decanter/1.0.0/xml/features,%g" ${FEATURESCONF}
-if [[ ! -z "${REPO_URL}" ]]; then
-   sed -ie "s%featuresRepositories =%featuresRepositories = ${REPO_URL},%g" ${FEATURESCONF}
+# only manipulate feature repo in integration distro
+if [[ "$KARAF_PROJECT" == "integration" ]]; then
+       sed -ie "s%\\(featuresRepositories=\\|featuresRepositories =\\)%featuresRepositories = mvn:org.opendaylight.integration/\${FEATURE_TEST_STRING}/\${FEATURE_TEST_VERSION}/xml/features,mvn:org.apache.karaf.decanter/apache-karaf-decanter/1.2.0/xml/features,%g" ${FEATURESCONF}
+       if [[ ! -z "${REPO_URL}" ]]; then
+          sed -ie "s%featuresRepositories =%featuresRepositories = ${REPO_URL},%g" ${FEATURESCONF}
+       fi
 fi
 cat ${FEATURESCONF}
 
@@ -861,19 +977,21 @@ function create_post_startup_script() {
 # wait up to 60s for karaf port 8101 to be opened, polling every 5s
 loop_count=0;
 until [[ \$loop_count -ge 12 ]]; do
-    netstat -na | grep 8101 && break;
+    netstat -na | grep ":::8101" && break;
     loop_count=\$[\$loop_count+1];
     sleep 5;
 done
 
 # This workaround is required for Karaf decanter to work proper
 # The bundle:refresh command does not fail if the decanter bundles are not present
-echo "ssh to karaf console to do bundle refresh of decanter jmx collector"
-sshpass -p karaf ssh -o StrictHostKeyChecking=no \
-                     -o UserKnownHostsFile=/dev/null \
-                     -o LogLevel=error \
-                     -p 8101 karaf@localhost \
-                     "bundle:refresh org.apache.karaf.decanter.collector.jmx && bundle:refresh org.apache.karaf.decanter.appender.elasticsearch"
+# There seems to be impact in silicon stream so we better comment the lines below
+#
+#echo "ssh to karaf console to do bundle refresh of decanter jmx collector"
+#sshpass -p karaf ssh -o StrictHostKeyChecking=no \
+#                     -o UserKnownHostsFile=/dev/null \
+#                     -o LogLevel=error \
+#                     -p 8101 karaf@localhost \
+#                     "bundle:refresh org.apache.karaf.decanter.collector.jmx && bundle:refresh org.apache.karaf.decanter.api"
 
 if [[ "$USEFEATURESBOOT" != "True" ]]; then
 
@@ -906,7 +1024,7 @@ done;
 
 # if we ended up not finding ready status in the above loop, we can output some debugs
 grep 'org.opendaylight.infrautils.*System ready' /tmp/${BUNDLEFOLDER}/data/log/karaf.log
-if [ $? -ne 0 ]; then
+if [ \$? -ne 0 ]; then
     echo "Timeout Controller DOWN"
     echo "Dumping first 500K bytes of karaf log..."
     head --bytes=500K "/tmp/${BUNDLEFOLDER}/data/log/karaf.log"
@@ -979,7 +1097,7 @@ function copy_and_run_post_startup_script() {
 function dump_controller_threads() {
     for i in $(seq 1 "${NUM_ODL_SYSTEM}"); do
         CONTROLLERIP="ODL_SYSTEM_${i}_IP"
-        echo "Lets's take the karaf thread dump"
+        echo "Let's take the karaf thread dump"
         ssh "${!CONTROLLERIP}" "sudo ps aux" > "${WORKSPACE}"/ps_before.log
         pid=$(grep org.apache.karaf.main.Main "${WORKSPACE}"/ps_before.log | grep -v grep | tr -s ' ' | cut -f2 -d' ')
         echo "karaf main: org.apache.karaf.main.Main, pid:${pid}"
@@ -1136,5 +1254,3 @@ function install_ovs_from_path() {
     ${SSH} "${ip}" "sudo yum -y install createrepo && createrepo --database /tmp/ovs_rpms"
     install_ovs_from_repo "${ip}" file:/tmp/ovs_rpms
 }
-
-