Add default auth api version inherited by other cookbooks and add the

common auth uri transform logic.

- Set default auth api version for other cookbooks, which can be
  inherited and overrided by other cookbooks.

- Move the auth uri transform logic from other cookbooks to this
  openstack-common libraries.

- When auth version is v3.0, the auth uri after transformed should be
suffixed with v3.

Change-Id: I36f831e706f4538c77353849146ebd84c1ca8f14
Imlements: blueprint move-keystone-authtoken-move-auth-uri-logic
This commit is contained in:
zyouzhou-cn 2014-02-24 23:03:01 +08:00 committed by ericzhou
parent 8d0440a59d
commit 038b77fc86
4 changed files with 39 additions and 0 deletions

View File

@ -24,6 +24,8 @@ of all the settable attributes for this cookbook.
Note that all attributes are in the `default["openstack"]` "namespace"
* `openstack['api']['auth']['version']` - Select v2.0 or v3.0. Default v2.0. The default auth API version used by other components to interact with identity service.
Recipes
=======

View File

@ -270,6 +270,10 @@ default['openstack']['endpoints']['orchestration-api-cloudwatch']['bind_interfac
# Set a default region that other regions are set to - such that changing the region for all services can be done in one place
default['openstack']['region'] = 'RegionOne'
# Set a default auth api version that other components use to interact with identity service.
# Allowed auth API versions: v2.0 or v3.0. By default, it is set to v2.0.
default['openstack']['api']['auth']['version'] = 'v2.0'
# logging.conf list keypairs module_name => log level to write
default['openstack']['logging']['ignore'] = { 'nova.api.openstack.wsgi' => 'WARNING',
'nova.osapi_compute.wsgi.server' => 'WARNING' }

View File

@ -53,4 +53,18 @@ module ::Openstack # rubocop:disable Documentation
paths.map! { |path| path.sub(/^\/+/, '').sub(/\/+$/, '') }
leadingslash + paths.join('/') + trailingslash
end
def auth_uri_transform(auth_uri, auth_version)
case auth_version
when 'v2.0'
auth_uri
when 'v3.0'
# The auth_uri should contain /v2.0 in most cases, but if the
# auth_version is v3.0, we set it to v3. This is only necessary
# for environments that need to support V3 non-default-domain
# tokens, which is really the only reason to set version to
# something other than v2.0 (the default)
auth_uri.gsub('/v2.0', '/v3')
end
end
end

View File

@ -98,4 +98,23 @@ describe 'Openstack uri' do
).to eq(expected)
end
end
describe '#auth_uri_transform' do
it 'preserves the original auth uri when the auth version passed is v2.0' do
auth_version = 'v2.0'
auth_uri = 'http://localhost:5000/v2.0'
expect(
subject.auth_uri_transform(auth_uri, auth_version)
).to eq(auth_uri)
end
it 'substitute /v2.0 with /v3 in the passed auth uri when auth version passed is v3.0' do
auth_version = 'v3.0'
auth_uri = 'http://localhost:5000/v2.0'
expected_auth_uri = 'http://localhost:5000/v3'
expect(
subject.auth_uri_transform(auth_uri, auth_version)
).to eq(expected_auth_uri)
end
end
end