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
commit d15ec4ffc7
2 changed files with 57 additions and 0 deletions

@ -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(
}
}

@ -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)