From b3219d242db71266f26cca3254d962ba55e710b1 Mon Sep 17 00:00:00 2001 From: Victor Seva Date: Wed, 31 Mar 2021 14:52:49 +0200 Subject: [PATCH] TT#116100 bin/create_registrations.pl: use scenario_ids.yml * IP/port info is already there, no need to split creation/update Change-Id: I63d080bbc1192af7c7c276eed5fff7ebde95ef75 --- bin/check.sh | 10 ---------- bin/create_registrations.pl | 39 +++++++++++++++++++++++++++++++++++-- bin/provide_scenario.sh | 1 + 3 files changed, 38 insertions(+), 12 deletions(-) diff --git a/bin/check.sh b/bin/check.sh index 9a9a4818..16eb64f9 100755 --- a/bin/check.sh +++ b/bin/check.sh @@ -352,8 +352,6 @@ get_ip() { port=${scen[3]} mport=${scen[4]} foreign_dom=${scen[6]} - registration=${scen[7]} - subscriber=${scen[8]} done< <(grep "$1" "${SCEN_CHECK_DIR}/scenario.csv") } @@ -433,14 +431,6 @@ run_sipp() { echo "$(date) - foreign domain detected... using 5060 port" port="5060" fi - if [ "${registration}" == "permanent" ]; then - echo "$(date) - Update permanent reg:${subscriber} ${ip}:${port} info" - if ! "${BIN_DIR}/update_perm_reg.pl" \ - -t "${transport}" "${subscriber}" "${ip}" "${port}"; - then - error_helper "$(date) - error updating peer info" 15 - fi - fi if [ -f "${SCEN_CHECK_DIR}/${base}_reg.xml" ]; then echo "$(date) - Register ${base} ${ip}:${port}-${mport}" diff --git a/bin/create_registrations.pl b/bin/create_registrations.pl index d5519d33..38f5bdc6 100755 --- a/bin/create_registrations.pl +++ b/bin/create_registrations.pl @@ -1,6 +1,6 @@ #!/usr/bin/perl # -# Copyright: 2013-2016 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 @@ -39,16 +39,20 @@ if ($config) { my $api = Sipwise::API->new($opts); $opts = $api->opts; my $del = 0; +my $ids = {}; sub usage { return "Usage:\n$PROGRAM_NAME registrations.yml\n". "Options:\n". + " -ids scenario_ids.yml file\n". " -delete\n". " -d debug\n". " -h this help\n"; } my $help = 0; +my $ids_path; GetOptions ("h|help" => \$help, + "ids=s" => \$ids_path, "d|debug" => \$opts->{verbose}, "delete" => \$del) or die("Error in command line arguments\n".usage()); @@ -56,6 +60,14 @@ GetOptions ("h|help" => \$help, die(usage()) unless (!$help); die("Error: wrong number of arguments\n".usage()) unless ($#ARGV == 0); +sub key_domain +{ + my $domain = shift; + + my $key_dom = $domain =~ tr/\./_/r; + return $key_dom =~ tr/\-/_/r; +} + sub delete_regs { my $subscriber = shift; @@ -71,6 +83,25 @@ sub delete_regs return; } +sub contact +{ + my $subscriber = shift; + my $domain = shift; + my $key_dom = key_domain($domain); + + foreach my $scen (@{$ids->{scenarios}}) + { + foreach my $resp (@{$scen->{responders}}) + { + if( $resp->{username} eq $subscriber && $resp->{domain} eq $domain) + { + return "sip:$resp->{ip}:$resp->{port}"; + } + } + } + die("can't find ${subscriber}\@${domain} on scenarios\n"); +} + sub create_regs { my $subscriber = shift; @@ -83,8 +114,9 @@ sub create_regs foreach my $r (@{$data}) { $r->{subscriber_id} = $subs_id; + $r->{contact} = contact($subscriber, $domain); my $id = $api->create_subscriber_registration($r); - print "registration: ${subscriber}[${subs_id}] created [${id}]\n"; + print "registration: ${subscriber}[${subs_id}] created as $r->{contact} [${id}]\n"; } } else { @@ -126,6 +158,9 @@ sub main { print "delete registrations\n" unless $opts->{debug}; return do_delete($r); } else { + die("scenario_ids.yml needed, use -ids option\n") unless defined($ids_path); + print "load ${ids_path}\n" unless $opts->{debug}; + $ids = LoadFile($ids_path); print "create registrations\n" unless $opts->{debug}; return do_create($r); } diff --git a/bin/provide_scenario.sh b/bin/provide_scenario.sh index 0d2dd0b2..89e1279e 100755 --- a/bin/provide_scenario.sh +++ b/bin/provide_scenario.sh @@ -57,6 +57,7 @@ create_voip() { if [ -f "${SCEN_CHECK_DIR}/registration.yml" ]; then echo "$(date) - Creating permanent registrations" "${BIN_DIR}/create_registrations.pl" \ + -ids "${SCEN_CHECK_DIR}/scenario_ids.yml" \ "${SCEN_CHECK_DIR}/registration.yml" fi }