Fix SC2086 for lines 940 until EOF
[releng/builder.git] / jjb / integration / common-functions.sh
index bae69e425b164cce3fdd82ebf1cfd1403302c927..c3fdb54a800c99ed8f358dd5fbf1c8ff07a3fa77 100644 (file)
@@ -21,6 +21,7 @@ function print_common_env() {
     cat << EOF
 common-functions environment:
 MAVENCONF: ${MAVENCONF}
+ACTUALFEATURES: ${ACTUALFEATURES}
 FEATURESCONF: ${FEATURESCONF}
 CUSTOMPROP: ${CUSTOMPROP}
 LOGCONF: ${LOGCONF}
@@ -29,6 +30,7 @@ CONTROLLERMEM: ${CONTROLLERMEM}
 AKKACONF: ${AKKACONF}
 MODULESCONF: ${MODULESCONF}
 MODULESHARDSCONF: ${MODULESHARDSCONF}
+SUITES: ${SUITES}
 
 EOF
 }
@@ -77,6 +79,9 @@ 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
+        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//./_}"
@@ -90,8 +95,9 @@ function configure_karaf_log() {
     fi
 
     # Add custom logging levels
-    # CONTROLLERDEBUGMAP is expected to be a key:value map of space separated values like "module:level module2:level2"
-    # where module is abbreviated and does not include "org.opendaylight."
+    # CONTROLLERDEBUGMAP is expected to be a key:value map of space separated
+    # values like "module:level module2:level2" where module is abbreviated and
+    # does not include "org.opendaylight."
     unset IFS
     echo "controllerdebugmap: ${controllerdebugmap}"
     if [ -n "${controllerdebugmap}" ]; then
@@ -117,6 +123,73 @@ function configure_karaf_log() {
     cat ${LOGCONF}
 } # function configure_karaf_log()
 
+function configure_karaf_log_for_apex() {
+    # TODO: add the extra steps to this function to do any extra work
+    # in this apex environment like we do in our standard environment.
+    # EX: log size, rollover, etc.
+
+    # Modify ODL Log Levels, if needed, for new distribution. This will modify
+    # the control nodes hiera data which will be used during the puppet deploy
+    # CONTROLLERDEBUGMAP is expected to be a key:value map of space separated
+    # values like "module:level module2:level2" where module is abbreviated and
+    # does not include "org.opendaylight."
+
+    local -r controller_ip=$1
+
+    unset IFS
+    # shellcheck disable=SC2153
+    echo "CONTROLLERDEBUGMAP: ${CONTROLLERDEBUGMAP}"
+    if [ -n "${CONTROLLERDEBUGMAP}" ]; then
+        logging_config='\"opendaylight::log_levels\": {'
+        for kv in ${CONTROLLERDEBUGMAP}; do
+            module="${kv%%:*}"
+            level="${kv#*:}"
+            echo "module: $module, level: $level"
+            # shellcheck disable=SC2157
+            if [ -n "${module}" ] && [ -n "${level}" ]; then
+                orgmodule="org.opendaylight.${module}"
+                logging_config="${logging_config} \\\"${orgmodule}\\\": \\\"${level}\\\","
+            fi
+        done
+        # replace the trailing comma with a closing brace followed by trailing comma
+        logging_config=${logging_config%,}" },"
+        echo $logging_config
+
+        # fine a sane line number to inject the custom logging json
+        lineno=$(ssh $OPENSTACK_CONTROL_NODE_1_IP "sudo grep -Fn 'opendaylight::log_mechanism' /etc/puppet/hieradata/service_configs.json" | awk -F: '{print $1}')
+        ssh $controller_ip "sudo sed -i \"${lineno}i ${logging_config}\" /etc/puppet/hieradata/service_configs.json"
+        ssh $controller_ip "sudo cat /etc/puppet/hieradata/service_configs.json"
+    fi
+} # function configure_karaf_log_for_apex()
+
+function configure_odl_features_for_apex() {
+
+    # if the environment variable $ACTUALFEATURES is not null, then rewrite
+    # the puppet config file with the features given in that variable, otherwise
+    # this function is a noop
+
+    local -r controller_ip=$1
+    local -r config_file=/etc/puppet/hieradata/service_configs.json
+
+cat > /tmp/set_odl_features.sh << EOF
+sudo jq '.["opendaylight::extra_features"] |= []' $config_file > tmp.json && mv tmp.json $config_file
+for feature in $(echo $ACTUALFEATURES | sed "s/,/ /g"); do
+    sudo jq --arg jq_arg \$feature '.["opendaylight::extra_features"] |= . + [\$jq_arg]' $config_file > tmp && mv tmp $config_file;
+done
+echo "Modified puppet-opendaylight service_configs.json..."
+cat $config_file
+EOF
+
+    echo "Feature configuration script..."
+    cat /tmp/set_odl_features.sh
+
+    if [ -n "${ACTUALFEATURES}" ]; then
+        scp /tmp/set_odl_features.sh $controller_ip:/tmp/set_odl_features.sh
+        ssh $controller_ip "sudo bash /tmp/set_odl_features.sh"
+    fi
+
+} # function configure_odl_features_for_apex()
+
 function get_os_deploy() {
     local -r num_systems=${1:-$NUM_OPENSTACK_SYSTEM}
     case ${num_systems} in
@@ -150,7 +223,7 @@ function get_test_suites() {
 
     # Use the testplan if specific SUITES are not defined.
     if [ -z "${SUITES}" ]; then
-        suite_list=`egrep -v '(^[[:space:]]*#|^[[:space:]]*$)' testplan.txt | tr '\012' ' '`
+        suite_list=$(egrep -v '(^[[:space:]]*#|^[[:space:]]*$)' testplan.txt | tr '\012' ' ')
     else
         suite_list=""
         workpath="${WORKSPACE}/test/csit/suites"
@@ -179,7 +252,7 @@ function run_plan() {
         ;;
     esac
 
-    printf "Locating ${type} plan to use...\n"
+    printf "Locating %s plan to use...\n" "${type}"
     plan_filepath="${WORKSPACE}/test/csit/${type}plans/$plan"
     if [ ! -f "${plan_filepath}" ]; then
         plan_filepath="${WORKSPACE}/test/csit/${type}plans/${STREAMTESTPLAN}"
@@ -189,17 +262,17 @@ function run_plan() {
     fi
 
     if [ -f "${plan_filepath}" ]; then
-        printf "${type} plan exists!!!\n"
-        printf "Changing the ${type} plan path...\n"
+        printf "%s plan exists!!!\n" "${type}"
+        printf "Changing the %s plan path...\n" "${type}"
         cat ${plan_filepath} | sed "s:integration:${WORKSPACE}:" > ${type}plan.txt
         cat ${type}plan.txt
         for line in $( egrep -v '(^[[:space:]]*#|^[[:space:]]*$)' ${type}plan.txt ); do
-            printf "Executing ${line}...\n"
+            printf "Executing %s...\n" "${line}"
             # shellcheck source=${line} disable=SC1091
             source ${line}
         done
     fi
-    printf "Finished running ${type} plans\n"
+    printf "Finished running %s plans\n" "${type}"
 } # function run_plan()
 
 # Return elapsed time. Usage:
@@ -209,7 +282,7 @@ function timer()
 {
     if [ $# -eq 0 ]; then
         # return the current time
-        printf "$(date "+%s")"
+        printf "%s" "$(date "+%s")"
     else
         local start_time=$1
         end_time=$(date "+%s")
@@ -302,7 +375,7 @@ function tcpdump_start() {
     local -r filter=$3
     filter_=${filter// /_}
 
-    printf "node ${ip}, ${prefix}_${ip}__${filter}: starting tcpdump\n"
+    printf "node %s, %s_%s__%s: starting tcpdump\n" "${ip}" "${prefix}" "${ip}" "${filter}"
     ssh ${ip} "nohup sudo /usr/sbin/tcpdump -vvv -ni eth0 ${filter} -w /tmp/tcpdump_${prefix}_${ip}__${filter_}.pcap > /tmp/tcpdump_start.log 2>&1 &"
     ${SSH} ${ip} "ps -ef | grep tcpdump"
 }
@@ -310,7 +383,7 @@ function tcpdump_start() {
 function tcpdump_stop() {
     local -r ip=$1
 
-    printf "node $ip: stopping tcpdump\n"
+    printf "node %s: stopping tcpdump\n" "$ip"
     ${SSH} ${ip} "ps -ef | grep tcpdump.sh"
     ${SSH} ${ip} "sudo pkill -f tcpdump"
     ${SSH} ${ip} "sudo xz -9ekvvf /tmp/*.pcap"
@@ -366,7 +439,7 @@ function collect_openstack_logs() {
     local -r node_type=${3}
     local oslogs="${folder}/oslogs"
 
-    printf "collect_openstack_logs for ${node_type} node: ${ip} into ${oslogs}\n"
+    printf "collect_openstack_logs for %s node: %s into %s\n" "${node_type}" "${ip}" "${oslogs}"
     rm -rf ${oslogs}
     mkdir -p ${oslogs}
     # There are always some logs in /opt/stack/logs and this also covers the
@@ -406,7 +479,7 @@ fi
 ls -al /tmp/oslogs
 EOF
 # cat > ${WORKSPACE}/collect_openstack_logs.sh << EOF
-        printf "collect_openstack_logs for ${node_type} node: ${ip} into ${oslogs}, executing script\n"
+        printf "collect_openstack_logs for %s node: %s into %s, executing script\n" "${node_type}" "${ip}" "${oslogs}"
         cat ${WORKSPACE}/collect_openstack_logs.sh
         scp ${WORKSPACE}/collect_openstack_logs.sh ${ip}:/tmp
         ${SSH} ${ip} "bash /tmp/collect_openstack_logs.sh > /tmp/collect_openstack_logs.log 2>&1"
@@ -460,7 +533,7 @@ EOF
 
     sleep 5
     # FIXME: Do not create .tar and gzip before copying.
-    for i in `seq 1 ${NUM_ODL_SYSTEM}`; do
+    for i in $(seq 1 "${NUM_ODL_SYSTEM}"); do
         CONTROLLERIP=ODL_SYSTEM_${i}_IP
         echo "collect_logs: for opendaylight controller ip: ${!CONTROLLERIP}"
         NODE_FOLDER="odl_${i}"
@@ -499,7 +572,7 @@ EOF
     print_job_parameters > ${WORKSPACE}/archives/params.txt
 
     # Control Node
-    for i in `seq 1 ${NUM_OPENSTACK_CONTROL_NODES}`; do
+    for i in $(seq 1 "${NUM_OPENSTACK_CONTROL_NODES}"); do
         OSIP=OPENSTACK_CONTROL_NODE_${i}_IP
         if [ "$(is_openstack_feature_enabled n-cpu)" == "1" ]; then
             echo "collect_logs: for openstack combo node ip: ${!OSIP}"
@@ -569,7 +642,7 @@ EOF
     done
 
     # Compute Nodes
-    for i in `seq 1 ${NUM_OPENSTACK_COMPUTE_NODES}`; do
+    for i in $(seq 1 "${NUM_OPENSTACK_COMPUTE_NODES}"); do
         OSIP=OPENSTACK_COMPUTE_NODE_${i}_IP
         echo "collect_logs: for openstack compute node ip: ${!OSIP}"
         NODE_FOLDER="compute_${i}"
@@ -636,7 +709,7 @@ function join() {
 
 function get_nodes_list() {
     # Create the string for nodes
-    for i in `seq 1 ${NUM_ODL_SYSTEM}` ; do
+    for i in $(seq 1 "${NUM_ODL_SYSTEM}") ; do
         CONTROLLERIP=ODL_SYSTEM_${i}_IP
         nodes[$i]=${!CONTROLLERIP}
     done
@@ -655,7 +728,7 @@ function get_features() {
 
     # Some versions of jenkins job builder result in feature list containing spaces
     # and ending in newline. Remove all that.
-    ACTUALFEATURES=`echo "${ACTUALFEATURES}" | tr -d '\n \r'`
+    ACTUALFEATURES=$(echo "${ACTUALFEATURES}" | tr -d '\n \r')
     echo "ACTUALFEATURES: ${ACTUALFEATURES}"
 
     # In the case that we want to install features via karaf shell, a space separated list of
@@ -821,7 +894,7 @@ EOF
 # Copy over the configuration script and configuration files to each controller
 # Execute the configuration script on each controller.
 function copy_and_run_configuration_script() {
-    for i in `seq 1 ${NUM_ODL_SYSTEM}`; do
+    for i in $(seq 1 "${NUM_ODL_SYSTEM}"); do
         CONTROLLERIP=ODL_SYSTEM_${i}_IP
         echo "Configuring member-${i} with IP address ${!CONTROLLERIP}"
         scp ${WORKSPACE}/configuration-script.sh ${!CONTROLLERIP}:/tmp/
@@ -831,7 +904,7 @@ function copy_and_run_configuration_script() {
 
 # Copy over the startup script to each controller and execute it.
 function copy_and_run_startup_script() {
-    for i in `seq 1 ${NUM_ODL_SYSTEM}`; do
+    for i in $(seq 1 "${NUM_ODL_SYSTEM}"); do
         CONTROLLERIP=ODL_SYSTEM_${i}_IP
         echo "Starting member-${i} with IP address ${!CONTROLLERIP}"
         scp ${WORKSPACE}/startup-script.sh ${!CONTROLLERIP}:/tmp/
@@ -841,12 +914,12 @@ function copy_and_run_startup_script() {
 
 function copy_and_run_post_startup_script() {
     seed_index=1
-    for i in `seq 1 ${NUM_ODL_SYSTEM}`; do
+    for i in $(seq 1 "${NUM_ODL_SYSTEM}"); do
         CONTROLLERIP=ODL_SYSTEM_${i}_IP
         echo "Execute the post startup script on controller ${!CONTROLLERIP}"
         scp ${WORKSPACE}/post-startup-script.sh ${!CONTROLLERIP}:/tmp
         ssh ${!CONTROLLERIP} "bash /tmp/post-startup-script.sh $(( seed_index++ ))"
-        if [ $(( $i % ${NUM_ODL_SYSTEM} )) == 0 ]; then
+        if [ $(( i % NUM_ODL_SYSTEM )) == 0 ]; then
             seed_index=1
         fi
     done
@@ -854,7 +927,7 @@ function copy_and_run_post_startup_script() {
 
 function create_controller_variables() {
     echo "Generating controller variables..."
-    for i in `seq 1 ${NUM_ODL_SYSTEM}`; do
+    for i in $(seq 1 "${NUM_ODL_SYSTEM}"); do
         CONTROLLERIP=ODL_SYSTEM_${i}_IP
         odl_variables=${odl_variables}" -v ${CONTROLLERIP}:${!CONTROLLERIP}"
         echo "Lets's take the karaf thread dump"
@@ -872,7 +945,7 @@ function build_ovs() {
     local -r rpm_path="$3"
 
     echo "Building OVS ${version} on ${ip} ..."
-    cat > ${WORKSPACE}/build_ovs.sh << EOF
+    cat > "${WORKSPACE}"/build_ovs.sh << EOF
 set -ex -o pipefail
 
 echo '---> Building openvswitch version ${version}'
@@ -927,10 +1000,10 @@ popd
 rm -rf \${TMP}
 EOF
 
-    scp ${WORKSPACE}/build_ovs.sh ${ip}:/tmp
-    ${SSH} ${ip} " bash /tmp/build_ovs.sh >> /tmp/install_ovs.txt 2>&1"
-    scp -r ${ip}:/tmp/ovs_rpms/* "${rpm_path}/"
-    ${SSH} ${ip} "rm -rf /tmp/ovs_rpms"
+    scp "${WORKSPACE}"/build_ovs.sh "${ip}":/tmp
+    ${SSH} "${ip}" " bash /tmp/build_ovs.sh >> /tmp/install_ovs.txt 2>&1"
+    scp -r "${ip}":/tmp/ovs_rpms/* "${rpm_path}/"
+    ${SSH} "${ip}" "rm -rf /tmp/ovs_rpms"
 }
 
 # Install OVS RPMs from yum repo
@@ -939,7 +1012,7 @@ function install_ovs_from_repo() {
     local -r rpm_repo="$2"
 
     echo "Installing OVS from repo ${rpm_repo} on ${ip} ..."
-    cat > ${WORKSPACE}/install_ovs.sh << EOF
+    cat > "${WORKSPACE}"/install_ovs.sh << EOF
 set -ex -o pipefail
 
 echo '---> Installing openvswitch from ${rpm_repo}'
@@ -997,8 +1070,8 @@ NEW_MOD=\$(sudo modinfo -n openvswitch || echo '')
 [ "\${PREV_MOD}" != "\${NEW_MOD}" ] || (echo "Kernel module was not updated" && exit 1)
 EOF
 
-    scp ${WORKSPACE}/install_ovs.sh ${ip}:/tmp
-    ${SSH} ${ip} "bash /tmp/install_ovs.sh >> /tmp/install_ovs.txt 2>&1"
+    scp "${WORKSPACE}"/install_ovs.sh "${ip}":/tmp
+    ${SSH} "${ip}" "bash /tmp/install_ovs.sh >> /tmp/install_ovs.txt 2>&1"
 }
 
 # Install OVS RPMS from path
@@ -1007,10 +1080,10 @@ function install_ovs_from_path() {
     local -r rpm_path="$2"
 
     echo "Creating OVS RPM repo on ${ip} ..."
-    ${SSH} ${ip} "mkdir -p /tmp/ovs_rpms"
-    scp -r "${rpm_path}"/* ${ip}:/tmp/ovs_rpms
-    ${SSH} ${ip} "sudo yum -y install createrepo && createrepo --database /tmp/ovs_rpms"
-    install_ovs_from_repo ${ip} file:/tmp/ovs_rpms
+    ${SSH} "${ip}" "mkdir -p /tmp/ovs_rpms"
+    scp -r "${rpm_path}"/* "${ip}":/tmp/ovs_rpms
+    ${SSH} "${ip}" "sudo yum -y install createrepo && createrepo --database /tmp/ovs_rpms"
+    install_ovs_from_repo "${ip}" file:/tmp/ovs_rpms
 }