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');