TT#116100 bin/check.sh: split logic of provisioning

* bin/provide_scenario.sh: point of entry of provisioning
* bin/get_domains.pl: script helper to get domains defined at
  scenario.yml

Change-Id: Ib1440f074b6f588c8a9dfac5dcf29d6b7459fb42
mr9.4
Victor Seva 5 years ago
parent 0cc5b149a4
commit 74fbf962be
No known key found for this signature in database
GPG Key ID: B1589889727198E0

@ -274,138 +274,6 @@ check_test() {
return 1
}
# $1 domain
create_voip() {
if ! "${BIN_DIR}/create_subscribers.pl" \
"${SCEN_CHECK_DIR}/scenario.yml" "${SCEN_CHECK_DIR}/scenario_ids.yml"
then
echo "$(date) - Deleting domain:${DOMAIN}"
delete_voip "$1"
echo "$(date) - Cannot create domain subscribers"
exit 1
fi
if [ -f "${SCEN_CHECK_DIR}/registration.yml" ]; then
echo "$(date) - Creating permanent registrations"
"${BIN_DIR}/create_registrations.pl" \
"${SCEN_CHECK_DIR}/registration.yml"
fi
}
# $1 prefs yml file
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"
fi
if [ -f "${SCEN_CHECK_DIR}/callforward.yml" ]; then
echo "$(date) - Setting callforward config"
"${BIN_DIR}/set_subscribers_callforward_advanced.pl" "${SCEN_CHECK_DIR}/callforward.yml"
fi
if [ -f "${SCEN_CHECK_DIR}/trusted.yml" ]; then
echo "$(date) - Setting trusted sources"
"${BIN_DIR}/set_subscribers_trusted_sources.pl" "${SCEN_CHECK_DIR}/trusted.yml"
fi
if [ -f "${SCEN_CHECK_DIR}/speeddial.yml" ]; then
echo "$(date) - Setting speeddial config"
"${BIN_DIR}/set_subscribers_speeddial.pl" "${SCEN_CHECK_DIR}/speeddial.yml"
fi
if [ -f "${SCEN_CHECK_DIR}/ncos.yml" ]; then
echo "$(date) - Creating ncos levels"
"${BIN_DIR}/create_ncos.pl" "${SCEN_CHECK_DIR}/ncos.yml"
fi
if [ -f "${SCEN_CHECK_DIR}/soundsets.yml" ]; then
echo "$(date) - Creating soundsets"
"${BIN_DIR}/create_soundsets.pl" \
"${SCEN_CHECK_DIR}/soundsets.yml" "${SCEN_CHECK_DIR}/scenario_ids.yml"
fi
if [ -f "${SCEN_CHECK_DIR}/peer.yml" ]; then
echo "$(date) - Creating peers"
"${BIN_DIR}/create_peers.pl" \
"${SCEN_CHECK_DIR}/peer.yml" "${SCEN_CHECK_DIR}/scenario_ids.yml"
# REMOVE ME!! fix for REST API
ngcp-kamcmd proxy lcr.reload
fi
if [ -f "${SCEN_CHECK_DIR}/lnp.yml" ]; then
echo "$(date) - Creating lnp carrier/number"
"${BIN_DIR}/create_lnp.pl" "${SCEN_CHECK_DIR}/lnp.yml"
fi
if [ -f "${SCEN_CHECK_DIR}/header.yml" ]; then
echo "$(date) - Creating header manipulations"
"${BIN_DIR}/create_header_manipulation.pl" "${SCEN_CHECK_DIR}/header.yml"
fi
if [ -f "${SCEN_CHECK_DIR}/prefs.json" ]; then
echo "$(date) - Setting preferences"
"${BIN_DIR}/set_preferences.pl" "${SCEN_CHECK_DIR}/prefs.json"
fi
}
# $1 domain
delete_voip() {
if [ -f "${SCEN_CHECK_DIR}/registration.yml" ]; then
echo "$(date) - Deleting registrations"
"${BIN_DIR}/create_registrations.pl" -delete "${SCEN_CHECK_DIR}/registration.yml"
fi
/usr/bin/ngcp-delete-domain "$1" >/dev/null 2>&1
if [ -f "${SCEN_CHECK_DIR}/peer.yml" ]; then
echo "$(date) - Deleting peers"
"${BIN_DIR}/create_peers.pl" -delete "${SCEN_CHECK_DIR}/peer.yml"
# REMOVE ME!! fix for REST API
ngcp-kamcmd proxy lcr.reload
fi
if [ -f "${SCEN_CHECK_DIR}/trusted.yml" ]; then
echo "$(date) - Deleting trusted sources"
# Trusted sources are not deleted from kamailio cache when the domain is removed
# therefore better reload them from the database
ngcp-kamcmd proxy permissions.trustedReload
fi
if [ -f "${SCEN_CHECK_DIR}/header.yml" ]; then
echo "$(date) - Deleting header manipulations"
"${BIN_DIR}/create_header_manipulation.pl" -delete "${SCEN_CHECK_DIR}/header.yml"
fi
if [ -f "${SCEN_CHECK_DIR}/lnp.yml" ]; then
echo "$(date) - Deleting lnp carrier/number"
"${BIN_DIR}/create_lnp.pl" -delete "${SCEN_CHECK_DIR}/lnp.yml"
# REMOVE ME!! fix for REST API
ngcp-kamcmd proxy lcr.reload
fi
if [ -f "${SCEN_CHECK_DIR}/ncos.yml" ]; then
echo "$(date) - Deleting ncos levels"
"${BIN_DIR}/create_ncos.pl" -delete "${SCEN_CHECK_DIR}/ncos.yml"
fi
if [ -f "${SCEN_CHECK_DIR}/rewrite.yml" ]; then
echo "$(date) - Deleting rewrite rules"
"${BIN_DIR}/create_rewrite_rules.pl" -delete "${SCEN_CHECK_DIR}/rewrite.yml"
fi
if [ -f "${SCEN_CHECK_DIR}/hosts" ]; then
echo "$(date) - Deleting foreign domains"
sed -e "s:$(cat "${SCEN_CHECK_DIR}/hosts")::" -i /etc/hosts
rm "${SCEN_CHECK_DIR}/hosts"
fi
if [ -f "${SCEN_CHECK_DIR}/soundsets.yml" ]; then
echo "$(date) - Deleting soundsets"
"${BIN_DIR}/create_soundsets.pl" -delete "${SCEN_CHECK_DIR}/soundsets.yml"
fi
}
release_appearance() {
local values
values=$(mktemp)
@ -427,8 +295,7 @@ release_appearance() {
error_helper() {
echo "$1"
if ! "${SKIP_DELDOMAIN}" ; then
echo "$(date) - Deleting domain:${DOMAIN}"
delete_voip "${DOMAIN}"
"${BIN_DIR}/provide_scenario.sh" "${SCEN_CHECK_DIR}" delete
fi
stop_capture
check_rtp
@ -781,7 +648,7 @@ cdr_check() {
}
usage() {
echo "Usage: check.sh [-hCDRTGgJKm] [-d DOMAIN ] [-p PROFILE ] -s [GROUP] check_name"
echo "Usage: check.sh [-hCDRTGgJKm] [-p PROFILE ] -s [GROUP] check_name"
echo "Options:"
echo -e "\\t-C: skip creation of domain and subscribers"
echo -e "\\t-R: skip run sipp"
@ -791,7 +658,6 @@ usage() {
echo -e "\\t-G: creation of graphviz image"
echo -e "\\t-g: creation of graphviz image only if test fails"
echo -e "\\t-r: fix retransmission issues"
echo -e "\\t-d: DOMAIN"
echo -e "\\t-p: CE|PRO default is CE"
echo -e "\\t-J: kamailio json output OFF"
echo -e "\\t-M: skip move of kamailio json output to log folder"
@ -803,11 +669,10 @@ usage() {
echo -e "\\tcheck_name. Scenario name to check. This is the name of the directory on GROUP dir."
}
while getopts 'hCd:p:Rs:DTPGgrcJKMmw:' opt; do
while getopts 'hCp:Rs:DTPGgrcJKMmw:' opt; do
case $opt in
h) usage; exit 0;;
C) SKIP=true;;
d) DOMAIN=${OPTARG};;
p) PROFILE=${OPTARG};;
R) SKIP_RUNSIPP=true; SKIP_DELDOMAIN=true;;
s) GROUP=${OPTARG};;
@ -849,7 +714,6 @@ SEMS_PBX_LOG=${SEMS_PBX_LOG:-"/var/log/ngcp/sems-pbx.log"}
RTP_LOG=${RTP_LOG:-"/var/log/ngcp/rtp.log"}
SCEN_DIR="${BASE_DIR}/${GROUP}"
SCEN_CHECK_DIR="${SCEN_DIR}/${NAME_CHECK}"
DOMAIN=${DOMAIN:-"spce.test"}
PROFILE="${PROFILE:-CE}"
MLOG_DIR="${BASE_DIR}/mem"
test_uuid=$(grep test_uuid "${SCEN_CHECK_DIR}/scenario.yml" | awk '{print $2}')
@ -878,12 +742,7 @@ if [ -f "${SCEN_CHECK_DIR}/pro.yml" ] && [ "${PROFILE}" == "CE" ]; then
fi
if ! "$SKIP" ; then
echo "$(date) - Deleting all info for ${DOMAIN} domain"
delete_voip "${DOMAIN}" # just to be sure nothing is there
echo "$(date) - Creating ${DOMAIN}"
create_voip "${DOMAIN}"
echo "$(date) - Adding prefs"
create_voip_prefs
"${BIN_DIR}/provide_scenario.sh" "${SCEN_CHECK_DIR}" create
fi
if ! "$SKIP_RUNSIPP" ; then
@ -981,9 +840,7 @@ fi
if ! "${SKIP_DELDOMAIN}" ; then
echo "$(date) - Deleting domain:${DOMAIN}"
delete_voip "${DOMAIN}"
echo "$(date) - Done"
"${BIN_DIR}/provide_scenario.sh" "${SCEN_CHECK_DIR}" delete
fi

@ -0,0 +1,46 @@
#!/usr/bin/perl
#
# 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".
#
use strict;
use warnings;
use English;
use Cwd 'abs_path';
use YAML::XS qw(LoadFile);
use Getopt::Long;
sub usage {
return "Usage:\n$PROGRAM_NAME scenario.yml\n".
"Options:\n".
" -h this help\n";
}
my $help = 0;
GetOptions ("h|help" => \$help)
or die("Error in command line arguments\n".usage());
die(usage()) unless (!$help);
die("Wrong number of arguments\n".usage()) unless ($#ARGV == 0);
my $data = LoadFile(abs_path($ARGV[0]));
foreach my $domain (sort keys %{$data->{domains}})
{
print("$domain\n");
}

@ -0,0 +1,228 @@
#!/bin/bash
#
# Copyright: 2013-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".
#
# shellcheck disable=SC2155
declare -r ME="$(basename "$0")"
BASE_DIR="${BASE_DIR:-/usr/share/kamailio-config-tests}"
BIN_DIR="${BASE_DIR}/bin"
if [ -z "${PERL5LIB}" ]; then
# Set up the environment, to use local perl modules
export PERL5LIB="${BASE_DIR}/lib"
fi
DOMAINS=()
get_domains() {
while read -r t; do
DOMAINS+=( "${t}" )
done < <("${BIN_DIR}/get_domains.pl" "${SCEN_CHECK_DIR}/scenario.yml")
if [[ ${#DOMAINS[@]} == 0 ]]; then
echo "$(date) no domains found"
exit 1
fi
}
delete() {
local DOMAIN=$1
echo "$(date) - Deleting domain:${DOMAIN}"
delete_voip "${DOMAIN}"
}
# $1 domain
create_voip() {
if ! "${BIN_DIR}/create_subscribers.pl" \
"${SCEN_CHECK_DIR}/scenario.yml" "${SCEN_CHECK_DIR}/scenario_ids.yml"
then
echo "$(date) - Cannot create domain subscribers"
delete "$1"
exit 1
fi
if [ -f "${SCEN_CHECK_DIR}/registration.yml" ]; then
echo "$(date) - Creating permanent registrations"
"${BIN_DIR}/create_registrations.pl" \
"${SCEN_CHECK_DIR}/registration.yml"
fi
}
# $1 prefs yml file
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"
fi
if [ -f "${SCEN_CHECK_DIR}/callforward.yml" ]; then
echo "$(date) - Setting callforward config"
"${BIN_DIR}/set_subscribers_callforward_advanced.pl" "${SCEN_CHECK_DIR}/callforward.yml"
fi
if [ -f "${SCEN_CHECK_DIR}/trusted.yml" ]; then
echo "$(date) - Setting trusted sources"
"${BIN_DIR}/set_subscribers_trusted_sources.pl" "${SCEN_CHECK_DIR}/trusted.yml"
fi
if [ -f "${SCEN_CHECK_DIR}/speeddial.yml" ]; then
echo "$(date) - Setting speeddial config"
"${BIN_DIR}/set_subscribers_speeddial.pl" "${SCEN_CHECK_DIR}/speeddial.yml"
fi
if [ -f "${SCEN_CHECK_DIR}/ncos.yml" ]; then
echo "$(date) - Creating ncos levels"
"${BIN_DIR}/create_ncos.pl" "${SCEN_CHECK_DIR}/ncos.yml"
fi
if [ -f "${SCEN_CHECK_DIR}/soundsets.yml" ]; then
echo "$(date) - Creating soundsets"
"${BIN_DIR}/create_soundsets.pl" \
"${SCEN_CHECK_DIR}/soundsets.yml" "${SCEN_CHECK_DIR}/scenario_ids.yml"
fi
if [ -f "${SCEN_CHECK_DIR}/peer.yml" ]; then
echo "$(date) - Creating peers"
"${BIN_DIR}/create_peers.pl" \
"${SCEN_CHECK_DIR}/peer.yml" "${SCEN_CHECK_DIR}/scenario_ids.yml"
# REMOVE ME!! fix for REST API
ngcp-kamcmd proxy lcr.reload
fi
if [ -f "${SCEN_CHECK_DIR}/lnp.yml" ]; then
echo "$(date) - Creating lnp carrier/number"
"${BIN_DIR}/create_lnp.pl" "${SCEN_CHECK_DIR}/lnp.yml"
fi
if [ -f "${SCEN_CHECK_DIR}/header.yml" ]; then
echo "$(date) - Creating header manipulations"
"${BIN_DIR}/create_header_manipulation.pl" "${SCEN_CHECK_DIR}/header.yml"
fi
if [ -f "${SCEN_CHECK_DIR}/prefs.json" ]; then
echo "$(date) - Setting preferences"
"${BIN_DIR}/set_preferences.pl" "${SCEN_CHECK_DIR}/prefs.json"
fi
}
# $1 domain
delete_voip() {
if [ -f "${SCEN_CHECK_DIR}/registration.yml" ]; then
echo "$(date) - Deleting registrations"
"${BIN_DIR}/create_registrations.pl" -delete "${SCEN_CHECK_DIR}/registration.yml"
fi
ngcp-delete-domain "$1" >/dev/null 2>&1
if [ -f "${SCEN_CHECK_DIR}/peer.yml" ]; then
echo "$(date) - Deleting peers"
"${BIN_DIR}/create_peers.pl" -delete "${SCEN_CHECK_DIR}/peer.yml"
# REMOVE ME!! fix for REST API
ngcp-kamcmd proxy lcr.reload
fi
if [ -f "${SCEN_CHECK_DIR}/trusted.yml" ]; then
echo "$(date) - Deleting trusted sources"
# Trusted sources are not deleted from kamailio cache when the domain is removed
# therefore better reload them from the database
ngcp-kamcmd proxy permissions.trustedReload
fi
if [ -f "${SCEN_CHECK_DIR}/header.yml" ]; then
echo "$(date) - Deleting header manipulations"
"${BIN_DIR}/create_header_manipulation.pl" -delete "${SCEN_CHECK_DIR}/header.yml"
fi
if [ -f "${SCEN_CHECK_DIR}/lnp.yml" ]; then
echo "$(date) - Deleting lnp carrier/number"
"${BIN_DIR}/create_lnp.pl" -delete "${SCEN_CHECK_DIR}/lnp.yml"
# REMOVE ME!! fix for REST API
ngcp-kamcmd proxy lcr.reload
fi
if [ -f "${SCEN_CHECK_DIR}/ncos.yml" ]; then
echo "$(date) - Deleting ncos levels"
"${BIN_DIR}/create_ncos.pl" -delete "${SCEN_CHECK_DIR}/ncos.yml"
fi
if [ -f "${SCEN_CHECK_DIR}/rewrite.yml" ]; then
echo "$(date) - Deleting rewrite rules"
"${BIN_DIR}/create_rewrite_rules.pl" -delete "${SCEN_CHECK_DIR}/rewrite.yml"
fi
if [ -f "${SCEN_CHECK_DIR}/hosts" ]; then
echo "$(date) - Deleting foreign domains"
sed -e "s:$(cat "${SCEN_CHECK_DIR}/hosts")::" -i /etc/hosts
rm "${SCEN_CHECK_DIR}/hosts"
fi
if [ -f "${SCEN_CHECK_DIR}/soundsets.yml" ]; then
echo "$(date) - Deleting soundsets"
"${BIN_DIR}/create_soundsets.pl" -delete "${SCEN_CHECK_DIR}/soundsets.yml"
fi
}
create() {
local DOMAIN=$1
delete "${DOMAIN}" # just to be sure nothing is there
echo "$(date) - Creating ${DOMAIN}"
create_voip "${DOMAIN}"
echo "$(date) - Adding prefs"
create_voip_prefs
}
usage() {
cat <<EOF
Usage: ${ME} [-h] scenario_dir action
Options:
-h: this help
Arguments:
scenario_dir
action. 'create' or 'delete'
EOF
}
while getopts 'hp:s:' opt; do
case $opt in
h) usage; exit 0;;
*) usage; exit 1;;
esac
done
shift $((OPTIND - 1))
if [[ $# != 2 ]]; then
echo "Wrong number of arguments"
usage
exit 1
fi
SCEN_CHECK_DIR="$1"
ACTION="$2"
if ! [ -d "${SCEN_CHECK_DIR}" ]; then
echo "scenario_dir:${SCEN_CHECK_DIR} found"
usage
exit 2
fi
get_domains
case ${ACTION} in
create) for t in "${DOMAINS[@]}"; do create "${t}"; done;;
delete) for t in "${DOMAINS[@]}"; do delete "${t}"; done;;
*) echo "action ${ACTION} unknown"; exit 2 ;;
esac
echo "$(date) - Done"

@ -3,7 +3,6 @@ RUN_DIR="$(dirname "$0")"
export BASE_DIR=${BASE_DIR:-$RUN_DIR}
BIN_DIR="${BASE_DIR}/bin"
PROFILE="${PROFILE:-}"
DOMAIN="spce.test"
GROUP="${GROUP:-scenarios}"
RETRANS=""
CDR=""
@ -77,7 +76,7 @@ fi
get_scenarios
echo "${SCEN[@]}" | tr ' ' '\n' \
| parallel "${BIN_DIR}/check.sh ${GRAPH} -C -R ${OPTS} ${RETRANS} ${CDR} -d ${DOMAIN} -p ${PROFILE} -s ${GROUP}"
| parallel "${BIN_DIR}/check.sh ${GRAPH} -C -R ${OPTS} ${RETRANS} ${CDR} -p ${PROFILE} -s ${GROUP}"
status=$?
echo "$(date) - All done[${status}]"
tap_cmd=()

@ -17,7 +17,7 @@ KAM_DIR="/tmp/cfgtest"
COREDUMP_DIR="/ngcp-data/coredumps"
PROFILE="${PROFILE:-}"
OPTS=(-P -T -M) #SKIP_PARSE=true, SKIP_TESTS=true, SKIP_MOVE_JSON_KAM=true
DOMAIN="spce.test"
TIMEOUT=${TIMEOUT:-300}
SHOW_SCENARIOS=false
SKIP_CONFIG=false
@ -376,7 +376,7 @@ for t in "${SCEN[@]}"; do
rm -rf "${json_temp}"
fi
if ! "${BIN_DIR}/check.sh" "${OPTS[@]}" -d "${DOMAIN}" -p "${PROFILE}" -s "${GROUP}" "${t}" ; then
if ! "${BIN_DIR}/check.sh" "${OPTS[@]}" -p "${PROFILE}" -s "${GROUP}" "${t}" ; then
echo "ERROR: ${t}"
error_flag=1
fi

Loading…
Cancel
Save