From 132a4146b0324898cb10c984cf72f84eb96d29a1 Mon Sep 17 00:00:00 2001 From: Marco Capetta Date: Fri, 12 Jan 2018 15:05:46 +0100 Subject: [PATCH] TT#30353 Fix function definitions in all bash scripts Change-Id: I02a58bb18240627e126dfad05ee41c79982e9978 --- bin/check.sh | 78 ++++++++++++++++++------------------------------- bin/presence.sh | 6 ++-- bin/sipp.sh | 3 +- get_results.sh | 6 ++-- run_tests.sh | 9 ++---- 5 files changed, 36 insertions(+), 66 deletions(-) diff --git a/bin/check.sh b/bin/check.sh index f685d3dd..8611fcbf 100755 --- a/bin/check.sh +++ b/bin/check.sh @@ -22,10 +22,10 @@ # sipwise password for mysql connections . /etc/mysql/sipwise.cnf + # $1 kamailio msg parsed to yml # $2 destination png filename -function graph -{ +graph() { local OPTS if [ -n "${JSON_KAM}" ]; then OPTS="--json" @@ -40,8 +40,7 @@ function graph # $1 destination tap file # $2 file path -function generate_error_tap -{ +generate_error_tap() { local tap_file="$1" cat < "$tap_file" 1..1 @@ -53,8 +52,7 @@ echo "$(date) - $(basename "$2") NOT ok" # $1 unit test yml # $2 kamailio msg parsed to yml # $3 destination tap filename -function check_test -{ +check_test() { local dest local kam_type="--yaml" @@ -90,8 +88,7 @@ function check_test } # $1 domain -function create_voip -{ +create_voip() { if ! "${BIN_DIR}/create_subscribers.pl" \ "${SCEN_CHECK_DIR}/scenario.yml" "${SCEN_CHECK_DIR}/scenario_ids.yml" then @@ -103,8 +100,7 @@ function create_voip } # $1 prefs yml file -function create_voip_prefs -{ +create_voip_prefs() { if [ -f "${SCEN_CHECK_DIR}/rewrite.yml" ]; then echo "$(date) - Creating rewrite rules" "${BIN_DIR}/create_rewrite_rules.pl" "${SCEN_CHECK_DIR}/rewrite.yml" @@ -151,8 +147,7 @@ function create_voip_prefs } # $1 domain -function delete_voip -{ +delete_voip() { /usr/bin/ngcp-delete_domain "$1" >/dev/null 2>&1 if [ -f "${SCEN_CHECK_DIR}/peer.yml" ]; then @@ -189,8 +184,7 @@ function delete_voip fi } -function delete_locations -{ +delete_locations() { local f local sub @@ -218,8 +212,7 @@ function delete_locations fi } -function release_appearance -{ +release_appearance() { local values values=$(mktemp) ngcp-sercmd proxy sca.all_appearances >"${values}" 2>&1 @@ -237,8 +230,7 @@ function release_appearance # $1 msg to echo # $2 exit value -function error_helper -{ +error_helper() { echo "$1" if [ -z "${SKIP_DELDOMAIN}" ]; then echo "$(date) - Deleting domain:${DOMAIN}" @@ -250,8 +242,7 @@ function error_helper exit "$2" } -function capture -{ +capture() { local name name=$(basename "${SCEN_CHECK_DIR}") echo "$(date) - Begin capture" @@ -261,8 +252,7 @@ function capture done } -function stop_capture -{ +stop_capture() { local inter="" local temp_pid="" if [ -n "${capture_pid}" ]; then @@ -279,8 +269,7 @@ function stop_capture } # $1 port to check -function check_port -{ +check_port() { local status=0 local port=$1 local step=${2:-1} @@ -297,8 +286,7 @@ function check_port # $1 media port to check # sipp uses media_port and media_port+2 -function check_mport -{ +check_mport() { local status=0 local mport=$1 local step=${2:-3} @@ -318,8 +306,7 @@ function check_mport } #$1 is filename -function get_ip -{ +get_ip() { transport=$(grep "$1" "${SCEN_CHECK_DIR}/scenario.csv"|cut -d\; -f2| tr -d '\n') ip=$(grep "$1" "${SCEN_CHECK_DIR}/scenario.csv"|cut -d\; -f3| tr -d '\n') if [[ $? -ne 0 ]]; then @@ -329,18 +316,7 @@ function get_ip foreign_dom=$(grep "$1" "${SCEN_CHECK_DIR}/scenario.csv"|cut -d\; -f5| tr -d '\n') } -#$1 is filename -function is_enabled -{ - if ! grep -q "$1" "${SCEN_CHECK_DIR}/scenario.csv" ; then - echo "$(date) $1 deactivated" - # shellcheck disable=SC2104 - continue - fi -} - -function copy_logs -{ +copy_logs() { # copy the kamailio log cp "${KAM_LOG}" "${LOG_DIR}/kamailio.log" if [ -f "${SEMS_LOG}" ] ; then @@ -355,8 +331,7 @@ function copy_logs cp "${KAMLB_LOG}" "${LOG_DIR}/kamailio-lb.log" } -function memdbg -{ +memdbg() { if [ -x /usr/share/ngcp-system-tools/kamcmd/memdbg ] ; then ngcp-sercmd proxy memdbg all >/dev/null mkdir -p "${MLOG_DIR}" @@ -365,8 +340,7 @@ function memdbg } # $1 sipp xml scenario file -function run_sipp -{ +run_sipp() { local PORT local MPORT PORT=$(check_port 50603) @@ -407,7 +381,10 @@ function run_sipp for res in $(find "${SCEN_CHECK_DIR}" -type f -name 'sipp_scenario_responder[0-9][0-9].xml'| sort); do base=$(basename "$res" .xml) - is_enabled "$(basename "$res")" + if ! grep -q "$(basename "$res")" "${SCEN_CHECK_DIR}/scenario.csv" ; then + echo "$(date) $(basename "$res") deactivated" + continue + fi get_ip "$(basename "$res")" if [ "${peer_host}" != "" ]; then echo "$(date) - Update peer_host:${peer_host} ${ip}:${PORT} info" @@ -445,7 +422,10 @@ function run_sipp # let's fire sipp scenarios for send in $(find "${SCEN_CHECK_DIR}" -type f -name 'sipp_scenario[0-9][0-9].xml'| sort); do base=$(basename "$send" .xml) - is_enabled "$(basename "$send")" + if ! grep -q "$(basename "$send")" "${SCEN_CHECK_DIR}/scenario.csv" ; then + echo "$(date) $(basename "$send") deactivated" + continue + fi get_ip "$(basename "$send")" PORT=$(check_port ) MPORT=$(check_mport ) @@ -493,8 +473,7 @@ function run_sipp } # shellcheck disable=SC2001 -function test_filepath -{ +test_filepath() { local msg_name if [ -z "${JSON_KAM}" ]; then @@ -505,8 +484,7 @@ function test_filepath msg=${LOG_DIR}/$(basename "$msg_name") } -function usage -{ +usage() { echo "Usage: check.sh [-hCDRTGgJKm] [-d DOMAIN ] [-p PROFILE ] -s [GROUP] check_name" echo "Options:" echo -e "\t-C: skip creation of domain and subscribers" diff --git a/bin/presence.sh b/bin/presence.sh index 923c54b6..534d141c 100755 --- a/bin/presence.sh +++ b/bin/presence.sh @@ -21,13 +21,11 @@ BASE_DIR="${BASE_DIR:-/usr/share/kamailio-config-tests}" DIR="${BASE_DIR}/scenarios" -function clean -{ +clean() { find "${DIR}" -type f -name 'presence_*.xml' -exec rm {} \; } -function usage -{ +usage() { echo "Usage: generate_tests.sh [-h] [-c] [-d directory] digest presence_file.xml" echo "Options:" echo -e "\tc: clean. Removes all generated presence files" diff --git a/bin/sipp.sh b/bin/sipp.sh index 005aaf16..2b69a386 100755 --- a/bin/sipp.sh +++ b/bin/sipp.sh @@ -18,8 +18,7 @@ # On Debian systems, the complete text of the GNU General # Public License version 3 can be found in "/usr/share/common-licenses/GPL-3". # -function usage -{ +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)" diff --git a/get_results.sh b/get_results.sh index e5f4aaad..7656ceb3 100755 --- a/get_results.sh +++ b/get_results.sh @@ -6,8 +6,7 @@ PROFILE="CE" DOMAIN="spce.test" GROUP="${GROUP:-scenarios}" -function usage -{ +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" @@ -20,8 +19,7 @@ function usage echo "BIN_DIR:${BIN_DIR}" } -function get_scenarios -{ +get_scenarios() { local t local flag flag=0 diff --git a/run_tests.sh b/run_tests.sh index 089297a6..13b85de0 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -13,8 +13,7 @@ DOMAIN="spce.test" TIMEOUT=${TIMEOUT:-300} error_flag=0 -function usage -{ +usage() { echo "Usage: run_test.sh [-p PROFILE] [-c] [-t]" echo "-p CE|PRO default is CE" echo "-l print available SCENARIOS in GROUP" @@ -28,8 +27,7 @@ function usage echo "BIN_DIR:${BIN_DIR}" } -function get_scenarios -{ +get_scenarios() { local t local flag flag=0 @@ -49,8 +47,7 @@ function get_scenarios fi } -function cfg_debug_off -{ +cfg_debug_off() { if [ -z "$SKIP" ]; then echo "$(date) - Removed apicert.pem" rm -f "${BASE_DIR}/apicert.pem"