From 78c08ad6dca9fc11a139384c9c5073640d99cc69 Mon Sep 17 00:00:00 2001 From: Thomas Goirand Date: Tue, 15 May 2018 14:19:03 +0200 Subject: [PATCH] Add environment param to service_validation.pp To be able to pass OS_PASSWORD=, we need the environment param to be added to this class. Needed-By: I8ab8a2c7bb1d93d6fb9d16eabd3a1112b1e1237b Change-Id: If10b57a38c61cadca48e1e3c1e76d659397849fb --- manifests/service_validation.pp | 6 ++++++ ...e-validation-environment-ad85f84da786768c.yaml | 6 ++++++ .../openstacklib_service_validation_spec.rb | 15 ++++++++++++--- 3 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 releasenotes/notes/service-validation-environment-ad85f84da786768c.yaml diff --git a/manifests/service_validation.pp b/manifests/service_validation.pp index 39f0fa6e..91f735d3 100644 --- a/manifests/service_validation.pp +++ b/manifests/service_validation.pp @@ -61,6 +61,10 @@ # Run the exec if all conditions in the array return false. # string or array; optional; default to 'undef' # +# [*environment*] +# Environment to use +# string; optional; default to empty array +# define openstacklib::service_validation( $command, $service_name = $name, @@ -72,6 +76,7 @@ define openstacklib::service_validation( $try_sleep = '2', $onlyif = undef, $unless = undef, + $environment = [], ) { if $onlyif and $unless { @@ -80,6 +85,7 @@ define openstacklib::service_validation( exec { "execute ${service_name} validation": command => $command, + environment => $environment, path => $path, provider => $provider, refreshonly => $refreshonly, diff --git a/releasenotes/notes/service-validation-environment-ad85f84da786768c.yaml b/releasenotes/notes/service-validation-environment-ad85f84da786768c.yaml new file mode 100644 index 00000000..2e734dd6 --- /dev/null +++ b/releasenotes/notes/service-validation-environment-ad85f84da786768c.yaml @@ -0,0 +1,6 @@ +--- +features: + - | + There's a new environment variable for service-validation. With it, it is + possible to pass in things like OS_PASWORD which should never appear in + the command line. diff --git a/spec/defines/openstacklib_service_validation_spec.rb b/spec/defines/openstacklib_service_validation_spec.rb index 45b5af35..2d700ffc 100644 --- a/spec/defines/openstacklib_service_validation_spec.rb +++ b/spec/defines/openstacklib_service_validation_spec.rb @@ -36,13 +36,13 @@ describe 'openstacklib::service_validation' do :path => '/usr/bin:/bin:/usr/sbin:/sbin', :provider => 'shell', :command => 'nova list', + :environment => [], :refreshonly => false, :timeout => '60', :tries => '10', :try_sleep => '2', :logoutput => 'on_failure', )} - end context 'with unless parameter' do @@ -60,12 +60,11 @@ describe 'openstacklib::service_validation' do :try_sleep => '2', :unless => 'pwd', )} - end context 'with onlyif parameter' do let :params do - required_params.merge!({:onlyif => 'pwd' }) + required_params.merge!({ :onlyif => 'pwd' }) end it { is_expected.to contain_exec("execute #{title} validation").with( @@ -78,13 +77,23 @@ describe 'openstacklib::service_validation' do :try_sleep => '2', :onlyif => 'pwd', )} + end + context 'with environment parameter' do + let :params do + required_params.merge!({ :environment => ['OS_PASSWORD=secret'] }) + end + + it { is_expected.to contain_exec("execute #{title} validation").with( + :environment => ['OS_PASSWORD=secret'], + )} end context 'when omitting a required parameter command' do let :params do required_params.delete(:command) end + it { expect { is_expected.to raise_error(Puppet::Error) } } end