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 f3dfb09
Show file tree
Hide file tree
Showing 5 changed files with 51 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: `Variant[String, Undef]`

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',
Variant[String, Undef] $config_validate_cmd = '/usr/sbin/keepalived -l -t -f %',

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

Expand Down
26 changes: 26 additions & 0 deletions spec/acceptance/keepalived_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,30 @@ 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':
sysconf_options => '-D --vrrp',
}
keepalived::vrrp::instance { 'VI_50':
interface => $facts['networking']['primary'],
state => 'MASTER',
virtual_router_id => 50,
priority => 101,
auth_type => 'PASS',
auth_pass => 'secret',
virtual_ipaddress => [ '10.0.0.1/16' ],
}
class { 'keepalived::global_defs':
notification_email_from => '', # this will generate an invalid config
}
EOS
it 'fails validate command' do

Check failure on line 154 in spec/acceptance/keepalived_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 8 - AlmaLinux 8

keepalived class with broken config fails validate command Failure/Error: apply_result = apply_manifest(pp, expect_failures: true) Beaker::Host::CommandFailure: Host 'almalinux8-64-puppet8.example.com' exited with 2 running: puppet apply --verbose --detailed-exitcodes /tmp/apply_manifest_120915793.suYzVW.pp Last 10 lines of output were: Warning: Facter: Container runtime, 'docker', is unsupported, setting to, 'container_other' �[mNotice: Compiled catalog for almalinux8-64-puppet8.example.com in environment production in 0.10 seconds Info: Using environment 'production' Info: Applying configuration version '1722600557' Info: Computing checksum on file /etc/keepalived/keepalived.conf Info: /Stage[main]/Keepalived::Config/Concat[/etc/keepalived/keepalived.conf]/File[/etc/keepalived/keepalived.conf]: Filebucketed /etc/keepalived/keepalived.conf to puppet with sum 47d4e40550fa54f216993b7311db6ec62cf5364ee6a8d5ba4a4306c001307330 �[mNotice: /Stage[main]/Keepalived::Config/Concat[/etc/keepalived/keepalived.conf]/File[/etc/keepalived/keepalived.conf]/content: content changed '{sha256}47d4e40550fa54f216993b7311db6ec62cf5364ee6a8d5ba4a4306c001307330' to '{sha256}6502d3e382f566438c9f8ddc1c2f7a3011c6e912af710448920b03fee64b4b63' Info: Concat[/etc/keepalived/keepalived.conf]: Scheduling refresh of Service[keepalived] �[mNotice: /Stage[main]/Keepalived::Service/Service[keepalived]: Triggered 'refresh' from 1 event �[mNotice: Applied catalog in 1.15 seconds

Check failure on line 154 in spec/acceptance/keepalived_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 7 - AlmaLinux 8

keepalived class with broken config fails validate command Failure/Error: apply_result = apply_manifest(pp, expect_failures: true) Beaker::Host::CommandFailure: Host 'almalinux8-64-puppet7.example.com' exited with 2 running: puppet apply --verbose --detailed-exitcodes /tmp/apply_manifest_120917675.yNvm4j.pp Last 10 lines of output were: Warning: Facter: Container runtime, 'docker', is unsupported, setting to, 'container_other' �[mNotice: Compiled catalog for almalinux8-64-puppet7.example.com in environment production in 0.09 seconds Info: Using environment 'production' Info: Applying configuration version '1722600559' Info: Computing checksum on file /etc/keepalived/keepalived.conf Info: /Stage[main]/Keepalived::Config/Concat[/etc/keepalived/keepalived.conf]/File[/etc/keepalived/keepalived.conf]: Filebucketed /etc/keepalived/keepalived.conf to puppet with sum 47d4e40550fa54f216993b7311db6ec62cf5364ee6a8d5ba4a4306c001307330 �[mNotice: /Stage[main]/Keepalived::Config/Concat[/etc/keepalived/keepalived.conf]/File[/etc/keepalived/keepalived.conf]/content: content changed '{sha256}47d4e40550fa54f216993b7311db6ec62cf5364ee6a8d5ba4a4306c001307330' to '{sha256}6502d3e382f566438c9f8ddc1c2f7a3011c6e912af710448920b03fee64b4b63' Info: Concat[/etc/keepalived/keepalived.conf]: Scheduling refresh of Service[keepalived] �[mNotice: /Stage[main]/Keepalived::Service/Service[keepalived]: Triggered 'refresh' from 1 event �[mNotice: Applied catalog in 1.14 seconds

Check failure on line 154 in spec/acceptance/keepalived_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 8 - Rocky 8

keepalived class with broken config fails validate command Failure/Error: apply_result = apply_manifest(pp, expect_failures: true) Beaker::Host::CommandFailure: Host 'rocky8-64-puppet8.example.com' exited with 2 running: puppet apply --verbose --detailed-exitcodes /tmp/apply_manifest_120922901.3WvCY8.pp Last 10 lines of output were: Warning: Facter: Container runtime, 'docker', is unsupported, setting to, 'container_other' �[mNotice: Compiled catalog for rocky8-64-puppet8.example.com in environment production in 0.10 seconds Info: Using environment 'production' Info: Applying configuration version '1722600564' Info: Computing checksum on file /etc/keepalived/keepalived.conf Info: /Stage[main]/Keepalived::Config/Concat[/etc/keepalived/keepalived.conf]/File[/etc/keepalived/keepalived.conf]: Filebucketed /etc/keepalived/keepalived.conf to puppet with sum 47d4e40550fa54f216993b7311db6ec62cf5364ee6a8d5ba4a4306c001307330 �[mNotice: /Stage[main]/Keepalived::Config/Concat[/etc/keepalived/keepalived.conf]/File[/etc/keepalived/keepalived.conf]/content: content changed '{sha256}47d4e40550fa54f216993b7311db6ec62cf5364ee6a8d5ba4a4306c001307330' to '{sha256}6502d3e382f566438c9f8ddc1c2f7a3011c6e912af710448920b03fee64b4b63' Info: Concat[/etc/keepalived/keepalived.conf]: Scheduling refresh of Service[keepalived] �[mNotice: /Stage[main]/Keepalived::Service/Service[keepalived]: Triggered 'refresh' from 1 event �[mNotice: Applied catalog in 1.15 seconds

Check failure on line 154 in spec/acceptance/keepalived_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 7 - Rocky 8

keepalived class with broken config fails validate command Failure/Error: apply_result = apply_manifest(pp, expect_failures: true) Beaker::Host::CommandFailure: Host 'rocky8-64-puppet7.example.com' exited with 2 running: puppet apply --verbose --detailed-exitcodes /tmp/apply_manifest_120929136.JBYmLM.pp Last 10 lines of output were: Warning: Facter: Container runtime, 'docker', is unsupported, setting to, 'container_other' �[mNotice: Compiled catalog for rocky8-64-puppet7.example.com in environment production in 0.10 seconds Info: Using environment 'production' Info: Applying configuration version '1722600570' Info: Computing checksum on file /etc/keepalived/keepalived.conf Info: /Stage[main]/Keepalived::Config/Concat[/etc/keepalived/keepalived.conf]/File[/etc/keepalived/keepalived.conf]: Filebucketed /etc/keepalived/keepalived.conf to puppet with sum 47d4e40550fa54f216993b7311db6ec62cf5364ee6a8d5ba4a4306c001307330 �[mNotice: /Stage[main]/Keepalived::Config/Concat[/etc/keepalived/keepalived.conf]/File[/etc/keepalived/keepalived.conf]/content: content changed '{sha256}47d4e40550fa54f216993b7311db6ec62cf5364ee6a8d5ba4a4306c001307330' to '{sha256}6502d3e382f566438c9f8ddc1c2f7a3011c6e912af710448920b03fee64b4b63' Info: Concat[/etc/keepalived/keepalived.conf]: Scheduling refresh of Service[keepalived] �[mNotice: /Stage[main]/Keepalived::Service/Service[keepalived]: Triggered 'refresh' from 1 event �[mNotice: Applied catalog in 1.15 seconds

Check failure on line 154 in spec/acceptance/keepalived_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 7 - Debian 11

keepalived class with broken config fails validate command Failure/Error: apply_result = apply_manifest(pp, expect_failures: true) Beaker::Host::CommandFailure: Host 'debian11-64-puppet7.example.com' exited with 2 running: puppet apply --verbose --detailed-exitcodes /tmp/apply_manifest_120937189.knjqCa.pp Last 10 lines of output were: Warning: Facter: Container runtime, 'docker', is unsupported, setting to, 'container_other' �[mNotice: Compiled catalog for debian11-64-puppet7.example.com in environment production in 0.10 seconds Info: Using environment 'production' Info: Applying configuration version '1722600578' Info: Computing checksum on file /etc/keepalived/keepalived.conf Info: /Stage[main]/Keepalived::Config/Concat[/etc/keepalived/keepalived.conf]/File[/etc/keepalived/keepalived.conf]: Filebucketed /etc/keepalived/keepalived.conf to puppet with sum 47d4e40550fa54f216993b7311db6ec62cf5364ee6a8d5ba4a4306c001307330 �[mNotice: /Stage[main]/Keepalived::Config/Concat[/etc/keepalived/keepalived.conf]/File[/etc/keepalived/keepalived.conf]/content: content changed '{sha256}47d4e40550fa54f216993b7311db6ec62cf5364ee6a8d5ba4a4306c001307330' to '{sha256}6502d3e382f566438c9f8ddc1c2f7a3011c6e912af710448920b03fee64b4b63' Info: Concat[/etc/keepalived/keepalived.conf]: Scheduling refresh of Service[keepalived] �[mNotice: /Stage[main]/Keepalived::Service/Service[keepalived]: Triggered 'refresh' from 1 event �[mNotice: Applied catalog in 1.57 seconds

Check failure on line 154 in spec/acceptance/keepalived_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 8 - Debian 11

keepalived class with broken config fails validate command Failure/Error: apply_result = apply_manifest(pp, expect_failures: true) Beaker::Host::CommandFailure: Host 'debian11-64-puppet8.example.com' exited with 2 running: puppet apply --verbose --detailed-exitcodes /tmp/apply_manifest_120941119.oL9kDg.pp Last 10 lines of output were: Warning: Facter: Container runtime, 'docker', is unsupported, setting to, 'container_other' �[mNotice: Compiled catalog for debian11-64-puppet8.example.com in environment production in 0.10 seconds Info: Using environment 'production' Info: Applying configuration version '1722600582' Info: Computing checksum on file /etc/keepalived/keepalived.conf Info: /Stage[main]/Keepalived::Config/Concat[/etc/keepalived/keepalived.conf]/File[/etc/keepalived/keepalived.conf]: Filebucketed /etc/keepalived/keepalived.conf to puppet with sum 47d4e40550fa54f216993b7311db6ec62cf5364ee6a8d5ba4a4306c001307330 �[mNotice: /Stage[main]/Keepalived::Config/Concat[/etc/keepalived/keepalived.conf]/File[/etc/keepalived/keepalived.conf]/content: content changed '{sha256}47d4e40550fa54f216993b7311db6ec62cf5364ee6a8d5ba4a4306c001307330' to '{sha256}6502d3e382f566438c9f8ddc1c2f7a3011c6e912af710448920b03fee64b4b63' Info: Concat[/etc/keepalived/keepalived.conf]: Scheduling refresh of Service[keepalived] �[mNotice: /Stage[main]/Keepalived::Service/Service[keepalived]: Triggered 'refresh' from 1 event �[mNotice: Applied catalog in 1.57 seconds

Check failure on line 154 in spec/acceptance/keepalived_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 7 - OracleLinux 8

keepalived class with broken config fails validate command Failure/Error: apply_result = apply_manifest(pp, expect_failures: true) Beaker::Host::CommandFailure: Host 'oracle8-64-puppet7.example.com' exited with 2 running: puppet apply --verbose --detailed-exitcodes /tmp/apply_manifest_120949172.I5LShK.pp Last 10 lines of output were: Warning: Facter: Container runtime, 'docker', is unsupported, setting to, 'container_other' �[mNotice: Compiled catalog for oracle8-64-puppet7.example.com in environment production in 0.09 seconds Info: Using environment 'production' Info: Applying configuration version '1722600590' Info: Computing checksum on file /etc/keepalived/keepalived.conf Info: /Stage[main]/Keepalived::Config/Concat[/etc/keepalived/keepalived.conf]/File[/etc/keepalived/keepalived.conf]: Filebucketed /etc/keepalived/keepalived.conf to puppet with sum 47d4e40550fa54f216993b7311db6ec62cf5364ee6a8d5ba4a4306c001307330 �[mNotice: /Stage[main]/Keepalived::Config/Concat[/etc/keepalived/keepalived.conf]/File[/etc/keepalived/keepalived.conf]/content: content changed '{sha256}47d4e40550fa54f216993b7311db6ec62cf5364ee6a8d5ba4a4306c001307330' to '{sha256}6502d3e382f566438c9f8ddc1c2f7a3011c6e912af710448920b03fee64b4b63' Info: Concat[/etc/keepalived/keepalived.conf]: Scheduling refresh of Service[keepalived] �[mNotice: /Stage[main]/Keepalived::Service/Service[keepalived]: Triggered 'refresh' from 1 event �[mNotice: Applied catalog in 1.14 seconds

Check failure on line 154 in spec/acceptance/keepalived_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Puppet 8 - OracleLinux 8

keepalived class with broken config fails validate command Failure/Error: apply_result = apply_manifest(pp, expect_failures: true) Beaker::Host::CommandFailure: Host 'oracle8-64-puppet8.example.com' exited with 2 running: puppet apply --verbose --detailed-exitcodes /tmp/apply_manifest_120956713.QWq6xs.pp Last 10 lines of output were: Warning: Facter: Container runtime, 'docker', is unsupported, setting to, 'container_other' �[mNotice: Compiled catalog for oracle8-64-puppet8.example.com in environment production in 0.09 seconds Info: Using environment 'production' Info: Applying configuration version '1722600598' Info: Computing checksum on file /etc/keepalived/keepalived.conf Info: /Stage[main]/Keepalived::Config/Concat[/etc/keepalived/keepalived.conf]/File[/etc/keepalived/keepalived.conf]: Filebucketed /etc/keepalived/keepalived.conf to puppet with sum 47d4e40550fa54f216993b7311db6ec62cf5364ee6a8d5ba4a4306c001307330 �[mNotice: /Stage[main]/Keepalived::Config/Concat[/etc/keepalived/keepalived.conf]/File[/etc/keepalived/keepalived.conf]/content: content changed '{sha256}47d4e40550fa54f216993b7311db6ec62cf5364ee6a8d5ba4a4306c001307330' to '{sha256}6502d3e382f566438c9f8ddc1c2f7a3011c6e912af710448920b03fee64b4b63' Info: Concat[/etc/keepalived/keepalived.conf]: Scheduling refresh of Service[keepalived] �[mNotice: /Stage[main]/Keepalived::Service/Service[keepalived]: Triggered 'refresh' from 1 event �[mNotice: Applied catalog in 1.17 seconds
apply_result = apply_manifest(pp, expect_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 f3dfb09

Please sign in to comment.