Add support for swift-drive-audit cron job
This change introduces the new class to configure cron job to run the swift-drive-audit CLI tool periodically. The CLI tool checks the log files to detect any device failure and umount faulty disks. Change-Id: I8aded9b59939e5a2eab04424277d9082cbda0a3a
This commit is contained in:
		
							
								
								
									
										189
									
								
								manifests/storage/drive_audit.pp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										189
									
								
								manifests/storage/drive_audit.pp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,189 @@ | |||||||
|  | # == Class swift::storage::drive_audit | ||||||
|  | # | ||||||
|  | # Set up swift-drive-audit cron job | ||||||
|  | # | ||||||
|  | # == Parameters | ||||||
|  | # | ||||||
|  | # [*user*] | ||||||
|  | #   (Optional) User with access to swift files. | ||||||
|  | #   Defaults to $::swift::params::user. | ||||||
|  | # | ||||||
|  | # [*minute*] | ||||||
|  | #   (Optional) Defaults to '1'. | ||||||
|  | # | ||||||
|  | # [*hour*] | ||||||
|  | #   (Optional) Defaults to '0'. | ||||||
|  | # | ||||||
|  | # [*monthday*] | ||||||
|  | #   (Optional) Defaults to '*'. | ||||||
|  | # | ||||||
|  | # [*month*] | ||||||
|  | #   (Optional) Defaults to '*'. | ||||||
|  | # | ||||||
|  | # [*weekday*] | ||||||
|  | #   (Optional) Defaults to '*'. | ||||||
|  | # | ||||||
|  | # [*maxdelay*] | ||||||
|  | #   (Optional) In Seconds. Should be a positive integer. | ||||||
|  | #   Induces a random delay before running the cronjob to avoid running | ||||||
|  | #   all cron jobs at the same time on all hosts this job is configured. | ||||||
|  | #   Defaults to 0. | ||||||
|  | # | ||||||
|  | # [*log_facility*] | ||||||
|  | #   (Optional) Syslog log facility. | ||||||
|  | #   Defaults to 'LOG_LOCAL2'. | ||||||
|  | # | ||||||
|  | # [*log_level*] | ||||||
|  | #   (Optional) Logging level. | ||||||
|  | #   Defaults to 'INFO'. | ||||||
|  | # | ||||||
|  | # [*log_address*] | ||||||
|  | #   (Optional) Location where syslog sends the logs to. | ||||||
|  | #   Defaults to '/dev/log'. | ||||||
|  | # | ||||||
|  | # [*log_name*] | ||||||
|  | #   (Optional) Label used when logging. | ||||||
|  | #   Defaults to 'drive-audit'. | ||||||
|  | # | ||||||
|  | # [*log_udp_host*] | ||||||
|  | #   (Optional) If not set, the UDP receiver for syslog is disabled. | ||||||
|  | #   Defaults to undef. | ||||||
|  | # | ||||||
|  | # [*log_udp_port*] | ||||||
|  | #   (Optional) Port value for UDP receiver, if enabled. | ||||||
|  | #   Defaults to undef. | ||||||
|  | # | ||||||
|  | # [*device_dir*] | ||||||
|  | #   (Optional) Directory devices are mounted under | ||||||
|  | #   Defaults to $::os_service_default. | ||||||
|  | # | ||||||
|  | # [*minutes*] | ||||||
|  | #   (Optional) Number of minutes to look back in the log file. | ||||||
|  | #   Defaults to $::os_service_default. | ||||||
|  | # | ||||||
|  | # [*error_limit*] | ||||||
|  | #   (Optional) Number of errors to find before a device is unmounted | ||||||
|  | #   Defaults to $::os_service_default. | ||||||
|  | # | ||||||
|  | # [*recon_cache_path*] | ||||||
|  | #   (Optional) The path for recon cache | ||||||
|  | #   Defaults to $::os_service_default. | ||||||
|  | # | ||||||
|  | # [*log_file_pattern*] | ||||||
|  | #   (Optional) Location of the log file with globbing pattern to check against | ||||||
|  | #   device errors. | ||||||
|  | #   Defaults to $::os_service_default. | ||||||
|  | # | ||||||
|  | # [*log_file_encoding*] | ||||||
|  | #   (Optional) The encoding used to interpret the log files. | ||||||
|  | #   Defaults to $::os_service_default. | ||||||
|  | # | ||||||
|  | # [*log_to_console*] | ||||||
|  | #   (Optional) Make drive-audit log to console in addition to syslog | ||||||
|  | #   Defaults to $::os_service_default. | ||||||
|  | # | ||||||
|  | # [*unmount_failed_device*] | ||||||
|  | #   (Optional) Unmount the device with errors detected. | ||||||
|  | #   Defaults to $::os_service_default. | ||||||
|  | # | ||||||
|  | # [*regex_pattern*] | ||||||
|  | #   (Optional) Regular expression patterns to be used to locate device blocks | ||||||
|  | #   with errors in the log file. | ||||||
|  | #   Defaults to $::os_service_default. | ||||||
|  | # | ||||||
|  | #  [*purge_config*] | ||||||
|  | #   (Optional) Whether to set only the specified config options in the drive | ||||||
|  | #   audit config. | ||||||
|  | #   Defaults to false. | ||||||
|  | # | ||||||
|  | class swift::storage::drive_audit( | ||||||
|  |   # cron options | ||||||
|  |   $user                  = $::swift::params::user, | ||||||
|  |   $minute                = 1, | ||||||
|  |   $hour                  = 0, | ||||||
|  |   $monthday              = '*', | ||||||
|  |   $month                 = '*', | ||||||
|  |   $weekday               = '*', | ||||||
|  |   $maxdelay              = 0, | ||||||
|  |   # drive-audit.conf options | ||||||
|  |   $log_facility          = 'LOG_LOCAL2', | ||||||
|  |   $log_level             = 'INFO', | ||||||
|  |   $log_address           = '/dev/log', | ||||||
|  |   $log_name              = 'drive-audit', | ||||||
|  |   $log_udp_host          = undef, | ||||||
|  |   $log_udp_port          = undef, | ||||||
|  |   $device_dir            = '/srv/node', | ||||||
|  |   $minutes               = $::os_service_default, | ||||||
|  |   $error_limit           = $::os_service_default, | ||||||
|  |   $recon_cache_path      = $::os_service_default, | ||||||
|  |   $log_file_pattern      = $::os_service_default, | ||||||
|  |   $log_file_encoding     = $::os_service_default, | ||||||
|  |   $log_to_console        = $::os_service_default, | ||||||
|  |   $unmount_failed_device = $::os_service_default, | ||||||
|  |   $regex_pattern         = {}, | ||||||
|  |   $purge_config          = false, | ||||||
|  | ) inherits swift::params { | ||||||
|  |  | ||||||
|  |   include swift::deps | ||||||
|  |  | ||||||
|  |   validate_legacy(Hash, 'validate_hash', $regex_pattern) | ||||||
|  |  | ||||||
|  |   resources { 'swift_drive_audit_config': | ||||||
|  |     purge => $purge_config, | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   swift_drive_audit_config { | ||||||
|  |     'drive-audit/log_name'    : value => $log_name; | ||||||
|  |     'drive-audit/log_facility': value => $log_facility; | ||||||
|  |     'drive-audit/log_level'   : value => $log_level; | ||||||
|  |     'drive-audit/log_address' : value => $log_address; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   if $log_udp_host { | ||||||
|  |     swift_drive_audit_config { | ||||||
|  |       'drive-audit/log_udp_host': value => $log_udp_host; | ||||||
|  |       'drive-audit/log_udp_port': value => pick($log_udp_port, $::os_service_default); | ||||||
|  |     } | ||||||
|  |   } else { | ||||||
|  |     swift_drive_audit_config { | ||||||
|  |       'drive-audit/log_udp_host': value => $::os_service_default; | ||||||
|  |       'drive-audit/log_udp_port': value => $::os_service_default; | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   swift_drive_audit_config { | ||||||
|  |     'drive-audit/user'                 : value => $user; | ||||||
|  |     'drive-audit/device_dir'           : value => $device_dir; | ||||||
|  |     'drive-audit/minutes'              : value => $minutes; | ||||||
|  |     'drive-audit/error_limit'          : value => $error_limit; | ||||||
|  |     'drive-audit/recon_cache_path'     : value => $recon_cache_path; | ||||||
|  |     'drive-audit/log_file_pattern'     : value => $log_file_pattern; | ||||||
|  |     'drive-audit/log_file_encoding'    : value => $log_file_encoding; | ||||||
|  |     'drive-audit/log_to_console'       : value => $log_to_console; | ||||||
|  |     'drive-audit/unmount_failed_device': value => $unmount_failed_device; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   $regex_pattern.each | $number, $regex | { | ||||||
|  |     swift_drive_audit_config { | ||||||
|  |       "drive-audit/regex_pattern_${number}": value => $regex; | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   if $maxdelay == 0 { | ||||||
|  |     $sleep = '' | ||||||
|  |   } else { | ||||||
|  |     $sleep = "sleep `expr \${RANDOM} \\% ${maxdelay}`; " | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   cron { 'swift-drive-audit': | ||||||
|  |     command     => "${sleep}swift-drive-audit /etc/swift/drive-audit.conf", | ||||||
|  |     environment => 'PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh', | ||||||
|  |     user        => $user, | ||||||
|  |     minute      => $minute, | ||||||
|  |     hour        => $hour, | ||||||
|  |     monthday    => $monthday, | ||||||
|  |     month       => $month, | ||||||
|  |     weekday     => $weekday, | ||||||
|  |     require     => Anchor['swift::config::end'], | ||||||
|  |   } | ||||||
|  | } | ||||||
							
								
								
									
										4
									
								
								releasenotes/notes/drive-audit-206e1c6e04e8decf.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								releasenotes/notes/drive-audit-206e1c6e04e8decf.yaml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,4 @@ | |||||||
|  | --- | ||||||
|  | features: | ||||||
|  |   - | | ||||||
|  |     The new ``swift::storage::drive_audit`` class has been added. | ||||||
							
								
								
									
										93
									
								
								spec/classes/swift_storage_driver_audit_spec.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										93
									
								
								spec/classes/swift_storage_driver_audit_spec.rb
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,93 @@ | |||||||
|  | require 'spec_helper' | ||||||
|  |  | ||||||
|  | describe 'swift::storage::drive_audit' do | ||||||
|  |   shared_examples 'swift::storage::drive_audit' do | ||||||
|  |  | ||||||
|  |     context 'with defaults' do | ||||||
|  |       it 'should configure default values' do | ||||||
|  |         should contain_swift_drive_audit_config('drive-audit/log_name').with_value('drive-audit') | ||||||
|  |         should contain_swift_drive_audit_config('drive-audit/log_facility').with_value('LOG_LOCAL2') | ||||||
|  |         should contain_swift_drive_audit_config('drive-audit/log_level').with_value('INFO') | ||||||
|  |         should contain_swift_drive_audit_config('drive-audit/log_address').with_value('/dev/log') | ||||||
|  |         should contain_swift_drive_audit_config('drive-audit/log_udp_host').with_value('<SERVICE DEFAULT>') | ||||||
|  |         should contain_swift_drive_audit_config('drive-audit/log_udp_port').with_value('<SERVICE DEFAULT>') | ||||||
|  |  | ||||||
|  |         should contain_swift_drive_audit_config('drive-audit/user').with_value('swift') | ||||||
|  |         should contain_swift_drive_audit_config('drive-audit/device_dir').with_value('/srv/node') | ||||||
|  |         should contain_swift_drive_audit_config('drive-audit/minutes').with_value('<SERVICE DEFAULT>') | ||||||
|  |         should contain_swift_drive_audit_config('drive-audit/error_limit').with_value('<SERVICE DEFAULT>') | ||||||
|  |         should contain_swift_drive_audit_config('drive-audit/recon_cache_path').with_value('<SERVICE DEFAULT>') | ||||||
|  |         should contain_swift_drive_audit_config('drive-audit/log_file_pattern').with_value('<SERVICE DEFAULT>') | ||||||
|  |         should contain_swift_drive_audit_config('drive-audit/log_file_encoding').with_value('<SERVICE DEFAULT>') | ||||||
|  |         should contain_swift_drive_audit_config('drive-audit/log_to_console').with_value('<SERVICE DEFAULT>') | ||||||
|  |         should contain_swift_drive_audit_config('drive-audit/unmount_failed_device').with_value('<SERVICE DEFAULT>') | ||||||
|  |  | ||||||
|  |         should contain_cron('swift-drive-audit').with( | ||||||
|  |           :command     => 'swift-drive-audit /etc/swift/drive-audit.conf', | ||||||
|  |           :environment => 'PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh', | ||||||
|  |           :user        => 'swift', | ||||||
|  |           :minute      => 1, | ||||||
|  |           :hour        => 0, | ||||||
|  |           :monthday    => '*', | ||||||
|  |           :month       => '*', | ||||||
|  |           :weekday     => '*', | ||||||
|  |         ) | ||||||
|  |       end | ||||||
|  |     end | ||||||
|  |  | ||||||
|  |     context 'with parameters' do | ||||||
|  |       let :params do | ||||||
|  |         { | ||||||
|  |           :maxdelay              => 30, | ||||||
|  |           :user                  => 'alt_swift', | ||||||
|  |           :device_dir            => '/opt/swift', | ||||||
|  |           :minutes               => 60, | ||||||
|  |           :error_limit           => 1, | ||||||
|  |           :recon_cache_path      => '/var/cache/swift', | ||||||
|  |           :log_file_pattern      => '/var/log/kern.*[!.][!g][!z]', | ||||||
|  |           :log_file_encoding     => 'auto', | ||||||
|  |           :log_to_console        => true, | ||||||
|  |           :unmount_failed_device => true, | ||||||
|  |           :regex_pattern         => {'1' => 'pattern1', '2' => 'pattern2'}, | ||||||
|  |         } | ||||||
|  |       end | ||||||
|  |  | ||||||
|  |       it 'should configure the given values' do | ||||||
|  |         should contain_swift_drive_audit_config('drive-audit/user').with_value('alt_swift') | ||||||
|  |         should contain_swift_drive_audit_config('drive-audit/device_dir').with_value('/opt/swift') | ||||||
|  |         should contain_swift_drive_audit_config('drive-audit/minutes').with_value(60) | ||||||
|  |         should contain_swift_drive_audit_config('drive-audit/error_limit').with_value(1) | ||||||
|  |         should contain_swift_drive_audit_config('drive-audit/recon_cache_path').with_value('/var/cache/swift') | ||||||
|  |         should contain_swift_drive_audit_config('drive-audit/log_file_pattern').with_value('/var/log/kern.*[!.][!g][!z]') | ||||||
|  |         should contain_swift_drive_audit_config('drive-audit/log_file_encoding').with_value('auto') | ||||||
|  |         should contain_swift_drive_audit_config('drive-audit/log_to_console').with_value(true) | ||||||
|  |         should contain_swift_drive_audit_config('drive-audit/unmount_failed_device').with_value(true) | ||||||
|  |         should contain_swift_drive_audit_config('drive-audit/regex_pattern_1').with_value('pattern1') | ||||||
|  |         should contain_swift_drive_audit_config('drive-audit/regex_pattern_2').with_value('pattern2') | ||||||
|  |  | ||||||
|  |         should contain_cron('swift-drive-audit').with( | ||||||
|  |           :command     => 'sleep `expr ${RANDOM} \\% 30`; swift-drive-audit /etc/swift/drive-audit.conf', | ||||||
|  |           :environment => 'PATH=/bin:/usr/bin:/usr/sbin SHELL=/bin/sh', | ||||||
|  |           :user        => 'alt_swift', | ||||||
|  |           :minute      => 1, | ||||||
|  |           :hour        => 0, | ||||||
|  |           :monthday    => '*', | ||||||
|  |           :month       => '*', | ||||||
|  |           :weekday     => '*', | ||||||
|  |         ) | ||||||
|  |       end | ||||||
|  |     end | ||||||
|  |   end | ||||||
|  |  | ||||||
|  |   on_supported_os({ | ||||||
|  |     :supported_os => OSDefaults.get_supported_os | ||||||
|  |   }).each do |os,facts| | ||||||
|  |     context "on #{os}" do | ||||||
|  |       let (:facts) do | ||||||
|  |         facts.merge(OSDefaults.get_facts()) | ||||||
|  |       end | ||||||
|  |  | ||||||
|  |       it_behaves_like 'swift::storage::drive_audit' | ||||||
|  |     end | ||||||
|  |   end | ||||||
|  | end | ||||||
		Reference in New Issue
	
	Block a user
	 Takashi Kajinami
					Takashi Kajinami