diff --git a/manifests/init.pp b/manifests/init.pp index b4b9144..4959503 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -2,14 +2,29 @@ # # simple template # +# === Parameters +# +# All parameteres are optional. +# +# [*raid_check_options*] +# Hash. defaults to '{}' +# # === Examples # # include mdadm # -class mdadm { +class mdadm( + $raid_check_options = {} +) { + validate_hash($raid_check_options) + include mdadm::params package { $mdadm::params::mdadm_package: ensure => present, } + + class { 'mdadm::raid_check': + options => $raid_check_options, + } } diff --git a/manifests/params.pp b/manifests/params.pp index e2855ab..86fc691 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -13,7 +13,9 @@ class mdadm::params { case $::osfamily { 'redhat': { - $mdadm_package = 'mdadm' + $mdadm_package = 'mdadm' + $raid_check_path = '/etc/sysconfig/raid-check' + $raid_check_template = "${module_name}/redhat/raid-check.el6.erb" } default: { fail("Module ${module_name} is not supported on ${::operatingsystem}") diff --git a/manifests/raid_check.pp b/manifests/raid_check.pp new file mode 100644 index 0000000..3c44cd3 --- /dev/null +++ b/manifests/raid_check.pp @@ -0,0 +1,30 @@ +# == Class: mdadm::raid_check +# +# This class should be considered private. +# +class mdadm::raid_check( + $options = {} +) { + include mdadm::params + + # note that 'NICE' is el6.x only + + $default_options = { + 'ENABLED' => 'yes', + 'CHECK' => 'check', + 'NICE' => 'low', + 'CHECK_DEVS' => '', + 'REPAIR_DEVS' => '', + 'SKIP_DEVS' => '', + } + + $safe_options = merge($default_options, $options) + + file { $mdadm::params::raid_check_path: + ensure => present, + owner => 'root', + group => 'root', + mode => '0644', + content => template($mdadm::params::raid_check_template), + } +} diff --git a/spec/classes/mdadm_spec.rb b/spec/classes/mdadm_spec.rb index 5eddf3a..05f0d61 100644 --- a/spec/classes/mdadm_spec.rb +++ b/spec/classes/mdadm_spec.rb @@ -5,8 +5,73 @@ context 'on osfamily RedHat' do let(:facts) {{ :osfamily => 'RedHat' }} - it { should contain_package('mdadm').with_ensure('present') } - it { should include_class('mdadm::params') } + context 'no params' do + it { should contain_package('mdadm').with_ensure('present') } + it { should include_class('mdadm::params') } + 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 # no params + + context 'raid_check_options =>' do + context '{}' do + let(:params) {{ :raid_check_options => {} }} + + it { should contain_package('mdadm').with_ensure('present') } + it { should include_class('mdadm::params') } + 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 '{ ... }' do + let(:params) do + { + :raid_check_options => { + 'ENABLED' => 'foo', + 'CHECK' => 'foo', + 'NICE' => 'foo', + 'CHECK_DEVS' => 'foo', + 'REPAIR_DEVS' => 'foo', + 'SKIP_DEVS' => 'foo', + }, + } + end + + it { should contain_package('mdadm').with_ensure('present') } + it { should include_class('mdadm::params') } + 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(/SKIP_DEVS="foo"/) + end + end + + context 'some_string' do + let(:params) {{ :raid_check_options => 'some_string' }} + + it 'should fail' do + expect { should }.to raise_error /is not a Hash/ + end + end + + end # raid_check_options => end end diff --git a/templates/redhat/raid-check.el6.erb b/templates/redhat/raid-check.el6.erb new file mode 100644 index 0000000..521d7e3 --- /dev/null +++ b/templates/redhat/raid-check.el6.erb @@ -0,0 +1,49 @@ +#!/bin/bash +# +# Configuration file for /usr/sbin/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 +# NICE - Change the raid check CPU and IO priority in order to make +# the system more responsive during lengthy checks. Valid +# values are high, normal, low, idle. +# +# Note: the raid-check script is run by the /etc/cron.d/raid-check cron job. +# Users may modify the frequency and timing at which raid-check is run by +# editing that cron job and their changes will be preserved across updates +# to the mdadm package. +# +# 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 -%>