TT#70351 change /etc/hosts via ngcpcfg

Since TT#47256 /etc/hosts is managed via ngcpcfg, so lets don't touch it
directly anymore

Change-Id: If6d5e72322ce5984836d67739514d75345c643eb
changes/20/35120/2
Victor Seva 7 years ago
parent a6a352d62a
commit 4fb43d47cd
No known key found for this signature in database
GPG Key ID: 2174A68E7DA82CC7

@ -60,7 +60,9 @@ if($#ARGV>1 || $help)
my $base_dir; my $base_dir;
my $yaml; my $yaml;
my $file = "/etc/ngcp-config/config.yml"; my $net_yaml;
my $file_yaml = '/etc/ngcp-config/config.yml';
my $file_net_yaml = '/etc/ngcp-config/network.yml';
my @array; my @array;
my $path; my $path;
if (exists $ENV{'BASE_DIR'}) if (exists $ENV{'BASE_DIR'})
@ -79,13 +81,9 @@ $domain = 'spce.test' unless defined($domain);
if (lc($action) eq "off") if (lc($action) eq "off")
{ {
move("$file.orig", $file) or die "Can't restore the orig config"; for my $file ($file_yaml, $file_net_yaml) {
tie @array, 'Tie::File', '/etc/hosts' or die ('Can set test domain on /etc/hosts'); move("$file.orig", $file) or die "Can't restore the orig config $file";
for (@array)
{
s/\Q$domain\E//;
} }
untie @array;
for my $i ('caller.csv', 'callee.csv') for my $i ('caller.csv', 'callee.csv')
{ {
$path = File::Spec->catfile( $base_dir, 'scenarios', $i); $path = File::Spec->catfile( $base_dir, 'scenarios', $i);
@ -99,8 +97,10 @@ if (lc($action) eq "off")
} }
else else
{ {
cp($file, $file.".orig") or die "Copy failed: $ERRNO" unless(-e $file.".orig"); for my $file ($file_yaml, $file_net_yaml) {
$yaml = LoadFile($file); cp($file, $file.".orig") or die "Copy $file failed: $ERRNO" unless(-e $file.".orig");
}
$yaml = LoadFile($file_yaml);
$yaml->{kamailio}{lb}{cfgt} = 'yes'; $yaml->{kamailio}{lb}{cfgt} = 'yes';
$yaml->{kamailio}{lb}{dns}{use_dns_cache} = 'off'; $yaml->{kamailio}{lb}{dns}{use_dns_cache} = 'off';
$yaml->{kamailio}{proxy}{children} = 1; $yaml->{kamailio}{proxy}{children} = 1;
@ -111,6 +111,13 @@ else
$yaml->{security}->{ngcp_panel}->{scripts}->{restapi}->{sslverify} = 'no'; $yaml->{security}->{ngcp_panel}->{scripts}->{restapi}->{sslverify} = 'no';
$yaml->{mediator}{interval} = '1'; $yaml->{mediator}{interval} = '1';
$net_yaml = LoadFile($file_net_yaml);
$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);
my $group_yml_file = $base_dir."/".$group."/config.yml"; my $group_yml_file = $base_dir."/".$group."/config.yml";
if ( -e $group_yml_file ) if ( -e $group_yml_file )
{ {
@ -124,11 +131,6 @@ else
print "$group_yml_file not found\n"; print "$group_yml_file not found\n";
} }
tie @array, 'Tie::File', '/etc/hosts' or die ('Can set test domain on /etc/hosts');
for (@array)
{
s/127.0.0.1[ \t]+localhost/127.0.0.1 localhost $domain/ unless($_ =~ /$domain/);
}
untie @array; untie @array;
for my $i ('caller.csv', 'callee.csv') for my $i ('caller.csv', 'callee.csv')
{ {
@ -140,7 +142,7 @@ else
} }
untie @array; untie @array;
} }
DumpFile($file, $yaml); DumpFile($file_yaml, $yaml);
} }
#EOF #EOF

Loading…
Cancel
Save