Merge "Add optional params for idempotency in service_validation"
This commit is contained in:
@@ -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(
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
Reference in New Issue
Block a user