From c2df9cfa1474a4b2080f539da04b1714c0cb14cf Mon Sep 17 00:00:00 2001 From: Victor Seva Date: Fri, 15 May 2020 11:40:02 +0200 Subject: [PATCH] TT#81700 generate_test_tt2.pl: add option to replace uuids from scenario_ids.yml file > # ./bin/generate_test_tt2.pl -f Route -f Call-id -f via -f expires -f max-forwards -i log/scenarios/invite/scenario_ids.yml log/scenarios/invite/0005.json > /tmp/out_1.tt2 > # ./bin/generate_test_tt2.pl -f Route -f Call-id -f via -f expires -f max-forwards log/scenarios/invite/0005.json > /tmp/out.tt2 > # diff -uN /tmp/out.tt2 /tmp/out_1.tt2 > --- /tmp/out.tt2 2020-05-15 11:42:37.114319685 +0200 > +++ /tmp/out_1.tt2 2020-05-15 11:42:26.850316458 +0200 > @@ -191,7 +191,7 @@ > 'P-NGCP-Authorization: testuser1002@spce.test', > 'P-NGCP-Authorized: 1', > 'P-NGCP-Caller-Info: ;ip=127.126.0.1;port=51602;primary=4311002', > - 'P-Caller-UUID: 86399f34-7385-4f4c-b829-70cb7ef9f466', > + 'P-Caller-UUID: [% spce_test.testuser1002.uuid %]', > 'Server: Sipwise NGCP Proxy 8.X', > 'Content-Length: 0', > ] > @@ -204,8 +204,8 @@ > 'Content-Type: application/sdp', > 'Content-Length: 176', > 'P-LB-Uptime: 1103', > - 'P-Caller-UUID: 86399f34-7385-4f4c-b829-70cb7ef9f466', > - 'P-Callee-UUID: e2ccfb8b-93ce-4472-99b5-9d39548c95e7', > + 'P-Caller-UUID: [% spce_test.testuser1002.uuid %]', > + 'P-Callee-UUID: [% spce_test.testuser1003.uuid %]', > 'P-Asserted-Identity: ', > 'P-Called-Party-ID: ', > 'P-App-Param: ;calltimer=21600;aleg_sst_enable=no;sst_enable=no;hold_alter_b2b_bleg=no;hold_alter_b2b_aleg=no', Change-Id: I3d0e577c7ac4f28f599b7afb0f4e746232e40415 --- bin/generate_test_tt2.pl | 72 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 67 insertions(+), 5 deletions(-) diff --git a/bin/generate_test_tt2.pl b/bin/generate_test_tt2.pl index 55249cca..ff7e5ffd 100755 --- a/bin/generate_test_tt2.pl +++ b/bin/generate_test_tt2.pl @@ -28,6 +28,7 @@ use Getopt::Long; use English; use utf8; use JSON; +use Scalar::Util qw(reftype); sub usage { @@ -35,13 +36,69 @@ sub usage $output .= "\tOptions:\n"; $output .= "-h --help: this help\n"; $output .= "-f --filter: remove this header ( can be used multiple times )\n"; + $output .= "-i --ids: subst ids present in scenarios_ids.yml file\n"; return $output } +sub load_ids +{ + my $yml = LoadFile($_[0]); + my $res = {}; + get_uuid($yml, "", $res); + return $res; +} + +sub get_uuid +{ + my $data = shift; + my $str_key = shift; + my $res = shift; + foreach my $key (sort keys %{$data}) { + my $new_key = ${str_key} ? "${str_key}.${key}" : "${key}"; + if($key eq 'uuid') { + $res->{$data->{$key}} = $new_key; + } else { + my $_type = defined(reftype($data->{$key})) ? reftype($data->{$key}) : ""; + if( $_type eq 'HASH') { + get_uuid($data->{$key}, $new_key, $res); + } + } + } + return $res; +} + +my $uuids; +sub subst_uuids +{ + my $line = shift; + + foreach my $uuid (sort keys %{$uuids}) { + if($line =~ s/\Q${uuid}\E/[% $uuids->{$uuid} %]/g) { + return $line; + } + } + return $line; +} +sub print_header +{ + my $_type = shift; + my $_l = shift; + my $line = $_l; + + if($uuids) { + $line = subst_uuids($_l); + } + if($_type eq 'sip_in') { + print " - '$line'\n"; + } else { + print " '$line',\n"; + } +} + my @headers; sub filter_header { - my $line = $_[0]; + my $line = shift; foreach my $header (@headers) { if ($line =~ /${header}:/i) { return 1; @@ -50,9 +107,9 @@ sub filter_header return 0; } -my $yml = ''; my $help = 0; -GetOptions ("h|help" => \$help, "f|filter=s" => \@headers) +my $f_ids; +GetOptions ("h|help" => \$help, "f|filter=s" => \@headers, "i|ids=s" => \$f_ids) or die("Error in command line arguments\n".usage()); if($#ARGV!=0 || $help) @@ -68,6 +125,11 @@ my $json; close $fh; } my $inlog = decode_json($json); + +if($f_ids) { + $uuids = load_ids(abs_path($f_ids)); +} + print "flow:\n"; foreach my $i (@{$inlog->{'flow'}}) { @@ -84,7 +146,7 @@ foreach my $i (@{$inlog->{'sip_in'}}) { if($l) { if(!filter_header($l)) { - print " - '$l'\n"; + print_header('sip_in', $l); } } else { # we don't care about SDP @@ -101,7 +163,7 @@ foreach my $i (@{$inlog->{'sip_out'}}) { if($l) { if(!filter_header($l)) { - print " '$l',\n"; + print_header('sip_out', $l); } } else { # we don't care about SDP