From a41504d2df5723d201b3b18d712427bc6d41504b Mon Sep 17 00:00:00 2001 From: Emilien Macchi Date: Wed, 10 Jun 2015 00:19:54 -0400 Subject: [PATCH] Validate service_identity resources * When creating an user, show a warning if no password has been set. * When creating a service, validate that a service_type is set. * When creating endpoints, validate *_url are set. It avoid catalog failures if a parameter is missing. Change-Id: Ibe6c467a875bbdb09faad91d7ee39edf35e30624 --- manifests/resource/service_identity.pp | 33 ++++++++++++------- ...keystone_resource_service_identity_spec.rb | 15 +++++++-- 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/manifests/resource/service_identity.pp b/manifests/resource/service_identity.pp index 4ac132205..172b95af6 100644 --- a/manifests/resource/service_identity.pp +++ b/manifests/resource/service_identity.pp @@ -156,6 +156,9 @@ define keystone::resource::service_identity( 'ignore_default_tenant' => $ignore_default_tenant, 'domain' => $user_domain_real, }) + if ! $password { + warning("No password had been set for ${auth_name} user.") + } } if $configure_user_role { @@ -166,19 +169,27 @@ define keystone::resource::service_identity( } if $configure_service { - ensure_resource('keystone_service', $service_name_real, { - 'ensure' => 'present', - 'type' => $service_type, - 'description' => $service_description, - }) + if $service_type { + ensure_resource('keystone_service', $service_name_real, { + 'ensure' => 'present', + 'type' => $service_type, + 'description' => $service_description, + }) + } else { + fail ('When configuring a service, you need to set the service_type parameter.') + } } if $configure_endpoint { - ensure_resource('keystone_endpoint', "${region}/${service_name_real}", { - 'ensure' => 'present', - 'public_url' => $public_url, - 'admin_url' => $admin_url, - 'internal_url' => $internal_url, - }) + if $public_url and $admin_url and $internal_url { + ensure_resource('keystone_endpoint', "${region}/${service_name_real}", { + 'ensure' => 'present', + 'public_url' => $public_url, + 'admin_url' => $admin_url, + 'internal_url' => $internal_url, + }) + } else { + fail ('When configuring an endpoint, you need to set the _url parameters.') + } } } diff --git a/spec/defines/keystone_resource_service_identity_spec.rb b/spec/defines/keystone_resource_service_identity_spec.rb index 63ef98ad9..2df4f00a6 100644 --- a/spec/defines/keystone_resource_service_identity_spec.rb +++ b/spec/defines/keystone_resource_service_identity_spec.rb @@ -62,11 +62,20 @@ describe 'keystone::resource::service_identity' do )} end - context 'when omitting a required parameter password' do + context 'when trying to create a service without service_type' do let :params do - required_params.delete(:password) + required_params.delete(:service_type) + required_params end - it { expect { is_expected.to raise_error(Puppet::Error) } } + it_raises 'a Puppet::Error', /When configuring a service, you need to set the service_type parameter/ + end + + context 'when trying to create an endpoint without url' do + let :params do + required_params.delete(:public_url) + required_params + end + it_raises 'a Puppet::Error', /When configuring an endpoint, you need to set the _url parameters/ end context 'with user domain' do