From f63d15ee8405f084316b715d73bfc5097808c0a7 Mon Sep 17 00:00:00 2001 From: Victor Seva Date: Thu, 18 Mar 2021 14:26:43 +0100 Subject: [PATCH] TT#116100 bin/get_scenarios.sh * single point of entry to get valid scenarios depending on PROFILE GROUP and obeying SCENARIOS environment variable Change-Id: I3dabf2b14c0c68f802287e1355f208ccb14224f6 --- bin/get_scenarios.sh | 99 ++++++++++++++++++++++++++++++++++++++++++++ get_results.sh | 36 +++------------- run_tests.sh | 27 ++++-------- 3 files changed, 112 insertions(+), 50 deletions(-) create mode 100755 bin/get_scenarios.sh diff --git a/bin/get_scenarios.sh b/bin/get_scenarios.sh new file mode 100755 index 00000000..86fe28f8 --- /dev/null +++ b/bin/get_scenarios.sh @@ -0,0 +1,99 @@ +#!/bin/bash +# +# Copyright: 2021 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 +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This package is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# On Debian systems, the complete text of the GNU General +# Public License version 3 can be found in "/usr/share/common-licenses/GPL-3". +# +GROUP="${GROUP:-scenarios}" +BASE_DIR="${BASE_DIR:-/usr/share/kamailio-config-tests}" +PROFILE="${PROFILE:-}" + +usage() { + echo "Usage: $0 [-h] [-x GROUP]" + echo "Options:" + echo -e "\\t-p CE|PRO default is autodetect" + echo -e "\\t-x set GROUP scenario. Default: scenarios" + echo -e "\\t-h this help" +} + +while getopts 'hp:x:' opt; do + case $opt in + h) usage; exit 0;; + p) PROFILE=${OPTARG};; + x) GROUP=${OPTARG};; + *) usage; exit 1;; + esac +done +shift $((OPTIND - 1)) + +if [[ $# -ne 0 ]]; then + echo "Wrong number or arguments" + usage + exit 1 +fi + +if [ -z "${PROFILE}" ] ; then + ngcp_type=$(command -v ngcp-type) + if [ -n "${ngcp_type}" ]; then + case $(${ngcp_type}) in + sppro|carrier) PROFILE=PRO;; + spce) PROFILE=CE;; + *) ;; + esac + fi +fi +if [ "${PROFILE}" != "CE" ] && [ "${PROFILE}" != "PRO" ]; then + echo "PROFILE ${PROFILE} unknown" + usage + exit 2 +fi + +filter_scenario() { + # filter out PRO only scenarios on CE + local scen=$1 + + if [ "${PROFILE}" == CE ] ; then + [ -f "${BASE_DIR}/${GROUP}/${scen}/pro.yml" ] && return 1 + fi + return 0 +} + +get_scenarios() { + local t + local flag + flag=false + + if [ -n "${SCENARIOS}" ]; then + for t in ${SCENARIOS}; do + if [ ! -f "${BASE_DIR}/${GROUP}/${t}/scenario.yml" ]; then + flag=true + else + filter_scenario "${t}" && echo "${t}" + fi + done + ${flag} && exit 1 + else + while read -r t; do + t=$(basename "${t}") + filter_scenario "${t}" && echo "${t}" + done < <(find "${BASE_DIR}/${GROUP}/" -name scenario.yml \ + -type f -exec dirname {} \; | sort) + fi +} + +get_scenarios +exit 0 \ No newline at end of file diff --git a/get_results.sh b/get_results.sh index c21460f8..fadd139c 100755 --- a/get_results.sh +++ b/get_results.sh @@ -24,37 +24,13 @@ usage() { echo "BIN_DIR:${BIN_DIR}" } -filter_scenario() { - # filter out PRO only scenarios on CE - local scen=$1 - - if [ "${PROFILE}" == CE ] ; then - [ -f "${BASE_DIR}/${GROUP}/${scen}/pro.yml" ] && return 1 - fi - return 0 -} - get_scenarios() { - local t - local flag - flag=false - - if [ -n "${SCENARIOS}" ]; then - for t in ${SCENARIOS}; do - if [ ! -f "${BASE_DIR}/${GROUP}/${t}/scenario.yml" ]; then - echo "$(date) - scenario: ${t}/scenario.yml at ${GROUP} not found" - flag=true - else - filter_scenario "${t}" && SCEN+=( "${t}" ) - fi - done - ${flag} && exit 1 - else - while read -r t; do - t=$(basename "${t}") - filter_scenario "${t}" && SCEN+=( "${t}" ) - done < <(find "${BASE_DIR}/${GROUP}/" -name scenario.yml \ - -type f -exec dirname {} \; | sort) + while read -r t; do + SCEN+=( "${t}" ) + done < <("${BIN_DIR}/get_scenarios.sh" -p "${PROFILE}" -x "${GROUP}") + if [[ ${#SCEN[@]} == 0 ]]; then + echo "$(date) no scenarios found" + exit 1 fi } diff --git a/run_tests.sh b/run_tests.sh index 5cc78bc5..12306ef6 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -31,25 +31,12 @@ error_flag=0 SCEN=() get_scenarios() { - local t - local flag - flag=false - - if [ -n "${SCENARIOS}" ]; then - for t in ${SCENARIOS}; do - 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 - ${flag} && exit 1 - else - while read -r t; do - SCEN+=( "$(basename "${t}")" ) - done < <(find "${BASE_DIR}/${GROUP}/" -name scenario.yml \ - -type f -exec dirname {} \; | sort) + while read -r t; do + SCEN+=( "${t}" ) + done < <("${BIN_DIR}/get_scenarios.sh" -p "${PROFILE}" -x "${GROUP}") + if [[ ${#SCEN[@]} == 0 ]]; then + echo "$(date) no scenarios found" + exit 1 fi } @@ -159,7 +146,7 @@ move_json_file() { fix_retransmissions() { echo "$(date) - =================================================================================" echo "$(date) - Checking retransmission issues" - for t in ${SCENARIOS}; do + for t in "${SCEN[@]}"; do echo "$(date) - - Scenario: ${t}" if [ "${t}" == "invite_retrans" ] ; then continue