From 1f858293f3b2a9fb3f64bf8233b7c1bddb9f270d Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Tue, 22 Feb 2022 00:01:27 +0900 Subject: [PATCH] Fix authtoken parameters to load service user credential This change fixes the old authtoken parameters used to load credential of the mistral service user, because these are no longer configured by puppet-mistral. Closes-Bug: #1961601 Change-Id: Idb55a4a64edd35b8fb9608fc36e2a91502f5de14 --- lib/puppet/provider/mistral.rb | 9 ++-- .../notes/bug-1961601-1df5a15bead1daf3.yaml | 5 ++ spec/unit/provider/mistral_spec.rb | 48 +++++++++++++++++++ 3 files changed, 57 insertions(+), 5 deletions(-) create mode 100644 releasenotes/notes/bug-1961601-1df5a15bead1daf3.yaml create mode 100644 spec/unit/provider/mistral_spec.rb diff --git a/lib/puppet/provider/mistral.rb b/lib/puppet/provider/mistral.rb index 9518c8c..98eccc1 100644 --- a/lib/puppet/provider/mistral.rb +++ b/lib/puppet/provider/mistral.rb @@ -17,9 +17,9 @@ class Puppet::Provider::Mistral < Puppet::Provider::MistralWorkflowRequester def self.mistral_request(service, action, error, properties=nil) properties ||= [] - @credentials.username = mistral_credentials['admin_username'] - @credentials.password = mistral_credentials['admin_password'] - @credentials.project_name = mistral_credentials['admin_project_name'] + @credentials.username = mistral_credentials['username'] + @credentials.password = mistral_credentials['password'] + @credentials.project_name = mistral_credentials['project_name'] @credentials.auth_url = auth_endpoint if mistral_credentials['region_name'] @credentials.region_name = mistral_credentials['region_name'] @@ -57,8 +57,7 @@ class Puppet::Provider::Mistral < Puppet::Provider::MistralWorkflowRequester end def self.get_mistral_credentials - auth_keys = ['auth_url', 'admin_tenant_name', 'admin_user', - 'admin_password'] + auth_keys = ['auth_url', 'project_name', 'username', 'password'] conf = mistral_conf if conf and conf['keystone_authtoken'] and auth_keys.all?{|k| !conf['keystone_authtoken'][k].nil?} diff --git a/releasenotes/notes/bug-1961601-1df5a15bead1daf3.yaml b/releasenotes/notes/bug-1961601-1df5a15bead1daf3.yaml new file mode 100644 index 0000000..6d808e7 --- /dev/null +++ b/releasenotes/notes/bug-1961601-1df5a15bead1daf3.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - | + Now the base ``Puppet::Provider::Mistral`` class loads service user + credential using the proper keystoneauth parameters. diff --git a/spec/unit/provider/mistral_spec.rb b/spec/unit/provider/mistral_spec.rb new file mode 100644 index 0000000..4913d28 --- /dev/null +++ b/spec/unit/provider/mistral_spec.rb @@ -0,0 +1,48 @@ +require 'puppet' +require 'spec_helper' +require 'puppet/provider/mistral' +require 'tempfile' + +klass = Puppet::Provider::Mistral + +describe Puppet::Provider::Mistral do + + after :each do + klass.reset + end + + describe 'when retrieving the auth credentials' do + + it 'should fail if no auth params are passed and the mistral config file does not have the expected contents' do + mock = {} + Puppet::Util::IniConfig::File.expects(:new).returns(mock) + mock.expects(:read).with('/etc/mistral/mistral.conf') + expect do + klass.mistral_credentials + end.to raise_error(Puppet::Error, /Mistral types will not work/) + end + + it 'should read conf file with all sections' do + creds_hash = { + 'auth_url' => 'https://192.168.56.210:5000/v3/', + 'project_name' => 'admin_tenant', + 'username' => 'admin', + 'password' => 'password', + 'project_domain_name' => 'Default', + 'user_domain_name' => 'Default', + } + mock = { + 'keystone_authtoken' => { + 'auth_url' => 'https://192.168.56.210:5000/v3/', + 'project_name' => 'admin_tenant', + 'username' => 'admin', + 'password' => 'password', + } + } + Puppet::Util::IniConfig::File.expects(:new).returns(mock) + mock.expects(:read).with('/etc/mistral/mistral.conf') + expect(klass.mistral_credentials).to eq(creds_hash) + end + + end +end