TT#116100 bin/config_debug.pl: split logic

* changes to network.yml on its own script
* remove unnecessary DOMAIN parameter

Change-Id: I824c7320ca9217f2d9175231646788bb039bb019
mr9.4
Victor Seva 5 years ago
parent 935bf89d4b
commit 2be72bb3e2
No known key found for this signature in database
GPG Key ID: B1589889727198E0

@ -66,6 +66,7 @@ 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
(
cd /etc/ngcp-config || true
ngcpcfg apply "k-c-t ${GROUP} on"
@ -97,6 +98,7 @@ 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
(
cd /etc/ngcp-config || true
ngcpcfg apply "k-c-t ${GROUP} off"

@ -29,13 +29,12 @@ use Hash::Merge qw(merge);
sub usage
{
my $output = "usage: config_debug.pl [-hgc] MODE DOMAIN\n";
my $output = "usage: config_debug.pl [-hgc] 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 .= "\tMODE: on|off\tdefault: off\n";
$output .= "\tDOMAIN: default: spce.test\n";
return $output
}
@ -62,42 +61,16 @@ if($#ARGV>1 || $help)
die("Wrong number of arguments\n".usage())
}
my $base_dir;
my $base_dir = '/usr/share/kamailio-config-tests';
my $file_yaml = '/etc/ngcp-config/config.yml';
my $file_net_yaml = '/etc/ngcp-config/network.yml';
my ($action, $domain) = @ARGV;
my ($action) = @ARGV;
$action = 'off' unless defined($action);
$domain = 'spce.test' unless defined($domain);
if (exists $ENV{'BASE_DIR'})
{
$base_dir = $ENV{'BASE_DIR'};
}
else
{
$base_dir = '/usr/share/kamailio-config-tests';
}
sub change_network
{
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',
type => ['rtp_tag']
};
push @{$net_yaml->{hosts}->{$host}->{interfaces}}, 'dummy0';
}
$net_yaml->{hosts_common}->{etc_hosts_global_extra_entries} //= ();
my $entries = $net_yaml->{hosts_common}->{etc_hosts_global_extra_entries};
push @{$entries}, "127.0.0.1 $domain";
$net_yaml->{hosts_common}->{etc_hosts_global_extra_entries} = $entries;
DumpFile($file_net_yaml, $net_yaml);
}
sub change_config
{
@ -134,17 +107,12 @@ sub change_config
if (lc($action) eq "off")
{
for my $file ($file_yaml, $file_net_yaml) {
move("$file.orig", $file) or die "Can't restore the orig config $file";
}
move("${file_yaml}.orig", $file_yaml) or die "Can't restore the orig config ${file_yaml}";
}
else
{
for my $file ($file_yaml, $file_net_yaml) {
cp($file, $file.".orig") or die "Copy $file failed: $ERRNO" unless(-e $file.".orig");
}
cp($file_yaml, "${file_yaml}.orig") or die "Copy $file_yaml failed: $ERRNO" unless(-e "${file_yaml}.orig");
change_config();
change_network();
}
#EOF

@ -0,0 +1,113 @@
#!/usr/bin/perl
#
# Copyright: 2021 Sipwise Development Team <support@sipwise.com>
#
# 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 <http://www.gnu.org/licenses/>.
#
# 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 English;
use File::Copy qw(cp move);
use File::Spec;
use Getopt::Long;
use strict;
use warnings;
use YAML::XS qw(LoadFile DumpFile);
use Hash::Merge qw(merge);
sub usage
{
my $output = "usage: $PROGRAM_NAME [-hg] MODE\n";
$output .= "Options:\n";
$output .= "\t-h: this help\n";
$output .= "\t-g: scenarios group\n";
$output .= "\tMODE: on|off\tdefault: off\n";
return $output
}
my $help = 0;
my $group;
if (exists $ENV{'GROUP'})
{
$group = $ENV{'GROUP'};
}
else
{
$group = "scenarios";
}
GetOptions (
"h|help" => \$help,
"g|group=s" => \$group)
or die("Error in command line arguments\n".usage());
if($#ARGV>0 || $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;
$action = 'off' unless defined($action);
if (exists $ENV{'BASE_DIR'})
{
$base_dir = $ENV{'BASE_DIR'};
}
sub get_domains
{
my $entries = shift;
push @{$entries}, "127.0.0.1 spce.test";
return $entries;
}
sub change_network
{
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',
type => ['rtp_tag']
};
push @{$net_yaml->{hosts}->{$host}->{interfaces}}, 'dummy0';
}
$net_yaml->{hosts_common}->{etc_hosts_global_extra_entries} //= ();
my $entries = $net_yaml->{hosts_common}->{etc_hosts_global_extra_entries};
$entries = get_domains($entries);
$net_yaml->{hosts_common}->{etc_hosts_global_extra_entries} = $entries;
DumpFile($file_net_yaml, $net_yaml);
}
if (lc($action) eq "off")
{
for my $file ($file_net_yaml) {
move("$file.orig", $file) or die "Can't restore the orig config $file";
}
}
else
{
for my $file ($file_net_yaml) {
cp($file, $file.".orig") or die "Copy $file failed: $ERRNO" unless(-e $file.".orig");
}
change_network();
}
#EOF

@ -58,7 +58,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 ${DOMAIN}
"${BIN_DIR}/config_debug.pl" -g "${GROUP}" off
echo "$(date) - Setting network config off"
"${BIN_DIR}/network_config.pl" -g "${GROUP}" off
if ! ngcpcfg apply "config debug off via kamailio-config-tests" ; then
echo "$(date) - ngcpcfg apply returned $?"
error_flag=4
@ -312,7 +314,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 ${DOMAIN}
"${BIN_DIR}/config_debug.pl" -c 5 -g "${GROUP}" on
echo "$(date) - Setting network config"
"${BIN_DIR}/network_config.pl" -g "${GROUP}" on
if [ "${PROFILE}" == "PRO" ]; then
echo "$(date) - Exec pid_watcher with timeout[${TIMEOUT}]"
( timeout "${TIMEOUT}" "${BIN_DIR}/pid_watcher.py" ${PIDWATCH_OPTS} )&

@ -6,7 +6,6 @@ export BASE_DIR=${BASE_DIR:-$RUN_DIR}
export PERL5LIB="${BASE_DIR}/lib"
BIN_DIR="${BASE_DIR}/bin"
GROUP="${GROUP:-scenarios}"
DOMAIN="spce.test"
usage() {
echo "Usage: set_config.sh [-h] [-x GROUP]"
@ -32,7 +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" -g "${GROUP}" on ${DOMAIN}
"${BIN_DIR}/config_debug.pl" -c 5 -g "${GROUP}" on
echo "$(date) - Setting network config"
"${BIN_DIR}/network_config.pl" -g "${GROUP}" on
cd /etc/ngcp-config || exit 3
if ! ngcpcfg apply "config debug on via kamailio-config-tests" ; then
echo "$(date) - ngcpcfg apply returned $?"

Loading…
Cancel
Save