TT#141100 NGCP::Template::Object: Add new get_dbnode method

Reimplement lib/get_dbnode based on this new method.

Change-Id: Idba7c6a4c7670117ff415ab498004f6c92ef4a37
mr10.1
Guillem Jover 5 years ago
parent 32695c44b9
commit 55164ec0f8

@ -143,6 +143,16 @@ sub get_firstname
}
}
sub get_dbnode
{
my ($self, $hostname) = @_;
if (not exists $self->{config}{hosts}{$hostname}) {
return 'self';
}
return $self->{config}{hosts}{$hostname}{dbnode};
}
sub get_mgmt_node
{
my ($self) = shift;
@ -280,6 +290,10 @@ Returns the peer name for a given $hostname.
Returns the (alphabetically) first hostname of a node pair for a given
$hostname.
=item $dbname = $t->get_dbname($hostname)
Returns the database name for this node.
=item $mgmtnode = $t->get_mgmt_node()
Returns the NGCP management node shared name.

@ -6,9 +6,6 @@
# @param argv.host The hostname to get the dbnode for.
# @return out The dbnode.
IF !hosts.${argv.host}.defined;
argv.host = 'self';
END;
out = hosts.${argv.host}.dbnode;
out = ngcp.get_dbnode(argv.host);
-%]

@ -5,7 +5,7 @@ use warnings;
use Test::More;
plan tests => 28;
plan tests => 30;
use_ok('NGCP::Template::Object');
@ -33,6 +33,7 @@ my $config = {
prx01a => {
role => [ qw(li proxy) ],
peer => 'prx01b',
dbnode => 'db01',
},
web01a => {
role => [ qw(mgmt) ],
@ -96,6 +97,10 @@ is($obj->get_mgmt_node(), 'sp', 'spce has sp as mgmt node');
is($obj->get_mgmt_node(), 'web01', 'carrier has web01 as mgmt node');
}
# Check get_dbnode().
is($obj->get_dbnode('non-existent'), 'self', 'host unknown has self as dbnode');
is($obj->get_dbnode('prx01a'), 'db01', 'host prx01a has db01 as dbnode');
# Check net_ip_expand().
is($obj->net_ip_expand('1:2::5:20'),
'1:2:0:0:0:0:5:20',

Loading…
Cancel
Save