Skip to content

Commit

Permalink
rename $default param to smartd class to $enable_default
Browse files Browse the repository at this point in the history
To work around this bug in Puppet 2.7.x: https://tickets.puppetlabs.com/browse/PUP-2244
  • Loading branch information
Joshua Hoblitt committed Apr 14, 2014
1 parent ff61535 commit aad6db6
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 32 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,26 +182,26 @@ Smart daemon notification email address.
Smart daemon problem mail notification frequency. Valid values are:
`daily`,`once`,`diminishing`

#### `default`
#### `enable_default`

`Bool` defaults to: `true` if `$::smartmontools_version >= 5.43`, otherwise `false`

Enables/disables the `DEFAULT` directive in the `smartd.conf` file. This
directive was added in the 5.43 release of smartmontools and is unsupported in
previous versions.

If `default` is set to `false` the the values from the [`mail_to`](#mail-to) and [`warning_schedule`](#warning-schedule) parameters are set on the `DEVICESCAN` directive (if enabled) instead of the [absent] `DEFAULT` directive.
If `enable_default` is set to `false` the the values from the [`mail_to`](#mail-to) and [`warning_schedule`](#warning-schedule) parameters are set on the `DEVICESCAN` directive (if enabled) instead of the [absent] `DEFAULT` directive.

Example `smartd.conf` content based on this setting:

`default => true`
`enable_default => true`
```
# Managed by Puppet -- do not edit!
DEFAULT -m root -M daily
DEVICESCAN
```

`default => false`
`enable_default => false`
```
# Managed by Puppet -- do not edit!
DEVICESCAN -m root -M daily
Expand All @@ -220,10 +220,10 @@ Configuration file /etc/smartd.conf was parsed, found DEVICESCAN, scanning devic
Device: DEFAULT, unable to autodetect device type
```

This option would be better named `enable_default` but the `enable_` prefix was
no used so as to appear more consistent with the rest of the API. The API may
be refactored in a future major release to be more consistent with current API
naming best practices.
This option could not be named `default` to be consistent with the naming
convention of the other parameters in this module due to this bug
[PUP-2244](https://tickets.puppetlabs.com/browse/PUP-2244) that affects puppet
2.7.x.

Note that RHEL5 ships with 5.42 while RHEL6 ships with 5.43.

Expand Down
4 changes: 2 additions & 2 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
$devices = $smartd::params::devices,
$mail_to = $smartd::params::mail_to,
$warning_schedule = $smartd::params::warning_schedule,
$default = $smartd::params::default,
$enable_default = $smartd::params::enable_default,
$default_options = $smartd::params::default_options,
) inherits smartd::params {
validate_re($ensure, '^present$|^latest$|^absent$|^purged$')
Expand All @@ -121,7 +121,7 @@
validate_string($mail_to)
validate_re($warning_schedule, '^daily$|^once$|^diminishing$',
'$warning_schedule must be either daily, once, or diminishing.')
validate_bool($default)
validate_bool($enable_default)
validate_string($default_options)

case $ensure {
Expand Down
4 changes: 2 additions & 2 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@

# smartd.conf < 5.43 does not support the 'DEFAULT' directive
if versioncmp($::smartmontools_version, 5.43) >= 0 {
$default = true
$enable_default = true
} else {
$default = false
$enable_default = false
}

case $::osfamily {
Expand Down
36 changes: 18 additions & 18 deletions spec/classes/smartd_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@
with_content(/^DEVICESCAN$/)
end

context 'default => false' do
before { params[:default] = false }
context 'enable_default => false' do
before { params[:enable_default] = false }

it 'should have the same arguments as DEFAULT would have' do
should contain_file('/etc/smartd.conf').
Expand Down Expand Up @@ -298,7 +298,7 @@
end
end

describe 'default => ' do
describe 'enable_default => ' do
context '(default)' do
context 'fact smartmontool_version = "5.43"' do
before { facts[:smartmontools_version] = '5.43' }
Expand All @@ -319,15 +319,15 @@
end # (default)

context 'true' do
let(:params) {{ :default => true }}
let(:params) {{ :enable_default => true }}
it do
should contain_file('/etc/smartd.conf').with_ensure('present').
with_content(/DEFAULT -m root -M daily/)
end
end

context 'false' do
let(:params) {{ :default => false }}
let(:params) {{ :enable_default => false }}
it do
should contain_file('/etc/smartd.conf').with_ensure('present').
without_content(/DEFAULT -m root -M daily/).
Expand All @@ -336,30 +336,30 @@
end

context 'foo' do
let(:params) {{ :default => 'foo' }}
let(:params) {{ :enable_default => 'foo' }}
it 'should fail' do
expect {
should raise_error(Puppet::Error, /is not a boolean../)
}
end
end
end # default =>
end # enable_default =>

describe 'default_options => ' do
context '(default)' do
let(:params) {{ }}

context 'default => true' do
before { params[:default] = true }
before { params[:enable_default] = true }

it do
should contain_file('/etc/smartd.conf').with_ensure('present').
with_content(/DEFAULT -m root -M daily/)
end
end

context 'default => false' do
before { params[:default] = false }
context 'enable_default => false' do
before { params[:enable_default] = false }

it do
should contain_file('/etc/smartd.conf').with_ensure('present').
Expand All @@ -372,17 +372,17 @@
context 'undef' do
let(:params) {{ :default_options => nil }}

context 'default => true' do
before { params[:default] = true }
context 'enable_default => true' do
before { params[:enable_default] = true }

it do
should contain_file('/etc/smartd.conf').with_ensure('present').
with_content(/DEFAULT -m root -M daily/)
end
end

context 'default => false' do
before { params[:default] = false }
context 'enable_default => false' do
before { params[:enable_default] = false }

it do
should contain_file('/etc/smartd.conf').with_ensure('present').
Expand All @@ -395,17 +395,17 @@
context '-H' do
let(:params) {{ :default_options => '-H'}}

context 'default => true' do
before { params[:default] = true }
context 'enable_default => true' do
before { params[:enable_default] = true }

it do
should contain_file('/etc/smartd.conf').with_ensure('present').
with_content(/DEFAULT -m root -M daily -H/)
end
end

context 'default => false' do
before { params[:default] = false }
context 'enable_default => false' do
before { params[:enable_default] = false }

it do
should contain_file('/etc/smartd.conf').with_ensure('present').
Expand Down
4 changes: 2 additions & 2 deletions templates/smartd.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Managed by Puppet -- do not edit!
<% if @default -%>
<% if @enable_default -%>
DEFAULT -m <%= @mail_to %> -M <%= @warning_schedule %><% if @default_options %><%= ' ' + @default_options %><% end %>
<% end -%>
<% @devices.each do |dev| -%>
Expand All @@ -26,7 +26,7 @@ if megaraid_device and megaraid_device != '' and
<% end -%>
<% end -%>
<% if @devicescan -%>
<% unless @default -%>
<% unless @enable_default -%>
DEVICESCAN -m <%= @mail_to %> -M <%= @warning_schedule %><% if @default_options %><%= ' ' + @default_options %><% end %><% if @devicescan_options %><%= ' ' + @devicescan_options %><% end %>
<% else -%>
DEVICESCAN<% if @devicescan_options %><%= ' ' + @devicescan_options %><% end %>
Expand Down

0 comments on commit aad6db6

Please sign in to comment.