From ebe908365c280d8cd8d976136c63fedb18c445ea Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fran=C3=A7ois=20Charlier?= Date: Thu, 19 Sep 2013 17:33:58 +0200 Subject: [PATCH] Allow to set full url for endpoints This changeset allows to set full url for endpoints. The default is still to use the {public,admin,internal}_{protocol,host} and port variables. The {public,admin,internal}_url parameters override the _protocol, _host & port parameters. There were previously one parameter for each {public,admin,internal} endpoint url component (protocol, host), but not port. Adding more parameters to allow different port would add too much parameters and still missing the path part. Fixes Bug#1227742 Change-Id: I834be8ab0f160b24348d218197711e8ecc392f5b --- manifests/keystone/auth.pp | 60 ++++++- spec/classes/ceilometer_keystone_auth_spec.rb | 147 ++++++++++++++---- 2 files changed, 171 insertions(+), 36 deletions(-) diff --git a/manifests/keystone/auth.pp b/manifests/keystone/auth.pp index ddf79c9..811bcfb 100644 --- a/manifests/keystone/auth.pp +++ b/manifests/keystone/auth.pp @@ -29,7 +29,7 @@ # Internal address for endpoint. Optional. Defaults to '127.0.0.1'. # # [*port*] -# Port for endpoint. Optional. Defaults to '8777'. +# Default port for enpoints. Optional. Defaults to '8777'. # # [*region*] # Region for endpoint. Optional. Defaults to 'RegionOne'. @@ -37,9 +37,36 @@ # [*tenant*] # Tenant for Ceilometer user. Optional. Defaults to 'services'. # -# [*protocol*] +# [*public_protocol*] # Protocol for public endpoint. Optional. Defaults to 'http'. # +# [*admin_protocol*] +# Protocol for admin endpoint. Optional. Defaults to 'http'. +# +# [*internal_protocol*] +# Protocol for public endpoint. Optional. Defaults to 'http'. +# +# [*public_url*] +# The endpoint's public url. +# Optional. Defaults to $public_protocol://$public_address:$port +# This url should *not* contain any API version and should have +# no trailing '/' +# Setting this variable overrides other $public_* parameters. +# +# [*admin_url*] +# The endpoint's admin url. +# Optional. Defaults to $admin_protocol://$admin_address:$port +# This url should *not* contain any API version and should have +# no trailing '/' +# Setting this variable overrides other $admin_* parameters. +# +# [*internal_url*] +# The endpoint's internal url. +# Optional. Defaults to $internal_protocol://$internal_address:$port +# This url should *not* contain any API version and should have +# no trailing '/' +# Setting this variable overrides other $internal_* parameters. +# class ceilometer::keystone::auth ( $password = false, $email = 'ceilometer@localhost', @@ -54,11 +81,32 @@ class ceilometer::keystone::auth ( $public_protocol = 'http', $admin_protocol = 'http', $internal_protocol = 'http', - $configure_endpoint = true + $configure_endpoint = true, + $public_url = undef, + $admin_url = undef, + $internal_url = undef, ) { validate_string($password) + if $public_url { + $public_url_real = $public_url + } else { + $public_url_real = "${public_protocol}://${public_address}:${port}" + } + + if $admin_url { + $admin_url_real = $admin_url + } else { + $admin_url_real = "${admin_protocol}://${admin_address}:${port}" + } + + if $internal_url { + $internal_url_real = $internal_url + } else { + $internal_url_real = "${internal_protocol}://${internal_address}:${port}" + } + Keystone_user_role["${auth_name}@${tenant}"] ~> Service <| name == 'ceilometer-api' |> @@ -86,9 +134,9 @@ class ceilometer::keystone::auth ( if $configure_endpoint { keystone_endpoint { "${region}/${auth_name}": ensure => present, - public_url => "${public_protocol}://${public_address}:${port}", - admin_url => "${admin_protocol}://${admin_address}:${port}", - internal_url => "${internal_protocol}://${internal_address}:${port}", + public_url => $public_url_real, + admin_url => $admin_url_real, + internal_url => $internal_url_real, } } } diff --git a/spec/classes/ceilometer_keystone_auth_spec.rb b/spec/classes/ceilometer_keystone_auth_spec.rb index a3e54de..15287fc 100644 --- a/spec/classes/ceilometer_keystone_auth_spec.rb +++ b/spec/classes/ceilometer_keystone_auth_spec.rb @@ -2,9 +2,8 @@ require 'spec_helper' describe 'ceilometer::keystone::auth' do - let :params do + let :default_params do { - :password => 'ceilometer-passw0rd', :email => 'ceilometer@localhost', :auth_name => 'ceilometer', :configure_endpoint => true, @@ -15,49 +14,137 @@ describe 'ceilometer::keystone::auth' do :port => '8777', :region => 'RegionOne', :tenant => 'services', - :public_protocol => 'http' + :public_protocol => 'http', + :admin_protocol => 'http', + :internal_protocol => 'http' } end shared_examples_for 'ceilometer keystone auth' do context 'without the required password parameter' do - before { params.delete(:password) } it { expect { should raise_error(Puppet::Error) } } end - it 'configures ceilometer user' do - should contain_keystone_user( params[:auth_name] ).with( - :ensure => 'present', - :password => params[:password], - :email => params[:email], - :tenant => params[:tenant] - ) + let :params do + { :password => 'ceil0met3r-passZord' } end - it 'configures ceilometer user roles' do - should contain_keystone_user_role("#{params[:auth_name]}@#{params[:tenant]}").with( - :ensure => 'present', - :roles => ['admin','ResellerAdmin'] - ) - end + context 'with the required parameters' do + it 'configures ceilometer user' do + should contain_keystone_user( default_params[:auth_name] ).with( + :ensure => 'present', + :password => params[:password], + :email => default_params[:email], + :tenant => default_params[:tenant] + ) + end + + it 'configures ceilometer user roles' do + should contain_keystone_user_role("#{default_params[:auth_name]}@#{default_params[:tenant]}").with( + :ensure => 'present', + :roles => ['admin','ResellerAdmin'] + ) + end + + it 'configures ceilometer service' do + should contain_keystone_service( default_params[:auth_name] ).with( + :ensure => 'present', + :type => default_params[:service_type], + :description => 'Openstack Metering Service' + ) + end - it 'configures ceilometer service' do - should contain_keystone_service( params[:auth_name] ).with( - :ensure => 'present', - :type => params[:service_type], - :description => 'Openstack Metering Service' - ) + it 'configure ceilometer endpoints' do + should contain_keystone_endpoint("#{default_params[:region]}/#{default_params[:auth_name]}").with( + :ensure => 'present', + :public_url => "#{default_params[:public_protocol]}://#{default_params[:public_address]}:#{default_params[:port]}", + :admin_url => "#{default_params[:admin_protocol]}://#{default_params[:admin_address]}:#{default_params[:port]}", + :internal_url => "#{default_params[:internal_protocol]}://#{default_params[:internal_address]}:#{default_params[:port]}" + ) + end end - it 'configure ceilometer endpoints' do - should contain_keystone_endpoint("#{params[:region]}/#{params[:auth_name]}").with( - :ensure => 'present', - :public_url => "#{params[:public_protocol]}://#{params[:public_address]}:#{params[:port]}", - :admin_url => "http://#{params[:admin_address]}:#{params[:port]}", - :internal_url => "http://#{params[:internal_address]}:#{params[:port]}" - ) + context 'with overriden parameters' do + before do + params.merge!({ + :email => 'mighty-ceilometer@remotehost', + :auth_name => 'mighty-ceilometer', + :service_type => 'cloud-measuring', + :public_address => '10.0.0.1', + :admin_address => '10.0.0.2', + :internal_address => '10.0.0.3', + :port => '65001', + :region => 'RegionFortyTwo', + :tenant => 'mighty-services', + :public_protocol => 'https', + :admin_protocol => 'ftp', + :internal_protocol => 'gopher' + }) + end + + it 'configures ceilometer user' do + should contain_keystone_user( params[:auth_name] ).with( + :ensure => 'present', + :password => params[:password], + :email => params[:email], + :tenant => params[:tenant] + ) + end + + it 'configures ceilometer user roles' do + should contain_keystone_user_role("#{params[:auth_name]}@#{params[:tenant]}").with( + :ensure => 'present', + :roles => ['admin','ResellerAdmin'] + ) + end + + it 'configures ceilometer service' do + should contain_keystone_service( params[:auth_name] ).with( + :ensure => 'present', + :type => params[:service_type], + :description => 'Openstack Metering Service' + ) + end + + it 'configure ceilometer endpoints' do + should contain_keystone_endpoint("#{params[:region]}/#{params[:auth_name]}").with( + :ensure => 'present', + :public_url => "#{params[:public_protocol]}://#{params[:public_address]}:#{params[:port]}", + :admin_url => "#{params[:admin_protocol]}://#{params[:admin_address]}:#{params[:port]}", + :internal_url => "#{params[:internal_protocol]}://#{params[:internal_address]}:#{params[:port]}" + ) + end + + context 'with overriden full uri' do + before do + params.merge!({ + :public_url => 'https://public.host:443/ceilometer_pub', + :admin_url => 'https://admin.host/ceilometer_adm', + :internal_url => 'http://internal.host:80/ceilometer_int', + }) + end + it 'configure ceilometer endpoints' do + should contain_keystone_endpoint("#{params[:region]}/#{params[:auth_name]}").with( + :ensure => 'present', + :public_url => params[:public_url], + :admin_url => params[:admin_url], + :internal_url => params[:internal_url] + ) + end + end + + context 'with configure_endpoint = false' do + before do + params.delete!(:configure_endpoint) + it 'does not configure ceilometer endpoints' do + should_not contain_keystone_endpoint("#{params[:region]}/#{params[:auth_name]}") + end + end + end end + + end -- 2.45.2