Skip to content

Commit

Permalink
add $default_options param to smartd class
Browse files Browse the repository at this point in the history
+ fix a few typos in README.md
  • Loading branch information
Joshua Hoblitt committed Apr 14, 2014
1 parent a51ca20 commit ff61535
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 10 deletions.
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Puppet smartd Module
1. [Overview](#overview)
2. [Description](#description)
3. [Usage](#usage)
* [Version `2.x.x` _incompatilbe_ API change](#version-2xx-incompatilbe-api-change)
* [Version `2.x.x` _incompatible_ API change](#version-2xx-incompatible-api-change)
* [Simple Usage](#simple-usage)
* [Parameters](#parameters)
* [Pedantic Example](#pedantic-example)
Expand Down Expand Up @@ -173,7 +173,7 @@ Explicit list of raw block devices to check. Eg.

`String` defaults to: `root`

Smart daemon notifcation email address.
Smart daemon notification email address.

#### `warning_schedule`

Expand Down Expand Up @@ -208,7 +208,7 @@ DEVICESCAN -m root -M daily
```

Here is an example of the error message generated by the `DEFFAULT` directive
apearing in the configuration file of 5.42.
appearing in the configuration file of 5.42.

```
smartd 5.42 2011-10-20 r3458 [i686-linux-2.6.18-371.6.1.el5PAE] (local build)
Expand All @@ -227,6 +227,16 @@ naming best practices.

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

#### `default_options`

`String` defaults to: `undef`

Additional arguments to be set on the `DEFAULT` directive.

If `default` is set to `false`, this parameter's value will be set on the
`DEVICESCAN` directive (if enabled) instead of the [absent] `DEFAULT`
directive.

### Pedantic Example

```puppet
Expand All @@ -245,6 +255,7 @@ Note that RHEL5 ships with 5.42 while RHEL6 ships with 5.43.
mail_to => 'root',
warning_schedule => 'diminishing',
default => 'false',
default_options => '-H',
}
```

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

case $ensure {
'present', 'latest': {
Expand Down
1 change: 1 addition & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
$devices = []
$mail_to = 'root'
$warning_schedule = 'daily' # other choices: once, diminishing
$default_options = undef

# smartd.conf < 5.43 does not support the 'DEFAULT' directive
if versioncmp($::smartmontools_version, 5.43) >= 0 {
Expand Down
92 changes: 87 additions & 5 deletions spec/classes/smartd_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
with_ensure('present').
with_content(/^DEVICESCAN$/)
end
end
end # (default)

context 'true' do
let(:params) {{ :devicescan => true }}
Expand All @@ -163,7 +163,7 @@
with_content(/^DEVICESCAN -m root -M daily$/)
end
end
end
end # true

context 'false' do
let(:params) {{ :devicescan => false }}
Expand All @@ -173,7 +173,7 @@
with_ensure('present').
without_content(/^DEVICESCAN$/)
end
end
end # false

context 'foo' do
let(:params) {{ :devicescan => 'foo' }}
Expand Down Expand Up @@ -312,7 +312,8 @@
before { facts[:smartmontools_version] = '5.42' }
it do
should contain_file('/etc/smartd.conf').with_ensure('present').
without_content(/DEFAULT -m root -M daily/)
without_content(/DEFAULT -m root -M daily/).
with_content(/DEVICESCAN -m root -M daily/)
end
end
end # (default)
Expand All @@ -329,7 +330,8 @@
let(:params) {{ :default => false }}
it do
should contain_file('/etc/smartd.conf').with_ensure('present').
without_content(/DEFAULT -m root -M daily/)
without_content(/DEFAULT -m root -M daily/).
with_content(/DEVICESCAN -m root -M daily/)
end
end

Expand All @@ -343,6 +345,86 @@
end
end # default =>

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

context 'default => true' do
before { params[: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 }

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

context 'undef' do
let(:params) {{ :default_options => nil }}

context 'default => true' do
before { params[: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 }

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

context '-H' do
let(:params) {{ :default_options => '-H'}}

context 'default => true' do
before { params[: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 }

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

context '[]' do
let(:params) {{ :default_options => [] }}
it 'should fail' do
expect {
should raise_error(Puppet::Error, /is not an Array../)
}
end
end # []
end # default_options =>

end


Expand Down
4 changes: 2 additions & 2 deletions templates/smartd.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Managed by Puppet -- do not edit!
<% if @default -%>
DEFAULT -m <%= @mail_to %> -M <%= @warning_schedule %>
DEFAULT -m <%= @mail_to %> -M <%= @warning_schedule %><% if @default_options %><%= ' ' + @default_options %><% end %>
<% end -%>
<% @devices.each do |dev| -%>
<% next if dev['device'] == 'megaraid' -%>
Expand All @@ -27,7 +27,7 @@ if megaraid_device and megaraid_device != '' and
<% end -%>
<% if @devicescan -%>
<% unless @default -%>
DEVICESCAN -m <%= @mail_to %> -M <%= @warning_schedule %><% if @devicescan_options %><%= ' ' + @devicescan_options %><% end %>
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 %>
<% end -%>
Expand Down

0 comments on commit ff61535

Please sign in to comment.