Skip to content

Commit

Permalink
ServiceActions: Unescape daemon names
Browse files Browse the repository at this point in the history
This allows for use with templated services e.g. `[email protected]` as `@` is an invalid character in a dict key.
  • Loading branch information
jrha committed Oct 30, 2024
1 parent 4e19f7b commit 35e815d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/main/perl/ServiceActions.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions src/test/perl/serviceactions.t
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {'[email protected]' => 1}}, "add correctly unescapes instanced name");


done_testing;

0 comments on commit 35e815d

Please sign in to comment.