From 5fe990c22e59af8bbc87f4df22a9ee5739793078 Mon Sep 17 00:00:00 2001 From: Victor Seva Date: Thu, 9 Jul 2020 10:35:40 +0200 Subject: [PATCH] TT#81700 generate_test_tt2.sh: helper Helper script to generate test_yml.tt2 files from scenario $ ./bin/generate_test_tt2.sh -x scenarios_pbx incoming_shared_line 16 17 Change-Id: Iaf43dbc04ddcd9c8f6d7b913939a7cd3649e31d8 --- bin/generate_test_tt2.sh | 101 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100755 bin/generate_test_tt2.sh diff --git a/bin/generate_test_tt2.sh b/bin/generate_test_tt2.sh new file mode 100755 index 00000000..37c81927 --- /dev/null +++ b/bin/generate_test_tt2.sh @@ -0,0 +1,101 @@ +#!/bin/bash +# +# Copyright: 2020 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". +# +BASE_DIR="${BASE_DIR:-/usr/share/kamailio-config-tests}" +BIN_DIR="${BASE_DIR}/bin" +DEST_DIR="${DEST_DIR}" +GROUP="${GROUP:-scenarios}" + +function usage +{ + echo "Usage: generate_tests_tt2.sh [-h] [-x GROUP] scenario [id1] [id2]" + echo "Options:" + echo -e "\\tx: group of scenarios. Default: scenarios" + echo -e "\\th: this help" + echo "Args:" + echo -e "\\tscenario: name of the scenario in GROUP" + echo -e "\\tid: of the json file and test file to be produced. This is optional," + echo -e "\\t if no ids, all json files in log dir will be used." + echo -e "\\t More than one id can be used. No need to pass leading zeros." + echo + echo "Examples:" + echo -e "\\t\$ generate_tests_tt2.sh -x scenarios_pbx invite" + echo -e "\\t\$ generate_tests_tt2.sh incoming 1 7 12" +} + +while getopts 'hx:' opt; do + case $opt in + h) usage; exit 0;; + x) GROUP=${OPTARG};; + *) usage; exit 1;; + esac +done +shift $((OPTIND - 1)) +SCEN="$1" + +if [[ $# -lt 1 ]]; then + echo "Wrong number or arguments" >&2 + usage + exit 1 +fi + +SCEN_DIR="${BASE_DIR}/${GROUP}/${SCEN}" +LOG_DIR="${BASE_DIR}/log/${GROUP}/${SCEN}" +if [ ! -d "${SCEN_DIR}" ] ; then + echo "${SCEN_DIR} not found" >&2 + exit 2 +elif [ ! -f "${SCEN_DIR}/scenario.yml" ] ; then + echo "${SCEN_DIR}/scenario.yml not found" >&2 + exit 2 +fi +if [ ! -d "${LOG_DIR}" ] ; then + echo "${LOG_DIR} not found" >&2 + exit 2 +elif [ ! -f "${LOG_DIR}/scenario_ids.yml" ] ; then + echo "${LOG_DIR}/scenario_ids.yml not found" >&2 + exit 2 +fi + +if [ ! -x "${BIN_DIR}/generate_test_tt2.pl" ]; then + echo "Cannot exec ${BIN_DIR}/generate_test_tt2.pl" >&2 + usage + exit 3 +fi +if [[ $# -eq 1 ]]; then + mapfile -t IDS < <(find "${LOG_DIR}" -maxdepth 1 -name '*.json' -exec basename {} \;| sort) +else + shift 1 + IDS=() + for t in "${@}"; do + file=$(printf "%04d.json" "${t}") + if [ ! -f "${LOG_DIR}/${file}" ]; then + echo "${LOG_DIR}/${file} not found" >&2 + exit 4 + fi + IDS+=( "${file}" ) + done +fi +CMD="${BIN_DIR}/generate_test_tt2.pl -F -i ${LOG_DIR}/scenario_ids.yml" +CMD+=" -n ${SCEN_DIR}/scenario.yml " +for t in "${IDS[@]}" ; do + file="${SCEN_DIR}/$(basename "${t}" .json)"_test.yml.tt2 + echo "generating: ${file}" + ${CMD} "${LOG_DIR}/${t}" > "${file}" +done