MT#54408 NGCP::Template::Object: Add spN support to get_*pairname()

These functions still had old assumptions about the number of nodes in a
"pair".

Change-Id: I29f03b9287c2b5e673f414192b0dff83300d850c
mr11.1
Guillem Jover 3 years ago
parent d29432342d
commit 783862cfc8

@ -128,11 +128,11 @@ sub get_pairname
my $ngcp_type = $self->{config}{general}{ngcp_type};
if ($ngcp_type eq 'carrier') {
if ($hostname =~ m/^(\w+[0-9])[ab]?$/) {
if ($hostname =~ m/^(\w+\d+)[a-i]?$/) {
return $1;
}
} elsif ($ngcp_type eq 'sppro') {
if ($hostname =~ m/^(sp)[12]$/) {
if ($hostname =~ m/^(sp)[1-9]$/) {
return $1;
}
} elsif ($ngcp_type eq 'spce') {
@ -187,7 +187,7 @@ sub get_mgmt_pairname
if ($ngcp_type eq 'carrier') {
foreach my $hostname (keys %{$self->{config}{hosts}}) {
if ($self->has_role($hostname, 'mgmt') and
$hostname =~ m/^(\w+[0-9])[ab]?$/)
$hostname =~ m/^(\w+\d+)[a-i]?$/)
{
return $1;
}

@ -6,7 +6,7 @@ use warnings;
use Cwd;
use Test::More;
plan tests => 33;
plan tests => 40;
use_ok('NGCP::Template::Object');
@ -118,6 +118,18 @@ is($obj_ce->get_firstname('self'), 'self', 'host self has self as first name');
is($obj_pro->get_firstname('sp1'), 'sp1', 'host sp1 has sp1 as first name');
is($obj_pro->get_firstname('sp2'), 'sp1', 'host sp2 has sp1 as first name');
# Check get_pairname().
is($obj_ce->get_pairname('self'), 'spce', 'host self has sp as pairname');
is($obj_pro->get_pairname('sp1'), 'sp', 'host sp1 has sp as pairname');
is($obj_pro->get_pairname('sp2'), 'sp', 'host sp2 has sp as pairname');
is($obj_pro->get_pairname('sp9'), 'sp', 'host sp9 has sp as pairname');
is($obj_carrier->get_pairname('web01a'), 'web01',
'host web01a has web01 as pairname');
is($obj_carrier->get_pairname('web01b'), 'web01',
'host web01b has web01 as pairname');
is($obj_carrier->get_pairname('web01i'), 'web01',
'host web01i has web01 as pairname');
# Check get_mgmt_pairname().
is($obj_ce->get_mgmt_pairname(), 'sp', 'spce has sp as mgmt pairname');
is($obj_pro->get_mgmt_pairname(), 'sp', 'sppro has sp as mgmt pairname');

Loading…
Cancel
Save