From 1fca1f6408379d5b79ebc03f5743256e9f211ecf Mon Sep 17 00:00:00 2001 From: Benedikt Trefzer Date: Sat, 26 Oct 2024 17:22:41 +0200 Subject: [PATCH] allow setting process parameters for track_process With this, setting parameter to check for vrrp processes is possible. --- manifests/vrrp/track_process.pp | 7 +++++-- .../keepalived_vrrp_track_process_spec.rb | 17 +++++++++++++++++ templates/vrrp_track_process.epp | 6 +++++- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/manifests/vrrp/track_process.pp b/manifests/vrrp/track_process.pp index 641f6a716..9cce73876 100644 --- a/manifests/vrrp/track_process.pp +++ b/manifests/vrrp/track_process.pp @@ -1,7 +1,10 @@ # # @summary Configure the process tracker # -# @param proc_name process name to track +# @param proc_name +# process name to track +# use an Array configuration to specify process parameters (first element needs to +# be the process name). # # @param weight The weight that should add to the instance. # @@ -18,7 +21,7 @@ # @param param_match Set inital if command has no parameters or use partial if first n parameters match # define keepalived::vrrp::track_process ( - String[1] $proc_name, + Variant[String[1], Array[String[1],1]] $proc_name, Optional[Integer[0]] $weight = undef, Integer[0] $quorum = 1, Optional[Integer[0]] $delay = undef, diff --git a/spec/defines/keepalived_vrrp_track_process_spec.rb b/spec/defines/keepalived_vrrp_track_process_spec.rb index a46a606cd..c931cc26f 100644 --- a/spec/defines/keepalived_vrrp_track_process_spec.rb +++ b/spec/defines/keepalived_vrrp_track_process_spec.rb @@ -37,6 +37,23 @@ end end + describe 'with array parameter proc_name' do + let(:params) do + { + proc_name: ['MYPROCNAME','PARAM 1'] + } + end + + it { is_expected.to create_keepalived__vrrp__track_process('_PROC_NAME_') } + + it do + is_expected.to \ + contain_concat__fragment('keepalived.conf_vrrp_track_process__PROC_NAME_').with( + 'content' => %r{process.*MYPROCNAME.*PARAM 1} + ) + end + end + describe 'with parameter weight' do let(:params) do { diff --git a/templates/vrrp_track_process.epp b/templates/vrrp_track_process.epp index dac71c5df..7cd4a5fda 100644 --- a/templates/vrrp_track_process.epp +++ b/templates/vrrp_track_process.epp @@ -1,5 +1,5 @@ <%- | String $name, - String $proc_name, + Variant[String[1], Array[String[1],1]] $proc_name, Optional[Integer] $weight, Optional[Integer] $quorum, Optional[Integer] $delay, @@ -9,7 +9,11 @@ Optional[Boolean] $full_command | -%> vrrp_track_process <%= $name %> { + <%- if $proc_name =~ String { -%> process "<%= $proc_name %>" + <%- } else { -%> + process "<%= $proc_name.join('" "') %>" + <%- } -%> <%- if $weight { -%> weight <%= $weight %> <%- } -%>