diff --git a/manifests/service_validation.pp b/manifests/service_validation.pp index 8a9ccd05..93905fba 100644 --- a/manifests/service_validation.pp +++ b/manifests/service_validation.pp @@ -45,6 +45,14 @@ # Number of seconds between validation attempts; # string; optional; default to '2' # +# [*onlyif*] +# Run the exec if all conditions in the array return true. +# string or array; optional; default to 'undef' +# +# [*unless*] +# Run the exec if all conditions in the array return false. +# string or array; optional; default to 'undef' +# define openstacklib::service_validation( $command, $service_name = $name, @@ -52,14 +60,22 @@ define openstacklib::service_validation( $provider = shell, $tries = '10', $try_sleep = '2', + $onlyif = undef, + $unless = undef, ) { + if $onlyif and $unless { + fail ('Only one parameter should be declared: onlyif or unless') + } + exec { "execute ${service_name} validation": path => $path, provider => $provider, command => $command, tries => $tries, try_sleep => $try_sleep, + onlyif => $onlyif, + unless => $unless, } anchor { "create ${service_name} anchor": @@ -67,3 +83,4 @@ define openstacklib::service_validation( } } + diff --git a/spec/defines/openstacklib_service_validation_spec.rb b/spec/defines/openstacklib_service_validation_spec.rb index cc196f07..1d1b4067 100644 --- a/spec/defines/openstacklib_service_validation_spec.rb +++ b/spec/defines/openstacklib_service_validation_spec.rb @@ -46,6 +46,46 @@ describe 'openstacklib::service_validation' do end + context 'with unless parameter' do + let :params do + required_params.merge!({ :unless => 'pwd' }) + end + + it { is_expected.to contain_exec("execute #{title} validation").with( + :path => '/usr/bin:/bin:/usr/sbin:/sbin', + :provider => 'shell', + :command => 'nova list', + :tries => '10', + :try_sleep => '2', + :unless => 'pwd', + )} + + it { is_expected.to contain_anchor("create #{title} anchor").with( + :require => "Exec[execute #{title} validation]", + )} + + end + + context 'with onlyif parameter' do + let :params do + required_params.merge!({:onlyif => 'pwd' }) + end + + it { is_expected.to contain_exec("execute #{title} validation").with( + :path => '/usr/bin:/bin:/usr/sbin:/sbin', + :provider => 'shell', + :command => 'nova list', + :tries => '10', + :try_sleep => '2', + :onlyif => 'pwd', + )} + + it { is_expected.to contain_anchor("create #{title} anchor").with( + :require => "Exec[execute #{title} validation]", + )} + + end + context 'when omitting a required parameter command' do let :params do required_params.delete(:command)