MT#54408 NGCP::Template::Object: Fix ngcp.get_firstname() to support spN

This makes this function spN ready, by getting the entire list of
siblings and returning the first of them.

Change-Id: Ifc69b1764bc6d8c1007b8b567f4158a66eca81d8
mr11.1
Guillem Jover 4 years ago
parent bca9daa3b3
commit 082feb52a7

@ -178,9 +178,7 @@ sub get_firstname
if (not exists $self->{config}{hosts}{$hostname}) {
return 'self';
} else {
my @hosts = ($hostname);
my $peername = $self->get_peername($hostname);
push @hosts, $peername if defined $peername;
my @hosts = ($hostname, $self->get_sibnames($hostname));
return (sort @hosts)[0];
}

@ -6,7 +6,7 @@ use warnings;
use Cwd;
use Test::More;
plan tests => 47;
plan tests => 48;
use_ok('NGCP::Template::Object');
@ -136,11 +136,9 @@ is_deeply([ $obj_carrier->get_sibnames('web01c') ], [ qw(web01a web01b) ], 'sibl
is($obj_ce->get_firstname('non-existent'), 'self',
'host unknown has self as first name');
is($obj_ce->get_firstname('self'), 'self', 'host self has self as first name');
# XXX: firstname is not spN ready for now.
$obj_pro->{config}{hosts}{sp2}{peer} = 'sp1';
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');
$obj_pro->{config}{hosts}{sp2}{peer} = 'sp3';
is($obj_pro->get_firstname('sp3'), 'sp1', 'host sp3 has sp1 as first name');
# Check get_pairname().
is($obj_ce->get_pairname('self'), 'spce', 'host self has sp as pairname');

Loading…
Cancel
Save