From 74fbf962be86c2fab3a73cff634761a08fc87f3c Mon Sep 17 00:00:00 2001 From: Victor Seva Date: Fri, 19 Mar 2021 15:24:52 +0100 Subject: [PATCH] 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 --- bin/check.sh | 153 +-------------------------- bin/get_domains.pl | 46 ++++++++ bin/provide_scenario.sh | 228 ++++++++++++++++++++++++++++++++++++++++ get_results.sh | 3 +- run_tests.sh | 4 +- 5 files changed, 282 insertions(+), 152 deletions(-) create mode 100755 bin/get_domains.pl create mode 100755 bin/provide_scenario.sh diff --git a/bin/check.sh b/bin/check.sh index 0f7071ef..7528df7d 100755 --- a/bin/check.sh +++ b/bin/check.sh @@ -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 diff --git a/bin/get_domains.pl b/bin/get_domains.pl new file mode 100755 index 00000000..547254fd --- /dev/null +++ b/bin/get_domains.pl @@ -0,0 +1,46 @@ +#!/usr/bin/perl +# +# 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". +# +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"); +} diff --git a/bin/provide_scenario.sh b/bin/provide_scenario.sh new file mode 100755 index 00000000..6297b421 --- /dev/null +++ b/bin/provide_scenario.sh @@ -0,0 +1,228 @@ +#!/bin/bash +# +# Copyright: 2013-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". +# +# 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 <