Skip to content

Commit

Permalink
Add validate_cmd for keepalived.conf
Browse files Browse the repository at this point in the history
Fixes #345
  • Loading branch information
phihos committed Aug 2, 2024
1 parent 22c952f commit 4cf1cd2
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 9 deletions.
10 changes: 10 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ The following parameters are available in the `keepalived` class:
* [`config_dir`](#-keepalived--config_dir)
* [`config_dir_mode`](#-keepalived--config_dir_mode)
* [`config_file_mode`](#-keepalived--config_file_mode)
* [`config_validate_cmd`](#-keepalived--config_validate_cmd)
* [`config_group`](#-keepalived--config_group)
* [`config_owner`](#-keepalived--config_owner)
* [`daemon_group`](#-keepalived--daemon_group)
Expand Down Expand Up @@ -113,6 +114,15 @@ Data type: `Stdlib::Filemode`

Default value: `'0644'`

##### <a name="-keepalived--config_validate_cmd"></a>`config_validate_cmd`

Data type: `Optional[String]`

Input for the `validate_cmd` param of the keepalived.conf concat fragment.
Default is `/usr/sbin/keepalived -l -t -f %`.

Default value: `'/usr/sbin/keepalived -l -t -f %'`

##### <a name="-keepalived--config_group"></a>`config_group`

Data type: `String[1]`
Expand Down
7 changes: 4 additions & 3 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@
}

concat { "${keepalived::config_dir}/keepalived.conf":
owner => $keepalived::config_owner,
group => $keepalived::config_group,
mode => $keepalived::config_file_mode,
owner => $keepalived::config_owner,
group => $keepalived::config_group,
mode => $keepalived::config_file_mode,
validate_cmd => $keepalived::config_validate_cmd,
}

concat::fragment { 'keepalived.conf_header':
Expand Down
10 changes: 7 additions & 3 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
#
# @param config_file_mode
#
# @param config_validate_cmd Input for the `validate_cmd` param of the keepalived.conf concat fragment.
# Default is `/usr/sbin/keepalived -l -t -f %`.
#
# @param config_group
#
# @param config_owner
Expand Down Expand Up @@ -61,9 +64,10 @@
Optional[Boolean] $service_hasrestart = undef,
Optional[Boolean] $service_hasstatus = undef,

Stdlib::Absolutepath $config_dir = '/etc/keepalived',
Stdlib::Filemode $config_dir_mode = '0755',
Stdlib::Filemode $config_file_mode = '0644',
Stdlib::Absolutepath $config_dir = '/etc/keepalived',
Stdlib::Filemode $config_dir_mode = '0755',
Stdlib::Filemode $config_file_mode = '0644',
Optional[String] $config_validate_cmd = '/usr/sbin/keepalived -l -t -f %',

Check warning on line 70 in manifests/init.pp

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

Optional parameter defaults to something other than undef (check: optional_default)

Array[Stdlib::Absolutepath] $include_external_conf_files = [],

Expand Down
15 changes: 15 additions & 0 deletions spec/acceptance/keepalived_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,19 @@ class { 'keepalived':
expect(service_fact.output).to match %r{.*Keepalived version was: (\d.\d.\d).*}
end
end

context 'with broken config' do
pp = <<-EOS
class { 'keepalived':
}
class { 'keepalived::global_defs':
notification_email_from => '', # this will generate an invalid config
}
EOS
it 'fails validate command' do
apply_result = apply_manifest(pp, catch_failures: true)
expect(apply_result.output).to match %r{.*emailfrom missing.*}
end
end
end
7 changes: 4 additions & 3 deletions spec/classes/keepalived_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@

it {
is_expected.to contain_concat('/etc/keepalived/keepalived.conf').with(
'group' => 'root',
'mode' => '0644',
'owner' => 'root'
'group' => 'root',
'mode' => '0644',
'owner' => 'root',
'validate_cmd' => '/usr/sbin/keepalived -l -t -f %',
)
}

Expand Down

0 comments on commit 4cf1cd2

Please sign in to comment.