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
mr9.4
Victor Seva 5 years ago
parent 2be72bb3e2
commit f63d15ee84
No known key found for this signature in database
GPG Key ID: B1589889727198E0

@ -0,0 +1,99 @@
#!/bin/bash
#
# Copyright: 2021 Sipwise Development Team <support@sipwise.com>
#
# 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 <http://www.gnu.org/licenses/>.
#
# 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

@ -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
}

@ -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

Loading…
Cancel
Save