From 55421df42cd832dfdf073f455d21ce4782e6c92c Mon Sep 17 00:00:00 2001 From: Julien Pivotto Date: Fri, 19 Aug 2016 10:47:30 +0200 Subject: [PATCH] Test corosync config where appropriate Signed-off-by: Julien Pivotto --- manifests/init.pp | 35 ++++++++++++++++++++++++++++------- manifests/params.pp | 21 +++++++++++++++++---- spec/classes/corosync_spec.rb | 16 ++++++++++++++++ 3 files changed, 61 insertions(+), 11 deletions(-) diff --git a/manifests/init.pp b/manifests/init.pp index 5095cf4f..e4e4ad15 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -192,6 +192,10 @@ # to 256000 / netmtu to prevent overflow of the kernel transmit buffers. # Defaults to 17 # +# [*test_corosync_config*] +# Wheter we should test new configuration files with `corosync -t`. +# Defaults to true on OS that allows that (requires corosync 2.3.4). +# # === Examples # # class { 'corosync': @@ -251,6 +255,7 @@ $join = $::corosync::params::join, $consensus = $::corosync::params::consensus, $max_messages = $::corosync::params::max_messages, + $test_corosync_config = $::corosync::params::test_corosync_config, ) inherits ::corosync::params { if $set_votequorum and !$quorum_members { @@ -370,13 +375,29 @@ # - $join # - $consensus # - $max_messages - file { '/etc/corosync/corosync.conf': - ensure => file, - mode => '0644', - owner => 'root', - group => 'root', - content => template($corosync_conf), - require => Package['corosync'], + if $test_corosync_config { + # corosync -t is only included since 2.3.4 + file { '/etc/corosync/corosync.conf': + ensure => file, + mode => '0644', + owner => 'root', + group => 'root', + content => template($corosync_conf), + validate_cmd => '/usr/bin/env COROSYNC_MAIN_CONFIG_FILE=% /usr/sbin/corosync -t', + require => [ + File['/etc/corosync/authkey'], + Package['corosync'], + ], + } + } else { + file { '/etc/corosync/corosync.conf': + ensure => file, + mode => '0644', + owner => 'root', + group => 'root', + content => template($corosync_conf), + require => Package['corosync'], + } } file { '/etc/corosync/service.d': diff --git a/manifests/params.pp b/manifests/params.pp index 375398f7..6793bba7 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -38,8 +38,10 @@ $compatibility = 'whitetank' if versioncmp($::operatingsystemrelease, '7') >= 0 { $manage_pacemaker_service = true + $test_corosync_config = true } else { $manage_pacemaker_service = false + $test_corosync_config = false } $package_install_options = undef } @@ -54,15 +56,23 @@ $set_votequorum = true $manage_pacemaker_service = true - file {'/etc/default/cman': - ensure => present, - content => template('corosync/cman.erb'), - } + if versioncmp($::operatingsystemrelease, '16.04') >= 0 { + $test_corosync_config = true + } else { + + #FIXME should be moved in another place + file {'/etc/default/cman': + ensure => present, + content => template('corosync/cman.erb'), + } + $test_corosync_config = false + } } else { $compatibility = 'whitetank' $set_votequorum = false $manage_pacemaker_service = false + $test_corosync_config = false } $package_install_options = undef } @@ -72,11 +82,13 @@ $compatibility = false $manage_pacemaker_service = true $package_install_options = ['-t', 'jessie-backports'] + $test_corosync_config = true } else { $set_votequorum = false $compatibility = 'whitetank' $manage_pacemaker_service = false $package_install_options = undef + $test_corosync_config = false } } default : { @@ -84,6 +96,7 @@ $set_votequorum = false $manage_pacemaker_service = false $package_install_options = undef + $test_corosync_config = false } } } diff --git a/spec/classes/corosync_spec.rb b/spec/classes/corosync_spec.rb index cb72b106..5e6929f8 100644 --- a/spec/classes/corosync_spec.rb +++ b/spec/classes/corosync_spec.rb @@ -268,6 +268,12 @@ } end + it 'validates the corosync configuration' do + should contain_file('/etc/corosync/corosync.conf').with_validate_cmd( + '/usr/bin/env COROSYNC_MAIN_CONFIG_FILE=% /usr/sbin/corosync -t' + ) + end + it_configures 'corosync' end @@ -288,6 +294,10 @@ it 'does not manage the pacemaker service' do should_not contain_service('pacemaker') end + + it 'does not validate the corosync configuration' do + should contain_file('/etc/corosync/corosync.conf').without_validate_cmd + end end context 'major version is 7' do @@ -302,6 +312,12 @@ ensure: 'running' ) end + + it 'validates the corosync configuration' do + should contain_file('/etc/corosync/corosync.conf').with_validate_cmd( + '/usr/bin/env COROSYNC_MAIN_CONFIG_FILE=% /usr/sbin/corosync -t' + ) + end end end end