From e73808567978a89af9f4acd9282b568ea672465d Mon Sep 17 00:00:00 2001 From: Victor Seva Date: Tue, 27 Apr 2021 11:02:43 +0200 Subject: [PATCH] TT#116100 config: add kamailio and rtpengine info * bin/config_debug.pl: use values from config.yml * bin/network_config.pl: use values from config.yml * bin/generate_test.pl: provide config.yml at "config" key * bin/provide_scenario.sh: pass "config" option to generate_test.pl Change-Id: I4ba62267b372b638f85dde62ecced6bd7d15c142 --- bench.sh | 14 +++++++------- bin/config_debug.pl | 23 +++++++++++++++-------- bin/generate_test.pl | 21 ++++++++++++++++++--- bin/network_config.pl | 20 ++++++++++++-------- bin/provide_scenario.sh | 1 + config.yml | 16 ++++++++++++++++ run_tests.sh | 8 ++++---- set_config.sh | 4 ++-- 8 files changed, 75 insertions(+), 32 deletions(-) diff --git a/bench.sh b/bench.sh index 595a6acc..f963410d 100755 --- a/bench.sh +++ b/bench.sh @@ -63,10 +63,10 @@ BASE_DIR=$(pwd) export BASE_DIR if ! "${SKIP_CONFIG}" ; then - export PERL5LIB="${BASE_DIR}/lib" - echo "add configuration for tests" - ./bin/config_debug.pl -c 5 -g "${GROUP}" on - ./bin/network_config.pl -g "${GROUP}" on + export PERL5LIB="${BASE_DIR}/lib" + echo "add configuration for tests" + ./bin/config_debug.pl -c 5 -g "${GROUP}" "${BASE_DIR}/config.yml" on + ./bin/network_config.pl -g "${GROUP}" "${BASE_DIR}/config.yml" on ( cd /etc/ngcp-config || true ngcpcfg --summary-only apply "k-c-t ${GROUP} on" @@ -96,9 +96,9 @@ done set +o pipefail if ! "${SKIP_CONFIG}" ; then - echo "remove configuration for tests" - ./bin/config_debug.pl -g"${GROUP}" off - ./bin/network_config.pl -g"${GROUP}" off + echo "remove configuration for tests" + ./bin/config_debug.pl -g"${GROUP}" "${BASE_DIR}/config.yml" off + ./bin/network_config.pl -g"${GROUP}" "${BASE_DIR}/config.yml" off ( cd /etc/ngcp-config || true ngcpcfg --summary-only apply "k-c-t ${GROUP} off" diff --git a/bin/config_debug.pl b/bin/config_debug.pl index 6fcca5c6..c4dcffae 100755 --- a/bin/config_debug.pl +++ b/bin/config_debug.pl @@ -1,6 +1,6 @@ #!/usr/bin/perl # -# Copyright: 2013 Sipwise Development Team +# 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 @@ -29,11 +29,12 @@ use Hash::Merge qw(merge); sub usage { - my $output = "usage: config_debug.pl [-hgc] MODE\n"; + my $output = "usage: $PROGRAM_NAME [-hgc] kct_config.yml MODE\n"; $output .= "Options:\n"; $output .= "\t-h: this help\n"; $output .= "\t-g: scenarios group\n"; $output .= "\t-c: number of kamailio.proxy.children\n"; + $output .= "\tkct_config.yml: config file for k-c-t environment\n"; $output .= "\tMODE: on|off\tdefault: off\n"; return $output } @@ -53,8 +54,8 @@ else GetOptions ( "h|help" => \$help, "g|group=s" => \$group, - "c|children=i" => \$children) - or die("Error in command line arguments\n".usage()); + "c|children=i" => \$children, +) or die("Error in command line arguments\n".usage()); if($#ARGV>1 || $help) { @@ -63,7 +64,7 @@ if($#ARGV>1 || $help) my $base_dir = '/usr/share/kamailio-config-tests'; my $file_yaml = '/etc/ngcp-config/config.yml'; -my ($action) = @ARGV; +my ($kct_conf_yaml, $action) = @ARGV; $action = 'off' unless defined($action); @@ -74,11 +75,15 @@ if (exists $ENV{'BASE_DIR'}) sub change_config { + my $kct_conf = shift; my $yaml = LoadFile($file_yaml); + my $es_test = $kct_conf->{kamailio}->{lb}->{extra_sockets}->{test}; + my $es_other = $kct_conf->{kamailio}->{lb}->{extra_sockets}->{other}; + $yaml->{kamailio}{lb}{cfgt} = 'yes'; $yaml->{kamailio}{lb}{dns}{use_dns_cache} = 'off'; - $yaml->{kamailio}{lb}{extra_sockets}->{test} = "udp:127.2.0.1:5064"; - $yaml->{kamailio}{lb}{extra_sockets}->{other} = "tcp:127.3.0.1:5074"; + $yaml->{kamailio}{lb}{extra_sockets}->{test} = "$es_test->{transport}:$es_test->{ip}:$es_test->{port}"; + $yaml->{kamailio}{lb}{extra_sockets}->{other} = "$es_other->{transport}:$es_other->{ip}:$es_other->{port}";; $yaml->{kamailio}{proxy}{children} = $children if($children > 0); $yaml->{kamailio}{proxy}{permissions_reload_delta} = 0; $yaml->{kamailio}{proxy}{cfgt} = 'yes'; @@ -112,7 +117,9 @@ if (lc($action) eq "off") else { cp($file_yaml, "${file_yaml}.orig") or die "Copy $file_yaml failed: $ERRNO" unless(-e "${file_yaml}.orig"); - change_config(); + print "loading $kct_conf_yaml\n"; + my $kct_conf = LoadFile($kct_conf_yaml); + change_config($kct_conf); } #EOF diff --git a/bin/generate_test.pl b/bin/generate_test.pl index fc271558..510c0b69 100755 --- a/bin/generate_test.pl +++ b/bin/generate_test.pl @@ -1,6 +1,6 @@ #!/usr/bin/perl # -# Copyright: 2016 Sipwise Development Team +# Copyright: 2016-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 @@ -31,13 +31,26 @@ sub usage $output .= "Options:\n"; $output .= "\t-h: this help\n"; $output .= "\t-p: PRO scenario\n"; + $output .= "\t-c: k-c-t config.yml\n"; return $output } +my $base_dir = '/usr/share/kamailio-config-tests'; my $help = 0; my $PRO = 0; -GetOptions ("h|help" => \$help, "p|pro" =>\$PRO) - or die("Error in command line arguments\n".usage()); +my $kct_conf_yaml = undef; + +GetOptions ( + "h|help" => \$help, + "p|pro" =>\$PRO, + "c|config=s" =>\$kct_conf_yaml, +) or die("Error in command line arguments\n".usage()); + +if (exists $ENV{'BASE_DIR'}) +{ + $base_dir = $ENV{'BASE_DIR'}; +} +$kct_conf_yaml = "${base_dir}/config.yml" unless(defined($kct_conf_yaml)); die(usage()) unless (!$help); die("Wrong number of arguments\n".usage()) unless ($#ARGV == 1); @@ -48,6 +61,8 @@ if($PRO) { } else { $ids->{CE} = 1; } +${ids}->{config} = LoadFile($kct_conf_yaml); + my $template = Template->new({ABSOLUTE => 1}); $template->process(abs_path($ARGV[0]), $ids) or die $template->error(); diff --git a/bin/network_config.pl b/bin/network_config.pl index 8a26b23f..6c4248d2 100755 --- a/bin/network_config.pl +++ b/bin/network_config.pl @@ -30,10 +30,11 @@ use Hash::Merge qw(merge); sub usage { - my $output = "usage: $PROGRAM_NAME [-hg] MODE\n"; + my $output = "usage: $PROGRAM_NAME [-hg] kct_config.yml MODE\n"; $output .= "Options:\n"; $output .= "\t-h: this help\n"; $output .= "\t-g: scenarios group\n"; + $output .= "\tkct_config.yml: config file for k-c-t environment\n"; $output .= "\tMODE: on|off\tdefault: off\n"; return $output } @@ -54,14 +55,14 @@ GetOptions ( "g|group=s" => \$group) or die("Error in command line arguments\n".usage()); -if($#ARGV>0 || $help) +if($#ARGV>1 || $help) { die("Wrong number of arguments\n".usage()) } my $base_dir = '/usr/share/kamailio-config-tests'; my $file_net_yaml = '/etc/ngcp-config/network.yml'; -my ($action) = @ARGV; +my ($kct_conf_yaml, $action) = @ARGV; $action = 'off' unless defined($action); @@ -72,7 +73,7 @@ if (exists $ENV{'BASE_DIR'}) sub get_domains { - my $ip = "127.0.0.1"; + my $ip = shift; my $entries = shift; my @scenarios = qx{${base_dir}/bin/get_scenarios.sh -x ${group}}; my @domains = (); @@ -94,12 +95,13 @@ sub get_domains sub change_network { + my $kct_conf = shift; my $net_yaml = LoadFile($file_net_yaml); for my $host (keys %{$net_yaml->{hosts}}) { $net_yaml->{hosts}->{$host}->{dummy0} = { - ip => '172.30.1.2', - netmask => '255.255.255.0', + ip => $kct_conf->{rtpengine}->{rtp_flag}->{ip}, + netmask => $kct_conf->{rtpengine}->{rtp_flag}->{netmask}, type => ['rtp_tag'] }; push @{$net_yaml->{hosts}->{$host}->{interfaces}}, 'dummy0'; @@ -107,7 +109,7 @@ sub change_network $net_yaml->{hosts_common}->{etc_hosts_global_extra_entries} //= (); my $entries = $net_yaml->{hosts_common}->{etc_hosts_global_extra_entries}; - $entries = get_domains($entries); + $entries = get_domains($kct_conf->{kamailio}->{lb}->{ip}, $entries); $net_yaml->{hosts_common}->{etc_hosts_global_extra_entries} = $entries; DumpFile($file_net_yaml, $net_yaml); } @@ -123,7 +125,9 @@ else for my $file ($file_net_yaml) { cp($file, $file.".orig") or die "Copy $file failed: $ERRNO" unless(-e $file.".orig"); } - change_network(); + print "loading $kct_conf_yaml\n"; + my $kct_conf = LoadFile($kct_conf_yaml); + change_network($kct_conf); } #EOF diff --git a/bin/provide_scenario.sh b/bin/provide_scenario.sh index 2a9e267f..c14f8c94 100755 --- a/bin/provide_scenario.sh +++ b/bin/provide_scenario.sh @@ -178,6 +178,7 @@ generate_template() { local base=$1 if [ -f "${SCEN_CHECK_DIR}/${base}.tt2" ]; then if ! "${BIN_DIR}/generate_test.pl" \ + --config="${BASE_DIR}/config.yml" \ "${SCEN_CHECK_DIR}/${base}.tt2" \ "${SCEN_CHECK_DIR}/scenario_ids.yml" > "${SCEN_CHECK_DIR}/${base}" then diff --git a/config.yml b/config.yml index d838809e..2563ab40 100644 --- a/config.yml +++ b/config.yml @@ -7,6 +7,22 @@ peer: ip: 127.0.2.1 port: 51602 mport: 45003 +kamailio: + lb: + ip: 127.0.0.1 + extra_sockets: + test: + transport: udp + ip: 127.2.0.1 + port: 5064 + other: + transport: tcp + ip: 127.3.0.1 + port: 5074 +rtpengine: + rtp_flag: + ip: 172.30.1.2 + netmask: 255.255.255.0 phone: cc: 43 ac: 1 diff --git a/run_tests.sh b/run_tests.sh index a29dd153..a8e58032 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -45,9 +45,9 @@ cfg_debug_off() { echo "$(date) - Removed apicert.pem" rm -f "${BASE_DIR}/apicert.pem" echo "$(date) - Setting config debug off" - "${BIN_DIR}/config_debug.pl" -g "${GROUP}" off + "${BIN_DIR}/config_debug.pl" -g "${GROUP}" "${BASE_DIR}/config.yml" off echo "$(date) - Setting network config off" - "${BIN_DIR}/network_config.pl" -g "${GROUP}" off + "${BIN_DIR}/network_config.pl" -g "${GROUP}" "${BASE_DIR}/config.yml" off dummy_ip=$(ip addr show dummy0 | grep inet | awk '{print $2}' | head -1) if [ -n "${dummy_ip}" ]; then echo "$(date) - start dummy0 interface" @@ -310,9 +310,9 @@ mkdir -p "${MLOG_DIR}" "${LOG_DIR}" if ! "${SKIP_CONFIG}" ; then echo "$(date) - Setting config debug on" - "${BIN_DIR}/config_debug.pl" -c 5 -g "${GROUP}" on + "${BIN_DIR}/config_debug.pl" -c 5 -g "${GROUP}" "${BASE_DIR}/config.yml" on echo "$(date) - Setting network config" - "${BIN_DIR}/network_config.pl" -g "${GROUP}" on + "${BIN_DIR}/network_config.pl" -g "${GROUP}" "${BASE_DIR}/config.yml" on if [ "${PROFILE}" == "PRO" ]; then echo "$(date) - Exec pid_watcher with timeout[${TIMEOUT}]" ( timeout "${TIMEOUT}" "${BIN_DIR}/pid_watcher.py" ${PIDWATCH_OPTS} )& diff --git a/set_config.sh b/set_config.sh index c90638f4..b713c6c8 100755 --- a/set_config.sh +++ b/set_config.sh @@ -31,9 +31,9 @@ error_flag=0 echo "$(date) - Removed apicert.pem" rm -f "${BASE_DIR}/apicert.pem" echo "$(date) - Setting config debug on" -"${BIN_DIR}/config_debug.pl" -c 5 -g "${GROUP}" on +"${BIN_DIR}/config_debug.pl" -c 5 -g "${GROUP}" "${BASE_DIR}/config.yml" on echo "$(date) - Setting network config" -"${BIN_DIR}/network_config.pl" -g "${GROUP}" on +"${BIN_DIR}/network_config.pl" -g "${GROUP}" "${BASE_DIR}/config.yml" on cd /etc/ngcp-config || exit 3 if ! ngcpcfg --summary-only apply "config debug on via kamailio-config-tests" ; then echo "$(date) - ngcpcfg apply returned $?"