diff --git a/bin/cdr_extract.sh b/bin/cdr_extract.sh new file mode 100755 index 00000000..045c66fd --- /dev/null +++ b/bin/cdr_extract.sh @@ -0,0 +1,74 @@ +#!/bin/bash +# +# Copyright: 2013-2016 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". +# + + +START_TIME="" + + +# sipwise password for mysql connections +. /etc/mysql/sipwise.cnf + + +usage() { + echo "Usage: check.sh [-h] -t START_TIME -s [GROUP] check_name" + echo "Options:" + echo -e "\t-t Tests start time in order to better tune the mysql query." + echo -e "\t-s scenario group. Default: scenarios" + echo "Arguments:" + echo -e "\tcheck_name. Scenario name to check. This is the name of the directory on GROUP dir." +} + +while getopts 'ht:s:' opt; do + case $opt in + h) usage; exit 0;; + t) START_TIME=$OPTARG;; + s) GROUP=$OPTARG;; + esac +done +shift $((OPTIND - 1)) + +if [[ $# != 1 ]]; then + echo "Wrong number of arguments" + usage + exit 1 +fi + +if [ -z "${START_TIME}" ]; then + echo "Start time not defined" + usage + exit 1 +fi + + +GROUP="${GROUP:-scenarios}" +NAME_CHECK="$1" +BASE_DIR="${BASE_DIR:-/usr/share/kamailio-config-tests}" +LOG_DIR="${BASE_DIR}/log/${GROUP}/${NAME_CHECK}" + + +echo "$(date) - Exporting generated CDRs" +mysql -usipwise -p"${SIPWISE_DB_PASSWORD}" accounting \ + -e "select * from cdr where call_id like 'NGCP\%${NAME_CHECK}\%%' and start_time > ${START_TIME} order by id desc limit 10\G" > "${LOG_DIR}/cdr.txt" || true +echo "$(date) - Done" + + +exit 0 +#EOF diff --git a/bin/check.sh b/bin/check.sh index 978cb02e..c99bb898 100755 --- a/bin/check.sh +++ b/bin/check.sh @@ -560,11 +560,6 @@ next_test_filepath() { next_msg="${LOG_DIR}/${msg_name}" } -export_cdr() { - mysql -usipwise -p"${SIPWISE_DB_PASSWORD}" accounting \ - -e "select * from cdr where call_id like 'NGCP\%${1}\%%' and start_time > unix_timestamp(date_sub(now(), interval 1 minute)) order by id desc limit 3\G" > "${2}/cdr.txt" || true -} - cdr_check() { if [ -f "$1" ] ; then echo -n "$(date) - Testing $(basename "$1") against $(basename "$2") -> $(basename "$3")" @@ -763,16 +758,6 @@ if ! "${SKIP_DELDOMAIN}" ; then fi -if ! "$SKIP_RUNSIPP" && "${CDR}" ; then -# if "${CDR}" ; then - echo "$(date) - Exporting generated CDRs" - sleep 1.5 - export_cdr "${NAME_CHECK}" "${LOG_DIR}" - echo "$(date) - Done" -# fi -fi - - if ! "${SKIP_PARSE}" ; then if ! "${JSON_KAM}" ; then echo "$(date) - Parsing ${LOG_DIR}/kamailio.log" diff --git a/run_tests.sh b/run_tests.sh index 8a1894b7..6888c1a2 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -18,6 +18,7 @@ SKIP_CAPTURE=false SKIP_RETRANS=false MEMDBG=false CDR=false +START_TIME=$(date +%s) error_flag=0 usage() { @@ -177,12 +178,11 @@ if "${SKIP_RETRANS}" ; then fi if "${CDR}" ; then - echo "$(date) - enable cdr export" - OPTS+=(-c) + echo "$(date) - enable cdr export at the end of the execution" fi for t in ${SCENARIOS}; do - echo "$(date) - Run[${GROUP}/${PROFILE}]: $t =================================================" + echo "$(date) - Run [${GROUP}/${PROFILE}]: $t =================================================" log_temp="${LOG_DIR}/${t}" if [ -d "${log_temp}" ]; then echo "$(date) - Clean log dir" @@ -195,6 +195,18 @@ for t in ${SCENARIOS}; do echo "$(date) - =================================================================================" done +if "${CDR}" ; then + sleep 2 + for t in ${SCENARIOS}; do + echo "$(date) - Extract CDRs for [${GROUP}/${PROFILE}]: $t ====================================" + if ! "${BIN_DIR}/cdr_extract.sh" -t "${START_TIME}" -s "${GROUP}" "$t" ; then + echo "ERROR: $t" + error_flag=1 + fi + echo "$(date) - =================================================================================" + done +fi + echo "$(date) - Final mem stats" "${BIN_DIR}/mem_stats.py" --private_file="${MLOG_DIR}/${VERSION}_${GROUP}_final_pvm.cvs" \ --share_file="${MLOG_DIR}/${VERSION}_${GROUP}_final_shm.cvs"