From 783862cfc8449eedb041e51997e9027f5e8fee8b Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Thu, 28 Apr 2022 16:36:34 +0200 Subject: [PATCH] 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 --- lib/NGCP/Template/Object.pm | 6 +++--- testsuite/NGCP_Template_Object.t | 14 +++++++++++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/NGCP/Template/Object.pm b/lib/NGCP/Template/Object.pm index 35593ed7..71a07623 100644 --- a/lib/NGCP/Template/Object.pm +++ b/lib/NGCP/Template/Object.pm @@ -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; } diff --git a/testsuite/NGCP_Template_Object.t b/testsuite/NGCP_Template_Object.t index 715d8cb8..e6159aae 100644 --- a/testsuite/NGCP_Template_Object.t +++ b/testsuite/NGCP_Template_Object.t @@ -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');