Add ability to tweak log levels in apex job
[releng/builder.git] / jjb / integration / common-functions.sh
index bae69e425b164cce3fdd82ebf1cfd1403302c927..6cbf10069e4eb740a72357d613afed76eb0861bb 100644 (file)
@@ -90,8 +90,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 +118,45 @@ 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 get_os_deploy() {
     local -r num_systems=${1:-$NUM_OPENSTACK_SYSTEM}
     case ${num_systems} in
@@ -179,7 +219,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 +229,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 +249,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 +342,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 +350,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 +406,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 +446,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"