From 8587969c426fb8b46bd1ba987610c3df10ba8b51 Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Fri, 10 Sep 2021 17:02:29 +0200 Subject: [PATCH] TT#141100 NGCP::Template::Object: Add new get_version method Base lib/get_ngcp_version on this new method. Change-Id: I5bb4f1d4d1f50f8490bab41456563d1a1f5204a6 --- lib/NGCP/Template/Object.pm | 22 ++++++++++++++++++++++ lib/get_ngcp_version | 17 +++-------------- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/lib/NGCP/Template/Object.pm b/lib/NGCP/Template/Object.pm index 4c794064..69b255a4 100644 --- a/lib/NGCP/Template/Object.pm +++ b/lib/NGCP/Template/Object.pm @@ -43,6 +43,24 @@ sub has_role return 0; } +sub get_version +{ + my $self = shift; + + my $filename = '/etc/ngcp_upgrade_version'; + unless (-e $filename) { + $filename = '/etc/ngcp_version'; + } + + open my $hh, '<', $filename or die "Error opening $filename"; + my $version = <$hh>; + close $hh; + chomp $version; + die "Fatal error retrieving ngcp_version [$version]" unless length $version; + + return $version; +} + sub get_hostname { my $self = shift; @@ -210,6 +228,10 @@ The $config argument contains the deserialized ngcp-config YAML configuration. Checks whether the $hostname node has the $role. +=item $version = $t->get_version() + +Returns the NGCP version. + =item $hostname = $t->get_hostname() Returns the hostname of the node calling this function. diff --git a/lib/get_ngcp_version b/lib/get_ngcp_version index 7221d81b..f029d9ac 100644 --- a/lib/get_ngcp_version +++ b/lib/get_ngcp_version @@ -4,18 +4,7 @@ # Returns the NGCP version of the node calling this function. # # @return out The NGCP version (e.g. 'mr4.5.3' or 'trunk'). --%] -[% PERL -%] - my $filename = '/etc/ngcp_upgrade_version'; - unless (-e $filename) { - $filename = '/etc/ngcp_version'; - } - open my $hh, '<', $filename or die "Error opening $filename"; - my $ngcp_version = <$hh>; - close $hh; - chomp $ngcp_version; - die "Fatal error retrieving ngcp_version [$ngcp_version]" unless length $ngcp_version; - $stash->set(out => $ngcp_version); - return; -[% END -%] +out = ngcp.get_version(); + +-%]