Merge "Replace url with endpoint in credentials provider"

This commit is contained in:
Zuul
2019-09-20 04:34:34 +00:00
committed by Gerrit Code Review
2 changed files with 16 additions and 7 deletions

View File

@@ -208,7 +208,10 @@ class Puppet::Provider::Keystone < Puppet::Provider::Openstack
def self.get_service_url def self.get_service_url
service_url = nil service_url = nil
if ENV['OS_URL'] if ENV['OS_ENDPOINT']
service_url = ENV['OS_ENDPOINT'].dup
# Compatibility with pre-4.0.0 openstackclient
elsif ENV['OS_URL']
service_url = ENV['OS_URL'].dup service_url = ENV['OS_URL'].dup
elsif public_endpoint elsif public_endpoint
service_url = public_endpoint service_url = public_endpoint
@@ -239,9 +242,15 @@ class Puppet::Provider::Keystone < Puppet::Provider::Openstack
def self.request_by_service_token(service, action, error, properties=nil, options={}) def self.request_by_service_token(service, action, error, properties=nil, options={})
properties ||= [] properties ||= []
@credentials.token = admin_token @credentials.token = admin_token
@credentials.url = service_url @credentials.endpoint = service_url
raise error unless @credentials.service_token_set? raise error unless @credentials.service_token_set?
begin
Puppet::Provider::Openstack.request(service, action, properties, @credentials, options) Puppet::Provider::Openstack.request(service, action, properties, @credentials, options)
rescue Puppet::ExecutionFailure, Puppet::Error::OpenstackUnauthorizedError
# openstackclient < 4.0.0 does not support --os-endpoint and requires --os-url
@credentials.url = service_url
Puppet::Provider::Openstack.request(service, action, properties, @credentials, options)
end
end end
def self.service_url def self.service_url

View File

@@ -260,13 +260,13 @@ id="the_user_id"
end end
describe '#get_service_url when retrieving the security token' do describe '#get_service_url when retrieving the security token' do
it 'should return nothing when OS_URL is not defined in environment' do it 'should return nothing when OS_ENDPOINT is not defined in environment' do
ENV.clear ENV.clear
expect(klass.get_service_url).to be_nil expect(klass.get_service_url).to be_nil
end end
it 'should return the OS_URL from the environment' do it 'should return the OS_ENDPOINT from the environment' do
ENV['OS_URL'] = 'http://127.0.0.1:5001/v3' ENV['OS_ENDPOINT'] = 'http://127.0.0.1:5001/v3'
expect(klass.get_service_url).to eq('http://127.0.0.1:5001/v3') expect(klass.get_service_url).to eq('http://127.0.0.1:5001/v3')
end end