From d6bd38fd169892139a62ba0e3b44dbd402635243 Mon Sep 17 00:00:00 2001 From: Victor Seva Date: Wed, 13 Apr 2016 10:29:48 +0200 Subject: [PATCH] MT#19053 support groups of scenarios * bin/config_debug.pl: - use YAML instead of YAML::Tiny - support config.yml per group Change-Id: I226cb1ef776fa147e0b4d85a5e4f9987427a51e2 --- bin/check.sh | 15 +++++++++------ bin/config_debug.pl | 45 ++++++++++++++++++++++++++++---------------- debian/control | 1 + get_results.sh | 7 ++++--- run_tests.sh | 19 ++++++++++--------- scenarios/config.yml | 9 +++++++++ 6 files changed, 62 insertions(+), 34 deletions(-) create mode 100644 scenarios/config.yml diff --git a/bin/check.sh b/bin/check.sh index dd31b1f1..ed78c51a 100755 --- a/bin/check.sh +++ b/bin/check.sh @@ -416,7 +416,7 @@ function test_filepath function usage { - echo "Usage: check.sh [-hCDRTGgJ] [-d DOMAIN ] [-p PROFILE ] check_name" + echo "Usage: check.sh [-hCDRTGgJ] [-d DOMAIN ] [-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" @@ -429,17 +429,19 @@ function usage echo -e "\t-p CE|PRO default is CE" echo -e "\t-J kamailio json output ON. PARSE skipped" echo -e "\t-K enable tcpdump capture" + 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 scenarios dir." + echo -e "\tcheck_name. Scenario name to check. This is the name of the directory on GROUP dir." } -while getopts 'hCd:p:RDTPGgJK' opt; do +while getopts 'hCd:p:Rs:DTPGgJK' opt; do case $opt in h) usage; exit 0;; C) SKIP=1;; d) DOMAIN=$OPTARG;; p) PROFILE=$OPTARG;; R) SKIP_RUNSIPP=1; SKIP_DELDOMAIN=1;; + s) GROUP=$OPTARG;; D) SKIP_DELDOMAIN=1;; T) SKIP_TESTS=1;; P) SKIP_PARSE=1;; @@ -457,16 +459,17 @@ if [[ $# != 1 ]]; then exit 1 fi +GROUP="${GROUP:-scenarios}" NAME_CHECK="$1" KAM_DIR="${KAM_DIR:-/var/run/kamailio/cfgtest}" BASE_DIR="${BASE_DIR:-/usr/share/kamailio-config-tests}" BIN_DIR="${BASE_DIR}/bin" -LOG_DIR="${BASE_DIR}/log/${NAME_CHECK}" -RESULT_DIR="${BASE_DIR}/result/${NAME_CHECK}" +LOG_DIR="${BASE_DIR}/log/${GROUP}/${NAME_CHECK}" +RESULT_DIR="${BASE_DIR}/result/${GROUP}/${NAME_CHECK}" KAM_LOG=${KAM_LOG:-"/var/log/ngcp/kamailio-proxy.log"} KAMLB_LOG=${KAMLB_LOG:-"/var/log/ngcp/kamailio-lb.log"} SEMS_LOG=${SEMS_LOG:-"/var/log/ngcp/sems.log"} -SCEN_DIR="${BASE_DIR}/scenarios" +SCEN_DIR="${BASE_DIR}/${GROUP}" SCEN_CHECK_DIR="${SCEN_DIR}/${NAME_CHECK}" DOMAIN=${DOMAIN:-"spce.test"} PROFILE="${PROFILE:-CE}" diff --git a/bin/config_debug.pl b/bin/config_debug.pl index dae1117e..32837ffe 100755 --- a/bin/config_debug.pl +++ b/bin/config_debug.pl @@ -25,13 +25,15 @@ use Getopt::Long; use strict; use Tie::File; use warnings; -use YAML::Tiny; +use YAML qw/LoadFile DumpFile/; +use Hash::Merge qw(merge); sub usage { my $output = "usage: config_debug.pl [-h] MODE DOMAIN\n"; $output .= "Options:\n"; $output .= "\t-h: this help\n"; + $output .= "\t-g: scenarios group\n"; $output .= "\tMODE: on|off\tdefault: off\n"; $output .= "\tDOMAIN: default: spce.test\n"; return $output @@ -39,7 +41,8 @@ sub usage my $help = 0; my $profile = "CE"; -GetOptions ("h|help" => \$help) +my $group = "scenarios"; +GetOptions ("h|help" => \$help, "g|group" => \$group) or die("Error in command line arguments\n".usage()); if($#ARGV>1 || $help) @@ -48,7 +51,7 @@ if($#ARGV>1 || $help) } my $base_dir; -my $yaml = YAML::Tiny->new; +my $yaml; my $file = "/etc/ngcp-config/config.yml"; my @array; my $path; @@ -89,17 +92,28 @@ if (lc($action) eq "off") else { copy($file, $file.".orig") or die "Copy failed: $ERRNO" unless(-e $file.".orig"); - $yaml = YAML::Tiny->read($file) or die "File $file could not be read"; - $yaml->[0]->{kamailio}{lb}{children} = 1; - $yaml->[0]->{kamailio}{lb}{debug} = 'yes'; - $yaml->[0]->{kamailio}{lb}{use_dns_cache} = 'off'; - $yaml->[0]->{kamailio}{proxy}{children} = 1; - $yaml->[0]->{kamailio}{proxy}{debug} = 'yes'; - $yaml->[0]->{kamailio}{proxy}{presence}{enable} = 'yes'; - $yaml->[0]->{kamailio}{proxy}{fritzbox_prefixes} = [ '112', '110', '118[0-9]{2}' ]; - $yaml->[0]->{sems}{debug} = 'yes'; - $yaml->[0]->{checktools}{sip_check_enable} = 0; - $yaml->[0]->{security}->{ngcp_panel}->{scripts}->{restapi}->{sslverify} = 'no'; + $yaml = LoadFile($file) or die "File $file could not be read"; + $yaml->{kamailio}{lb}{children} = 1; + $yaml->{kamailio}{lb}{debug} = 'yes'; + $yaml->{kamailio}{lb}{use_dns_cache} = 'off'; + $yaml->{kamailio}{proxy}{children} = 1; + $yaml->{kamailio}{proxy}{debug} = 'yes'; + $yaml->{sems}{debug} = 'yes'; + $yaml->{checktools}{sip_check_enable} = 0; + $yaml->{security}->{ngcp_panel}->{scripts}->{restapi}->{sslverify} = 'no'; + + my $group_yml_file = $base_dir."/".$group."/config.yml"; + if ( -e $group_yml_file ) + { + my $group_yml = LoadFile($group_yml_file) or + die "File $group_yml_file could not be read"; + my $hm = Hash::Merge->new('RIGHT_PRECEDENT'); + my $config = {}; + $config = $hm->merge( $config, $yaml); + $yaml = $hm->merge( $config, $group_yml); + } else { + print "$group_yml_file not found\n"; + } tie @array, 'Tie::File', '/etc/hosts' or die ('Can set test domain on /etc/hosts'); for (@array) @@ -117,8 +131,7 @@ else } untie @array; } - open(my $fh, '>', "$file") or die "Could not open $file for writing"; - print $fh $yaml->write_string() or die "Could not write YAML to $file"; + DumpFile($file, $yaml) or die "Could not write YAML to $file"; } #EOF diff --git a/debian/control b/debian/control index 18c42695..92870911 100644 --- a/debian/control +++ b/debian/control @@ -13,6 +13,7 @@ Depends: curl, libjson-perl, libtemplate-perl, libtext-csv-perl, + libyaml-perl, ngcp-provisioning-tools, parallel, python, diff --git a/get_results.sh b/get_results.sh index b87c0f4a..33d37816 100755 --- a/get_results.sh +++ b/get_results.sh @@ -4,6 +4,7 @@ export BASE_DIR=${BASE_DIR:-$RUN_DIR} BIN_DIR="${BASE_DIR}/bin" PROFILE="CE" DOMAIN="spce.test" +GROUP="${GROUP:-scenarios}" function usage { @@ -25,7 +26,7 @@ function get_scenarios flag=0 if [ -n "${SCENARIOS}" ]; then for t in ${SCENARIOS}; do - if [ ! -d "${BASE_DIR}/scenarios/$t" ]; then + if [ ! -d "${BASE_DIR}/${GROUP}/$t" ]; then echo "$(date) - scenario: $t not found" flag=1 fi @@ -34,7 +35,7 @@ function get_scenarios exit 1 fi else - SCENARIOS=$(find "${BASE_DIR}/scenarios/" -depth -maxdepth 1 -mindepth 1 \ + SCENARIOS=$(find "${BASE_DIR}/${GROUP}/" -depth -maxdepth 1 -mindepth 1 \ -type d -exec basename {} \; | grep -v templates | sort) fi } @@ -66,7 +67,7 @@ fi get_scenarios echo "${SCENARIOS}" | tr ' ' '\n' \ - | parallel "${BIN_DIR}/check.sh ${GRAPH} -J -C -R ${OPTS} -d ${DOMAIN} -p ${PROFILE}" + | parallel "${BIN_DIR}/check.sh ${GRAPH} -J -C -R ${OPTS} -d ${DOMAIN} -p ${PROFILE} -s ${GROUP}" status=$? echo "$(date) - All done[$status]" exit $status diff --git a/run_tests.sh b/run_tests.sh index e49162ea..44a6325c 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -4,7 +4,8 @@ export BASE_DIR=${BASE_DIR:-$RUN_DIR} # Set up the environment, to use local perl modules export PERL5LIB="${BASE_DIR}/lib" BIN_DIR="${BASE_DIR}/bin" -LOG_DIR="${BASE_DIR}/log" +GROUP="${GROUP:-scenarios}" +LOG_DIR="${BASE_DIR}/log/${GROUP}" MLOG_DIR="${BASE_DIR}/mem" PROFILE="CE" DOMAIN="spce.test" @@ -29,8 +30,8 @@ function get_scenarios flag=0 if [ -n "${SCENARIOS}" ]; then for t in ${SCENARIOS}; do - if [ ! -d "${BASE_DIR}/scenarios/$t" ]; then - echo "$(date) - scenario: $t not found" + if [ ! -d "${BASE_DIR}/${GROUP}/$t" ]; then + echo "$(date) - scenario: $t at ${GROUP} not found" flag=1 fi done @@ -38,7 +39,7 @@ function get_scenarios exit 1 fi else - SCENARIOS=$(find "${BASE_DIR}/scenarios/" -depth -maxdepth 1 -mindepth 1 \ + SCENARIOS=$(find "${BASE_DIR}/${GROUP}/" -depth -maxdepth 1 -mindepth 1 \ -type d -exec basename {} \; | grep -v templates | sort) fi } @@ -108,8 +109,8 @@ fi echo "$(date) - Initial mem stats" VERSION="${PROFILE}_$(cut -f1 -d' '< /etc/ngcp_version)_" -"${BIN_DIR}/mem_stats.py" --private_file="${MLOG_DIR}/${VERSION}initial_pvm.cvs" \ - --share_file="${MLOG_DIR}/${VERSION}initial_shm.cvs" +"${BIN_DIR}/mem_stats.py" --private_file="${MLOG_DIR}/${VERSION}_${GROUP}_initial_pvm.cvs" \ + --share_file="${MLOG_DIR}/${VERSION}_${GROUP}_initial_shm.cvs" get_scenarios @@ -125,7 +126,7 @@ for t in ${SCENARIOS}; do echo "$(date) - Clean log dir" rm -rf "${log_temp}" fi - if ! "${BIN_DIR}/check.sh" ${OPTS} -J -P -T -d ${DOMAIN} -p "${PROFILE}" "$t" ; then + if ! "${BIN_DIR}/check.sh" ${OPTS} -J -P -T -d ${DOMAIN} -p "${PROFILE}" -s "${GROUP}" "$t" ; then echo "ERROR: $t" error_flag=1 fi @@ -133,8 +134,8 @@ for t in ${SCENARIOS}; do done echo "$(date) - Final mem stats" -"${BIN_DIR}/mem_stats.py" --private_file="${MLOG_DIR}/${VERSION}final_pvm.cvs" \ - --share_file="${MLOG_DIR}/${VERSION}final_shm.cvs" +"${BIN_DIR}/mem_stats.py" --private_file="${MLOG_DIR}/${VERSION}_${GROUP}_final_pvm.cvs" \ + --share_file="${MLOG_DIR}/${VERSION}_${GROUP}_final_shm.cvs" cfg_debug_off diff --git a/scenarios/config.yml b/scenarios/config.yml new file mode 100644 index 00000000..d2d0b077 --- /dev/null +++ b/scenarios/config.yml @@ -0,0 +1,9 @@ +kamailio: + proxy: + presence: + enable: 'yes' + fritzbox: + prefixes: + - '112' + - '110' + - '118[0-9]{2}'