From 35e815dd8344a8ddc03c6c487c9930ef886a86cb Mon Sep 17 00:00:00 2001 From: James Adams Date: Tue, 29 Oct 2024 15:53:43 +0000 Subject: [PATCH] ServiceActions: Unescape daemon names This allows for use with templated services e.g. `ssh@mgmt.service` as `@` is an invalid character in a dict key. --- src/main/perl/ServiceActions.pm | 6 ++++-- src/test/perl/serviceactions.t | 5 +++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/perl/ServiceActions.pm b/src/main/perl/ServiceActions.pm index c10588a1..3bb71ceb 100644 --- a/src/main/perl/ServiceActions.pm +++ b/src/main/perl/ServiceActions.pm @@ -3,6 +3,7 @@ use parent qw(CAF::Object Exporter); use CAF::Service; use CAF::Object qw(SUCCESS); +use EDG::WP4::CCM::Path qw(unescape); use Readonly; @@ -113,8 +114,9 @@ sub add $msg = " $msg" if $msg; my @acts; - foreach my $daemon (sort keys %{$pairs || {}}) { - my $action = $pairs->{$daemon}; + foreach my $escdaemon (sort keys %{$pairs || {}}) { + my $daemon = unescape($escdaemon); + my $action = $pairs->{$escdaemon}; if (grep {$_ eq $action} @SERVICE_ACTIONS) { $self->{actions}->{$action} ||= {}; $self->{actions}->{$action}->{$daemon} = 1; diff --git a/src/test/perl/serviceactions.t b/src/test/perl/serviceactions.t index dd6588e6..7d297881 100644 --- a/src/test/perl/serviceactions.t +++ b/src/test/perl/serviceactions.t @@ -76,4 +76,9 @@ ok(command_history_ok(["systemctl reload daemon2.service"], ['daemon1']), "run runs expected commands wrong (no daemon1)"); +my $sa4 = CAF::ServiceActions->new(log => $obj); +$sa4->add({daemon_40instance_2eservice => 'restart'}); +is_deeply($sa4->{actions}, {restart => {'daemon@instance.service' => 1}}, "add correctly unescapes instanced name"); + + done_testing;