diff --git a/lib/puppet/provider/manila.rb b/lib/puppet/provider/manila.rb index 377c5443..3173d966 100644 --- a/lib/puppet/provider/manila.rb +++ b/lib/puppet/provider/manila.rb @@ -1,99 +1,11 @@ -require 'puppet/util/inifile' +# Since there's only one manila_* type for API resources now, +# this probably could have all gone in the provider file. +# But maybe this is good long-term. require 'puppet/provider/openstack' require 'puppet/provider/openstack/auth' -require 'puppet/provider/openstack/credentials' class Puppet::Provider::Manila < Puppet::Provider::Openstack extend Puppet::Provider::Openstack::Auth - def self.conf_filename - '/etc/manila/manila.conf' - end - - def self.manila_conf - return @manila_conf if @manila_conf - @manila_conf = Puppet::Util::IniConfig::File.new - @manila_conf.read(conf_filename) - @manila_conf - end - - def self.request(service, action, properties=nil) - begin - super - rescue Puppet::Error::OpenstackAuthInputError, Puppet::Error::OpenstackUnauthorizedError => error - manila_request(service, action, error, properties) - end - end - - def self.manila_request(service, action, error, properties=nil) - warning('Usage of keystone_authtoken parameters is deprecated.') - properties ||= [] - @credentials.username = manila_credentials['username'] - @credentials.password = manila_credentials['password'] - @credentials.project_name = manila_credentials['project_name'] - @credentials.auth_url = auth_endpoint - @credentials.user_domain_name = manila_credentials['user_domain_name'] - @credentials.project_domain_name = manila_credentials['project_domain_name'] - if manila_credentials['region_name'] - @credentials.region_name = manila_credentials['region_name'] - end - raise error unless @credentials.set? - Puppet::Provider::Openstack.request(service, action, properties, @credentials) - end - - def self.manila_credentials - @manila_credentials ||= get_manila_credentials - end - - def manila_credentials - self.class.manila_credentials - end - - def self.get_manila_credentials - auth_keys = ['auth_url', 'project_name', 'username', - 'password'] - conf = manila_conf - if conf and conf['keystone_authtoken'] and - auth_keys.all?{|k| !conf['keystone_authtoken'][k].nil?} - creds = Hash[ auth_keys.map \ - { |k| [k, conf['keystone_authtoken'][k].strip] } ] - if conf['keystone_authtoken']['project_domain_name'] - creds['project_domain_name'] = conf['keystone_authtoken']['project_domain_name'] - else - creds['project_domain_name'] = 'Default' - end - - if conf['keystone_authtoken']['user_domain_name'] - creds['user_domain_name'] = conf['keystone_authtoken']['user_domain_name'] - else - creds['user_domain_name'] = 'Default' - end - - if conf['keystone_authtoken']['region_name'] - creds['region_name'] = conf['keystone_authtoken']['region_name'] - end - - return creds - else - raise(Puppet::Error, "File: #{conf_filename} does not contain all " + - "required sections. Manila types will not work if manila is not " + - "correctly configured.") - end - end - - def self.get_auth_endpoint - q = manila_credentials - "#{q['auth_url']}" - end - - def self.auth_endpoint - @auth_endpoint ||= get_auth_endpoint - end - - def self.reset - @manila_conf = nil - @manila_credentials = nil - @auth_endpoint = nil - end end diff --git a/releasenotes/notes/stop-reading-authtoken-opts-fb13932d73d35fca.yaml b/releasenotes/notes/stop-reading-authtoken-opts-fb13932d73d35fca.yaml new file mode 100644 index 00000000..eda6e205 --- /dev/null +++ b/releasenotes/notes/stop-reading-authtoken-opts-fb13932d73d35fca.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + The ``manila_type`` resource type no longer attempts to load user + credentials from the ``[keystone_authtoken]`` section in ``manila.conf``. diff --git a/spec/unit/provider/manila_spec.rb b/spec/unit/provider/manila_spec.rb deleted file mode 100644 index cabde49c..00000000 --- a/spec/unit/provider/manila_spec.rb +++ /dev/null @@ -1,48 +0,0 @@ -require 'puppet' -require 'spec_helper' -require 'puppet/provider/manila' -require 'tempfile' - -klass = Puppet::Provider::Manila - -describe Puppet::Provider::Manila 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 manila config file does not have the expected contents' do - mock = {} - expect(Puppet::Util::IniConfig::File).to receive(:new).and_return(mock) - expect(mock).to receive(:read).with('/etc/manila/manila.conf') - expect do - klass.manila_credentials - end.to raise_error(Puppet::Error, /Manila 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', - } - } - expect(Puppet::Util::IniConfig::File).to receive(:new).and_return(mock) - expect(mock).to receive(:read).with('/etc/manila/manila.conf') - expect(klass.manila_credentials).to eq(creds_hash) - end - - end -end diff --git a/spec/unit/provider/manila_type/openstack_spec.rb b/spec/unit/provider/manila_type/openstack_spec.rb index 9774c8e5..8aaa44ad 100644 --- a/spec/unit/provider/manila_type/openstack_spec.rb +++ b/spec/unit/provider/manila_type/openstack_spec.rb @@ -35,11 +35,6 @@ describe provider_class do before(:each) { set_creds_env } - after(:each) do - Puppet::Type.type(:manila_type).provider(:openstack).reset - provider_class.reset - end - describe 'managing type' do describe '#create' do context 'with defaults' do