From 740408f3fc9fec311cc706204e77a663c826fc8b Mon Sep 17 00:00:00 2001 From: Victor Seva Date: Tue, 7 Jul 2020 14:13:07 +0200 Subject: [PATCH] TT#81700 fix discover of scenarios * check for dirs with a scenario.yml file * remove some shellcheck warnings: SC2207: Prefer mapfile or read -a to split command output (or quote to avoid splitting). Change-Id: I88b48fcc9668c3be26755472d6001f630a341fca --- bench.sh | 8 +++--- bin/check.sh | 2 +- bin/generate_test_tt2.pl | 2 +- bin/sipp.sh | 19 +++++++------- get_results.sh | 41 +++++++++++++++-------------- run_tests.sh | 56 +++++++++++++++++++++------------------- 6 files changed, 68 insertions(+), 60 deletions(-) diff --git a/bench.sh b/bench.sh index c5203179..03ae08c6 100755 --- a/bench.sh +++ b/bench.sh @@ -6,10 +6,10 @@ GROUP="${GROUP:-scenarios}" usage() { echo "Usage: bench.sh [-p PROFILE] [-C] [num_runs]" echo "Options:" - echo -e "\t-p CE|PRO default is CE" - echo -e "\t-C skips configuration of the environment" - echo -e "\t-x set GROUP scenario. Default: scenarios" - echo -e "\t-h this help" + echo -e "\\t-p CE|PRO default is CE" + echo -e "\\t-C skips configuration of the environment" + echo -e "\\t-x set GROUP scenario. Default: scenarios" + echo -e "\\t-h this help" echo -e "num_runs default is 20" } diff --git a/bin/check.sh b/bin/check.sh index 51dca98f..443bb61b 100755 --- a/bin/check.sh +++ b/bin/check.sh @@ -840,7 +840,7 @@ if ! "$SKIP_RUNSIPP" ; then for json_file in "${file_find[@]}" ; do new_name=$(printf "%04d.json" "${a}") mv -n "${json_file}" "${LOG_DIR}/${new_name}" &> /dev/null - ((a=a+1)) + ((a++)) done fi diff --git a/bin/generate_test_tt2.pl b/bin/generate_test_tt2.pl index 1deb454a..4d9455fe 100755 --- a/bin/generate_test_tt2.pl +++ b/bin/generate_test_tt2.pl @@ -133,7 +133,7 @@ sub subst_common $line =~ s/response="[^"]+"/response=".+"/; $line =~ s/nonce="[^"]+"/nonce=".+"/; } elsif($line =~ /^(Server|User-Agent): Sipwise/i) { - $line =~ s/: Sipwise NGCP (Proxy|PBX) Server.+/: Sipwise NGCP ${1} Server/; + $line =~ s/: Sipwise NGCP (Proxy|Application|PBX).+/: Sipwise NGCP ${1}/; } elsif($line =~ /^Content-Length:[ ]+[1-9]/i) { $line =~ s/:[ ]+\d+/:\\s+\\d+/; } elsif($line =~ /^P-LB-Uptime: /i) { diff --git a/bin/sipp.sh b/bin/sipp.sh index dafa5064..e4026b28 100755 --- a/bin/sipp.sh +++ b/bin/sipp.sh @@ -1,6 +1,6 @@ #!/bin/bash # -# Copyright: 2013 Sipwise Development Team +# Copyright: 2013-2020 Sipwise Development Team # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -21,15 +21,15 @@ usage() { echo "Usage: sipp.sh [-p PORT] [-m MPORT] [-t TIMEOUT] [-r] [-T TRANSPORT] scenario.xml" echo "Options:" - echo -e "\t-p: sip port. default 50602/50603(responder)" - echo -e "\t-m: media port" - echo -e "\t-t: timeout. default 10/25(responder)" - echo -e "\t-i: IP. default 127.0.0.1" - echo -e "\t-T: transport [UDP|TCP] default UDP" - echo -e "\t-r: responder" - echo -e "\t-b: run sipp in background (responder)" + echo -e "\\t-p: sip port. default 50602/50603(responder)" + echo -e "\\t-m: media port" + echo -e "\\t-t: timeout. default 10/25(responder)" + echo -e "\\t-i: IP. default 127.0.0.1" + echo -e "\\t-T: transport [UDP|TCP] default UDP" + echo -e "\\t-r: responder" + echo -e "\\t-b: run sipp in background (responder)" echo "Arguments:" - echo -e "\t sipp_scenario.xml file" + echo -e "\\t sipp_scenario.xml file" } while getopts 'hrp:m:t:i:T:b' opt; do @@ -42,6 +42,7 @@ while getopts 'hrp:m:t:i:T:b' opt; do i) IP=$OPTARG;; T) TRANSPORT=${OPTARG,,};; b) BACK="-bg";; + *) usage; exit 0;; esac done shift $((OPTIND - 1)) diff --git a/get_results.sh b/get_results.sh index 690ea5b3..bf220b3d 100755 --- a/get_results.sh +++ b/get_results.sh @@ -10,15 +10,15 @@ CDR="" usage() { echo "Usage: get_results.sh [-p PROFILE] [-h] [-g]" - echo "-p CE|PRO default is CE" - echo "-g generate png flow graphs if test fails" - echo "-G generate png all flow graphs" - echo "-h this help" - echo "-P parse only will disable test" - echo "-T test only will disable parse" - echo "-r fix retransmission issues" - echo "-c enable cdr validation" - echo "-x set GROUP scenario. Default: scenarios" + echo -e "\\t-p CE|PRO default is CE" + echo -e "\\t-g generate png flow graphs if test fails" + echo -e "\\t-G generate png all flow graphs" + echo -e "\\t-h this help" + echo -e "\\t-P parse only will disable test" + echo -e "\\t-T test only will disable parse" + echo -e "\\t-r fix retransmission issues" + echo -e "\\t-c enable cdr validation" + echo -e "\\t-x set GROUP scenario. Default: scenarios" echo "BASE_DIR:${BASE_DIR}" echo "BIN_DIR:${BIN_DIR}" } @@ -26,20 +26,23 @@ usage() { get_scenarios() { local t local flag - flag=0 + flag=false + if [ -n "${SCENARIOS}" ]; then for t in ${SCENARIOS}; do - if [ ! -d "${BASE_DIR}/${GROUP}/${t}" ]; then - echo "$(date) - scenario: $t not found" - flag=1 + if [ ! -f "${BASE_DIR}/${GROUP}/${t}/scenario.yml" ]; then + echo "$(date) - scenario: ${t}/scenario.yml at ${GROUP} not found" + flag=true + else + SCEN+=( "${t}" ) fi done - if [ $flag != 0 ]; then - exit 1 - fi + ${flag} && exit 1 else - SCENARIOS=$(find "${BASE_DIR}/${GROUP}/" -depth -maxdepth 1 -mindepth 1 \ - -type d -exec basename {} \; | grep -v templates | sort) + while read -r t; do + SCEN+=( "$(basename "${t}")" ) + done < <(find "${BASE_DIR}/${GROUP}/" -name scenario.yml \ + -type f -exec dirname {} \; | sort) fi } @@ -82,7 +85,7 @@ fi get_scenarios -echo "${SCENARIOS}" | tr ' ' '\n' \ +echo "${SCEN[@]}" | tr ' ' '\n' \ | parallel "${BIN_DIR}/check.sh ${GRAPH} -C -R ${OPTS} ${RETRANS} ${CDR} -d ${DOMAIN} -p ${PROFILE} -s ${GROUP}" status=$? echo "$(date) - All done[${status}]" diff --git a/run_tests.sh b/run_tests.sh index 72d0037e..7a9c37ef 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -26,24 +26,28 @@ MEMDBG=false CDR=false START_TIME=$(date +%s) error_flag=0 +SCEN=() get_scenarios() { local t local flag - flag=0 + flag=false + if [ -n "${SCENARIOS}" ]; then for t in ${SCENARIOS}; do - if [ ! -d "${BASE_DIR}/${GROUP}/${t}" ]; then - echo "$(date) - scenario: $t at ${GROUP} not found" - flag=1 + if [ ! -f "${BASE_DIR}/${GROUP}/${t}/scenario.yml" ]; then + echo "$(date) - scenario: ${t}/scenario.yml at ${GROUP} not found" + flag=true + else + SCEN+=( "${t}" ) fi done - if [ ${flag} != 0 ]; then - exit 1 - fi + ${flag} && exit 1 else - SCENARIOS=$(find "${BASE_DIR}/${GROUP}/" -depth -maxdepth 1 -mindepth 1 \ - -type d -exec basename {} \; | grep -v templates | sort) + while read -r t; do + SCEN+=( "$(basename "${t}")" ) + done < <(find "${BASE_DIR}/${GROUP}/" -name scenario.yml \ + -type f -exec dirname {} \; | sort) fi } @@ -126,7 +130,7 @@ stop_capture() { move_json_file() { echo "$(date) - =================================================================================" echo "$(date) - Move kamailio json files" - for t in ${SCENARIOS}; do + for t in "${SCEN[@]}"; do echo "$(date) - - Scenario: ${t}" json_dir="${KAM_DIR}/${t}" if [ -d "${json_dir}" ] ; then @@ -155,7 +159,7 @@ fix_retransmissions() { continue fi RETRANS_ISSUE=false - file_find=($(find "${LOG_DIR}/${t}" -maxdepth 1 -name '*.json' | sort)) + mapfile -t file_find < <(find "${LOG_DIR}/${t}" -maxdepth 1 -name '*.json' | sort) for json_file in "${file_find[@]}" ; do file_find=("${file_find[@]:1}") if ! [ -a "${json_file}" ] ; then @@ -184,12 +188,12 @@ fix_retransmissions() { if "${RETRANS_ISSUE}" ; then echo "$(date) - - - Reordering kamailio json files" - file_find=($(find "${LOG_DIR}/${t}" -maxdepth 1 -name '*.json' | sort)) + mapfile -t file_find < <(find "${LOG_DIR}/${t}" -maxdepth 1 -name '*.json' | sort) a=1 for json_file in "${file_find[@]}" ; do new_name=$(printf "%04d.json" "${a}") mv -n "${json_file}" "${LOG_DIR}/${t}/${new_name}" &> /dev/null - let a=a+1 + ((a++)) done fi done @@ -201,7 +205,7 @@ fix_retransmissions() { cdr_export() { echo "$(date) - =================================================================================" echo "$(date) - Extracting CDRs" - for t in ${SCENARIOS}; do + for t in "${SCEN[@]}"; do echo "$(date) - - Scenario: $t" if ! "${BIN_DIR}/cdr_extract.sh" -m -t "${START_TIME}" -s "${GROUP}" "${t}" ; then echo "ERROR: ${t}" @@ -216,16 +220,16 @@ cdr_export() { usage() { echo "Usage: run_test.sh [-p PROFILE] [-C] [-t]" echo "Options:" - echo -e "\t-p CE|PRO default is CE" - echo -e "\t-l print available SCENARIOS in GROUP" - echo -e "\t-C skips configuration of the environment" - echo -e "\t-K capture messages with tcpdump" - echo -e "\t-x set GROUP scenario. Default: scenarios" - echo -e "\t-t set timeout in secs for pid_watcher.py [PRO]. Default: 300" - echo -e "\t-r fix retransmission issues" - echo -e "\t-c export CDRs at the end of the test" - echo -e "\t-m mem debug" - echo -e "\t-h this help" + echo -e "\\t-p CE|PRO default is CE" + echo -e "\\t-l print available SCENARIOS in GROUP" + echo -e "\\t-C skips configuration of the environment" + echo -e "\\t-K capture messages with tcpdump" + echo -e "\\t-x set GROUP scenario. Default: scenarios" + echo -e "\\t-t set timeout in secs for pid_watcher.py [PRO]. Default: 300" + echo -e "\\t-r fix retransmission issues" + echo -e "\\t-c export CDRs at the end of the test" + echo -e "\\t-m mem debug" + echo -e "\\t-h this help" echo "BASE_DIR:${BASE_DIR}" echo "BIN_DIR:${BIN_DIR}" @@ -256,7 +260,7 @@ fi if "${SHOW_SCENARIOS}" ; then get_scenarios - echo "${SCENARIOS}" + echo "${SCEN[@]}" exit 0 fi @@ -356,7 +360,7 @@ if "${CAPTURE}" ; then capture fi -for t in ${SCENARIOS}; do +for t in "${SCEN[@]}"; do echo "$(date) - =================================================================================" echo "$(date) - Run [${GROUP}/${PROFILE}]: ${t}"