Merge "Add optional params for idempotency in service_validation"

This commit is contained in:
Jenkins
2016-07-14 22:12:34 +00:00
committed by Gerrit Code Review
2 changed files with 57 additions and 0 deletions

View File

@@ -45,6 +45,14 @@
# Number of seconds between validation attempts; # Number of seconds between validation attempts;
# string; optional; default to '2' # 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( define openstacklib::service_validation(
$command, $command,
$service_name = $name, $service_name = $name,
@@ -52,14 +60,22 @@ define openstacklib::service_validation(
$provider = shell, $provider = shell,
$tries = '10', $tries = '10',
$try_sleep = '2', $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": exec { "execute ${service_name} validation":
path => $path, path => $path,
provider => $provider, provider => $provider,
command => $command, command => $command,
tries => $tries, tries => $tries,
try_sleep => $try_sleep, try_sleep => $try_sleep,
onlyif => $onlyif,
unless => $unless,
} }
anchor { "create ${service_name} anchor": anchor { "create ${service_name} anchor":
@@ -67,3 +83,4 @@ define openstacklib::service_validation(
} }
} }

View File

@@ -46,6 +46,46 @@ describe 'openstacklib::service_validation' do
end 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 context 'when omitting a required parameter command' do
let :params do let :params do
required_params.delete(:command) required_params.delete(:command)