From 236b56d990dc09949a5cfb3778ea8cfdcaa0a64a Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Thu, 6 Sep 2018 14:38:43 +0200 Subject: [PATCH] TT#43306 NGCP::Template::Object: Only match li_dist exactly This partially reverts commit bc8ae9e795007202a3b7a645f7b1a26f0de2de8a. We should not match li_dist with regexes as then we would trap cases that we should not be covering by the li_dist mapping logic. Just do exact matches. This also fixes the hypothetical case with other regexes that are not the wrongly specified '*'. Change-Id: I9d9d850969e03fa9dc587f2d47a688bc0359e63c --- lib/NGCP/Template/Object.pm | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/lib/NGCP/Template/Object.pm b/lib/NGCP/Template/Object.pm index 59bbe4af..7a0a920e 100644 --- a/lib/NGCP/Template/Object.pm +++ b/lib/NGCP/Template/Object.pm @@ -21,19 +21,14 @@ sub has_role { my ($self, $hostname, $role) = @_; - my $li_check = 1; - if ($role eq '*') { - $role = '.+'; - $li_check = 0; - } - if (not defined $self->{config}{hosts}{$hostname}) { $hostname = 'self'; } # The LI role has a virtual role counterpart, which is active only in - # distributed mode. - if ($li_check && 'li_dist' =~ m/^$role$/) { + # distributed mode. We only check for exact matches, as we do not want + # to grab a regex that would match multiple cases. + if ('li_dist' eq $role) { if ($self->{config}{cluster_sets}{type} eq 'distributed') { $role = 'li'; } else { @@ -44,7 +39,7 @@ sub has_role if (any { m/^$role$/ } @{$self->{config}{hosts}{$hostname}{role}}) { # The LI roles are a bit special, they use additional keys to get # enabled, so we handle them here. - if ($li_check && 'li' =~ m/^$role$/) { + if ('li' =~ m/^$role$/) { return $self->{config}{intercept}{enable} eq 'yes'; } else { # Otherwise, unconditionally enable the role.