Skip to content

Commit

Permalink
add el5.x support for raid_check_options param to mdadm class
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Hoblitt committed May 21, 2014
1 parent c30edf7 commit 5d1b8d3
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 37 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,20 @@ Enables/disables management of the EL specific `raid-check` cron task.

`Hash` defaults to '{}'

Keyword/value pairs to be set in the `/etc/sysconfig/raid-check` configuration
file. Example:

```puppet
{
'ENABLED' => 'yes',
'CHECK' => 'check',
'NICE' => 'low',
'CHECK_DEVS' => '/dev/md0 /dev/md1',
'REPAIR_DEVS' => '/dev/md0',
'SKIP_DEVS' => '/dev/md1',
}
```

### Facts

#### `mdadm`
Expand Down
26 changes: 24 additions & 2 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# This class should be considered private.
#
class mdadm::params {
# mdadm class default params
$config_file_manage = true
$config_file_options = {}
$service_force = false
Expand All @@ -11,13 +12,34 @@
$raid_check_manage = true
$raid_check_options = {}

# internal only
$mdadm_package = 'mdadm'
$raid_check_path = '/etc/sysconfig/raid-check'

case $::osfamily {
'redhat': {
case $::operatingsystemmajrelease {
6: {
$mdadm_package = 'mdadm'
$raid_check_path = '/etc/sysconfig/raid-check'
$raid_check_template = "${module_name}/redhat/raid-check.el6.erb"
# note that 'NICE' is el6.x only
$raid_check_default_options = {
'ENABLED' => 'yes',
'CHECK' => 'check',
'NICE' => 'low',
'CHECK_DEVS' => '',
'REPAIR_DEVS' => '',
'SKIP_DEVS' => '',
}
}
5: {
$raid_check_template = "${module_name}/redhat/raid-check.el5.erb"
$raid_check_default_options = {
'ENABLED' => 'yes',
'CHECK' => 'check',
'CHECK_DEVS' => '',
'REPAIR_DEVS' => '',
'SKIP_DEVS' => '',
}
}
default: {
fail("Module ${module_name} is not supported on ${::operatingsystem} ${::operatingsystemmajrelease}")
Expand Down
17 changes: 3 additions & 14 deletions manifests/raid_check.pp
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,13 @@
fail("Use of private class ${name} by ${caller_module_name}")
}

# note that 'NICE' is el6.x only
$safe_options = merge($::mdadm::raid_check_default_options, $options)

$default_options = {
'ENABLED' => 'yes',
'CHECK' => 'check',
'NICE' => 'low',
'CHECK_DEVS' => '',
'REPAIR_DEVS' => '',
'SKIP_DEVS' => '',
}

$safe_options = merge($default_options, $options)

file { $mdadm::raid_check_path:
file { $::mdadm::raid_check_path:
ensure => present,
owner => 'root',
group => 'root',
mode => '0644',
content => template($mdadm::raid_check_template),
content => template($::mdadm::raid_check_template),
}
}
26 changes: 22 additions & 4 deletions spec/unit/classes/mdadm_params_spec.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,35 @@
require 'spec_helper'

describe 'mdadm::params', :type => :class do
describe 'for osfamily RedHat' do
context 'for osfamily RedHat' do
let(:facts) do
{
:osfamily => 'RedHat',
:operatingsystem => 'Scientific',
:operatingsystemmajrelease => 6,
}
end

it { should contain_class('mdadm::params') }
end
context '6.x' do
before { facts[:operatingsystemmajrelease] = 6 }

it { should contain_class('mdadm::params') }
end

context '5.x' do
before { facts[:operatingsystemmajrelease] = 5 }

it { should contain_class('mdadm::params') }
end

context '4.x' do
before { facts[:operatingsystemmajrelease] = 4 }

it 'should fail' do
expect { should contain_class('mdadm::params') }.
to raise_error(Puppet::Error, /not supported on Scientific 4/)
end
end
end # for osmfaily RedHat

describe 'unsupported osfamily' do
let :facts do
Expand Down
55 changes: 38 additions & 17 deletions spec/unit/classes/mdadm_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,19 +177,40 @@

context 'raid_check_options =>' do
context '{}' do
let(:params) {{ :raid_check_options => {} }}

it_behaves_like 'mdadm'
it do
should contain_file('/etc/sysconfig/raid-check').
with_content(/ENABLED="yes"/).
with_content(/CHECK="check"/).
with_content(/NICE="low"/).
with_content(/CHECK_DEVS=""/).
with_content(/REPAIR_DEVS=""/).
with_content(/SKIP_DEVS=""/)
end
end
context 'on el6.x' do
before { facts[:operatingsystemmajrelease] = 6 }
let(:params) {{ :raid_check_options => {} }}

it_behaves_like 'mdadm'
it do
should contain_file('/etc/sysconfig/raid-check').
with_content(/ENABLED="yes"/).
with_content(/CHECK="check"/).
with_content(/NICE="low"/).
with_content(/CHECK_DEVS=""/).
with_content(/REPAIR_DEVS=""/).
with_content(/SKIP_DEVS=""/)
end
end # el6.x

context 'on el5.x' do
before { facts[:operatingsystemmajrelease] = 5 }
let(:params) {{ :raid_check_options => {} }}

it_behaves_like 'mdadm'
it do
should contain_file('/etc/sysconfig/raid-check').
with_content(/ENABLED="yes"/).
with_content(/CHECK="check"/).
with_content(/CHECK_DEVS=""/).
with_content(/REPAIR_DEVS=""/).
with_content(/SKIP_DEVS=""/)

should_not contain_file('/etc/sysconfig/raid-check').
with_content(/NICE="low"/)
end
end # el5.x
end # {}

context '{ ... }' do
let(:params) do
Expand All @@ -209,10 +230,10 @@
it do
should contain_file('/etc/sysconfig/raid-check').
with_content(/ENABLED="foo"/).
with_content(/CHECK="foo"/).
with_content(/NICE="foo"/).
with_content(/CHECK_DEVS="foo"/).
with_content(/REPAIR_DEVS="foo"/).
with_content(/CHECK="foo"/).
with_content(/NICE="foo"/).
with_content(/CHECK_DEVS="foo"/).
with_content(/REPAIR_DEVS="foo"/).
with_content(/SKIP_DEVS="foo"/)
end
end
Expand Down
50 changes: 50 additions & 0 deletions templates/redhat/raid-check.el5.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash
#
# Configuration file for /etc/cron.weekly/raid-check
#
# options:
# ENABLED - must be yes in order for the raid check to proceed
# CHECK - can be either check or repair depending on the type of
# operation the user desires. A check operation will scan
# the drives looking for bad sectors and automatically
# repairing only bad sectors. If it finds good sectors that
# contain bad data (meaning that the data in a sector does
# not agree with what the data from another disk indicates
# the data should be, for example the parity block + the other
# data blocks would cause us to think that this data block
# is incorrect), then it does nothing but increments the
# counter in the file /sys/block/$dev/md/mismatch_count.
# This allows the sysadmin to inspect the data in the sector
# and the data that would be produced by rebuilding the
# sector from redundant information and pick the correct
# data to keep. The repair option does the same thing, but
# when it encounters a mismatch in the data, it automatically
# updates the data to be consistent. However, since we really
# don't know whether it's the parity or the data block that's
# correct (or which data block in the case of raid1), it's
# luck of the draw whether or not the user gets the right
# data instead of the bad data. This option is the default
# option for devices not listed in either CHECK_DEVS or
# REPAIR_DEVS.
# CHECK_DEVS - a space delimited list of devs that the user specifically
# wants to run a check operation on.
# REPAIR_DEVS - a space delimited list of devs that the user
# specifically wants to run a repair on.
# SKIP_DEVS - a space delimited list of devs that should be skipped
#
# Note: the raid-check script intentionaly runs last in the cron.weekly
# sequence. This is so we can wait for all the resync operations to complete
# and then check the mismatch_count on each array without unduly delaying
# other weekly cron jobs. If any arrays have a non-0 mismatch_count after
# the check completes, we echo a warning to stdout which will then me emailed
# to the admin as long as mails from cron jobs have not been redirected to
# /dev/null. We do not wait for repair operations to complete as the
# md stack will correct any mismatch_cnts automatically.
#
# Note2: you can not use symbolic names for the raid devices, such as you
# /dev/md/root. The names used in this file must match the names seen in
# /proc/mdstat and in /sys/block.

<% @safe_options.keys.sort.each do |key| -%>
<%= key %>="<%= @safe_options[key] %>"
<% end -%>

0 comments on commit 5d1b8d3

Please sign in to comment.