Skip to content

Commit

Permalink
Merge pull request #346 from phihos/345
Browse files Browse the repository at this point in the history
Add `validate_cmd` for `keepalived.conf`
  • Loading branch information
kenyon authored Aug 6, 2024
2 parents 22c952f + eb77b40 commit a6899f8
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 9 deletions.
9 changes: 9 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,14 @@ 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 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
9 changes: 6 additions & 3 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#
# @param config_file_mode
#
# @param config_validate_cmd Input for the `validate_cmd` param of the keepalived.conf concat fragment.
#
# @param config_group
#
# @param config_owner
Expand Down Expand Up @@ -61,9 +63,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
28 changes: 28 additions & 0 deletions spec/acceptance/keepalived_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class { 'keepalived::global_defs':
group => 'root',
mode => '0644',
content => "vrrp_instance VI_50 { interface ${facts['networking']['primary']}
virtual_ipaddress { 10.0.0.1/16 }
virtual_router_id 50 }",
notify => Class['keepalived::service']
}
Expand Down Expand Up @@ -130,4 +131,31 @@ 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':
smtp_server => '',
notification_email_from => '', # this will generate an invalid config
}
EOS
it 'fails validate command' do
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 a6899f8

Please sign in to comment.