From 54b75c6ba9fa4b697771e31c844960f0248024c2 Mon Sep 17 00:00:00 2001 From: ngcp-config Date: Fri, 7 Oct 2022 12:06:49 +0200 Subject: [PATCH] MT#55472 NGCP::Template::Object: Add get_supported_roles() method Change-Id: Ib2e82ea16d537fd2068cd880f8d49fb3d8e9661b --- lib/NGCP/Template/Object.pm | 18 ++++++++++++++++++ testsuite/NGCP_Template_Object.t | 16 +++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/lib/NGCP/Template/Object.pm b/lib/NGCP/Template/Object.pm index 5216f11e..76c08b08 100644 --- a/lib/NGCP/Template/Object.pm +++ b/lib/NGCP/Template/Object.pm @@ -28,6 +28,20 @@ sub get_online_cpus return $nproc // 1; } +sub get_supported_roles +{ + return [ qw( + db + lb + li + li_dist + mgmt + proxy + rtp + storage + ) ]; +} + sub has_role { my ($self, $hostname, $role) = @_; @@ -344,6 +358,10 @@ Returns the number of online CPUs on the system. This can be used to compute values in templates that depend on the amount of cores. +=item $bool = $t->get_supported_roles() + +Returns the list of roles supported by NGCP. + =item $bool = $t->has_role($hostname, $role) Checks whether the $hostname node has the $role. diff --git a/testsuite/NGCP_Template_Object.t b/testsuite/NGCP_Template_Object.t index 94cfd113..4952900a 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 => 48; +plan tests => 49; use_ok('NGCP::Template::Object'); @@ -87,6 +87,20 @@ my $obj_carrier = NGCP::Template::Object->new($cfg_carrier); is($obj_ce->get_online_cpus(), 8, 'number of online processors'); } +# Check get_supported_roles() +is_deeply($obj_ce->get_supported_roles(), + [ qw( + db + lb + li + li_dist + mgmt + proxy + rtp + storage + ) ], + 'list of supported roles'); + # Check has_role(). ok(!$obj_ce->has_role('non-existent', 'storage'), 'host unknown has storage role');