Skip to content

Commit

Permalink
(#310) {vrrp_,}track_file: Enforce only String datatype
Browse files Browse the repository at this point in the history
Example config:

```
track_file acme {
  file     "/var/local/vrrp_track_file"
  weight      1
}
vrrp_instance lb_slm_test_4 {
  interface                 ens192
  state                     MASTER
  virtual_router_id         4
  priority                  50
  advert_int                1
  garp_master_delay         5

  track_script {
    access-lb
  }

  track_file {
    acme weight 1
  }

  virtual_ipaddress {
    127.0.0.1/27 dev eth0
  }
}
```

The parameter `track_file` in `keepalived::vrrp::instance` is the list `track_file`:

```
  track_file {
    acme weight 1
  }
```

This can be a random string and references a `track_file` block with that name:

```
track_file acme {
  file     "/var/local/vrrp_track_file"
  weight      1
}
```

^ is created by `keepalived::vrrp::track_file` defined resource.
  • Loading branch information
tuxmea authored and bastelfreak committed Mar 12, 2024
1 parent f7f4ca7 commit 63955d3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
9 changes: 4 additions & 5 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -1211,18 +1211,17 @@ Default value: `undef`

##### <a name="-keepalived--vrrp--instance--track_file"></a>`track_file`

Data type: `Optional[Array[Stdlib::Absolutepath]]`
Data type: `Optional[Array[String[1]]]`

Define which file trackers to run (array).
Define which file trackers to run. References a track_file block that can be created with keepalived::vrrp::track_file.

Default value: `undef`

##### <a name="-keepalived--vrrp--instance--vrrp_track_file"></a>`vrrp_track_file`

Data type: `Optional[Array[Stdlib::Absolutepath]]`
Data type: `Optional[Array[String[1]]]`

Define which file trackers to run (array).
Deprecated, for keepalived < 2.1.0
Define which file trackers to run. Deprecated, for keepalived < 2.1.0. References a vrrp_track_file block that can be created with keepalived::vrrp::vrrp_track_file.

Default value: `undef`

Expand Down
9 changes: 4 additions & 5 deletions manifests/vrrp/instance.pp
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,10 @@
# Define which process trackers to run.
#
# @param track_file
# Define which file trackers to run (array).
# Define which file trackers to run. References a track_file block that can be created with keepalived::vrrp::track_file.
#
# @param vrrp_track_file
# Define which file trackers to run (array).
# Deprecated, for keepalived < 2.1.0
# Define which file trackers to run. Deprecated, for keepalived < 2.1.0. References a vrrp_track_file block that can be created with keepalived::vrrp::vrrp_track_file.
#
# @param track_interface
# Define which interface(s) to monitor.
Expand Down Expand Up @@ -208,8 +207,8 @@
Optional[Variant[String, Sensitive[String]]] $auth_pass = undef,
$track_script = undef,
Optional[Array[String[1]]] $track_process = undef,
Optional[Array[Stdlib::Absolutepath]] $track_file = undef,
Optional[Array[Stdlib::Absolutepath]] $vrrp_track_file = undef,
Optional[Array[String[1]]] $track_file = undef,
Optional[Array[String[1]]] $vrrp_track_file = undef,
$track_interface = undef,
$lvs_interface = undef,
$virtual_ipaddress_int = undef,
Expand Down
14 changes: 12 additions & 2 deletions spec/defines/keepalived_vrrp_instance_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
'include keepalived'
end

on_supported_os.each do |os, facts|
on_supported_os.each do |os, os_facts|
context "on #{os}" do
let(:facts) do
facts
os_facts
end

describe 'without parameters' do
Expand Down Expand Up @@ -1420,6 +1420,16 @@
)
}
end

# explicit checks for strings, to prevent future people from enforcing Stdlib::Absolutepath
# See https://github.com/voxpupuli/puppet-keepalived/pull/312 for context
describe 'with track_file and vrrp_track_file' do
let :params do
mandatory_params.merge(track_file: ['acme', 'foo'], vrrp_track_file: ['bar', 'baz'])

Check failure on line 1428 in spec/defines/keepalived_vrrp_instance_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

Style/WordArray: Use `%w` or `%W` for an array of words. (https://rubystyle.guide#percent-w)

Check failure on line 1428 in spec/defines/keepalived_vrrp_instance_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

Style/WordArray: Use `%w` or `%W` for an array of words. (https://rubystyle.guide#percent-w)
end

Check failure on line 1429 in spec/defines/keepalived_vrrp_instance_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

RSpec/EmptyLineAfterFinalLet: Add an empty line after the last `let`. (https://rspec.rubystyle.guide/#empty-line-after-let, https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/EmptyLineAfterFinalLet)
it { is_expected.to contain_concat__fragment('keepalived.conf_vrrp_instance__NAME_').with_content(%r{track_file \{\n.*acme.*\n.*foo}) }
it { is_expected.to contain_concat__fragment('keepalived.conf_vrrp_instance__NAME_').with_content(%r{vrrp_track_file \{\n.*bar.*\n.*baz}) }
end
end
end
end

0 comments on commit 63955d3

Please sign in to comment.