Browse Source

Replace url with endpoint in credentials provider

python-openstackclient has removed the --os-url option in [1]. This
commit is part of the upcoming 4.0.0 release.

The openstack provider relies on that for Keystone initial configuration,
so we need to fix this or puppet-keystone will be broken.

[1] - https://review.opendev.org/677795

Change-Id: I50830450efe7a13be801a31f4ef0333684c7837b
changes/08/682108/5
Javier Pena 3 years ago
parent
commit
03170a9383
  1. 1
      lib/puppet/provider/openstack.rb
  2. 4
      lib/puppet/provider/openstack/credentials.rb
  3. 14
      spec/unit/provider/openstack/auth_spec.rb
  4. 10
      spec/unit/provider/openstack/credentials_spec.rb

1
lib/puppet/provider/openstack.rb

@ -119,6 +119,7 @@ class Puppet::Provider::Openstack < Puppet::Provider
break
rescue Puppet::ExecutionFailure => exception
raise Puppet::Error::OpenstackUnauthorizedError, 'Could not authenticate' if exception.message =~ /HTTP 40[13]/
raise Puppet::Error::OpenstackUnauthorizedError, 'Could not authenticate' if exception.message.match(/Missing value \S* required for auth plugin/)
if current_time > end_time
error_message = exception.message
error_message += " (tried #{retry_count}, for a total of #{end_time - start_time } seconds)"

4
lib/puppet/provider/openstack/credentials.rb

@ -5,7 +5,7 @@ class Puppet::Provider::Openstack::Credentials
KEYS = [
:auth_url, :password, :project_name, :username,
:token, :url,
:token, :endpoint, :url,
:identity_api_version,
:region_name,
:interface
@ -28,7 +28,7 @@ class Puppet::Provider::Openstack::Credentials
end
def service_token_set?
return true if @token && @url
return true if (@token && @endpoint) || (@token && @url)
end
def to_env

14
spec/unit/provider/openstack/auth_spec.rb

@ -35,7 +35,7 @@ describe Puppet::Provider::Openstack::Auth do
ENV['OS_PROJECT_NAME'] = nil
ENV['OS_AUTH_URL'] = nil
ENV['OS_TOKEN'] = nil
ENV['OS_URL'] = nil
ENV['OS_ENDPOINT'] = nil
end
describe '#set_credentials' do
@ -46,7 +46,7 @@ describe Puppet::Provider::Openstack::Auth do
'OS_PROJECT_NAME' => 'tenant',
'OS_AUTH_URL' => 'http://127.0.0.1:5000',
'OS_TOKEN' => 'token',
'OS_URL' => 'http://127.0.0.1:5000',
'OS_ENDPOINT' => 'http://127.0.0.1:5000',
'OS_IDENTITY_API_VERSION' => '2.0',
'OS_NOT_VALID' => 'notvalid'
}
@ -57,7 +57,7 @@ describe Puppet::Provider::Openstack::Auth do
"OS_PASSWORD" => "secret",
"OS_PROJECT_NAME" => "tenant",
"OS_TOKEN" => "token",
"OS_URL" => "http://127.0.0.1:5000",
"OS_ENDPOINT" => "http://127.0.0.1:5000",
"OS_USERNAME" => "user")
end
end
@ -192,7 +192,7 @@ describe Puppet::Provider::Openstack::Auth do
it 'is successful' do
klass.expects(:get_os_vars_from_env)
.returns({ 'OS_TOKEN' => 'test',
'OS_URL' => 'http://127.0.0.1:5000',
'OS_ENDPOINT' => 'http://127.0.0.1:5000',
'OS_NOT_VALID' => 'notvalid' })
klass.expects(:openstack)
.with('project', 'list', '--quiet', '--format', 'csv', ['--long'])
@ -204,7 +204,7 @@ describe Puppet::Provider::Openstack::Auth do
expect(klass.instance_variable_get(:@credentials).to_env).to eq({
'OS_IDENTITY_API_VERSION' => '3',
'OS_TOKEN' => 'test',
'OS_URL' => 'http://127.0.0.1:5000',
'OS_ENDPOINT' => 'http://127.0.0.1:5000',
})
end
end
@ -240,7 +240,7 @@ describe Puppet::Provider::Openstack::Auth do
# return incomplete creds from env
klass.expects(:get_os_vars_from_env)
.returns({ 'OS_TOKEN' => 'incomplete' })
mock = "export OS_TOKEN='test'\nexport OS_URL='abc123'\nexport OS_NOT_VALID='notvalid'\n"
mock = "export OS_TOKEN='test'\nexport OS_ENDPOINT='abc123'\nexport OS_NOT_VALID='notvalid'\n"
File.expects(:exists?).with("#{ENV['HOME']}/openrc").returns(true)
File.expects(:open).with("#{ENV['HOME']}/openrc").returns(StringIO.new(mock))
klass.expects(:openstack)
@ -253,7 +253,7 @@ describe Puppet::Provider::Openstack::Auth do
expect(klass.instance_variable_get(:@credentials).to_env).to eq({
'OS_IDENTITY_API_VERSION' => '3',
'OS_TOKEN' => 'test',
'OS_URL' => 'abc123',
'OS_ENDPOINT' => 'abc123',
})
end
end

10
spec/unit/provider/openstack/credentials_spec.rb

@ -32,7 +32,7 @@ describe Puppet::Provider::Openstack::Credentials do
context "with service credentials" do
it 'is successful' do
creds.token = 'token'
creds.url = 'url'
creds.endpoint = 'endpoint'
expect(creds.service_token_set?).to be_truthy
expect(creds.user_password_set?).to be_falsey
end
@ -88,7 +88,7 @@ describe Puppet::Provider::Openstack::Credentials do
creds.project_name = 'project_name'
creds.username = 'username'
creds.token = 'token'
creds.url = 'url'
creds.endpoint = 'endpoint'
creds.identity_api_version = 'identity_api_version'
creds.unset
expect(creds.auth_url).to eq('')
@ -96,7 +96,7 @@ describe Puppet::Provider::Openstack::Credentials do
expect(creds.project_name).to eq('')
expect(creds.username).to eq('')
expect(creds.token).to eq('')
expect(creds.url).to eq('')
expect(creds.endpoint).to eq('')
expect(creds.identity_api_version).to eq('identity_api_version')
newcreds = Puppet::Provider::Openstack::CredentialsV3.new
expect(newcreds.identity_api_version).to eq('3')
@ -112,7 +112,7 @@ describe Puppet::Provider::Openstack::Credentials do
creds.project_name = 'project_name'
creds.username = 'username'
creds.token = 'token'
creds.url = 'url'
creds.endpoint = 'endpoint'
creds.identity_api_version = 'identity_api_version'
creds.region_name = 'Region1'
expect(creds.to_env).to eq({
@ -121,7 +121,7 @@ describe Puppet::Provider::Openstack::Credentials do
'OS_PROJECT_NAME' => 'project_name',
'OS_AUTH_URL' => 'auth_url',
'OS_TOKEN' => 'token',
'OS_URL' => 'url',
'OS_ENDPOINT' => 'endpoint',
'OS_IDENTITY_API_VERSION' => 'identity_api_version',
'OS_REGION_NAME' => 'Region1',
})

Loading…
Cancel
Save