Use glance-swift conf for swift backend

For working with Swift backend, Glance needs authentication parameters,
which are supplied to Swift when making calls to its storage system.
Glance will use information from the file specified under parameter
swift_store_config_file. When this parameter is set to the same file
(glance-api.conf), we have lot of non-critical errors in glance-api
log, because of 'Invalid format of swift store config'.

The same problem, when we have RadosGW.

Change-Id: I18ee8f68f7ce793d2580685e79ed636556c57ddd
Related-bug: #1540890
This commit is contained in:
Denis Egorenko 2016-02-02 17:26:25 +03:00
parent 7e2e1162d0
commit c8b7d3319b
6 changed files with 181 additions and 10 deletions

View File

@ -0,0 +1,10 @@
Puppet::Type.type(:glance_swift_config).provide(
:ini_setting,
:parent => Puppet::Type.type(:openstack_config).provider(:ini_setting)
) do
def self.file_path
'/etc/glance/glance-swift.conf'
end
end

View File

@ -0,0 +1,57 @@
Puppet::Type.newtype(:glance_swift_config) do
ensurable
newparam(:name, :namevar => true) do
desc 'Section/setting name to manage from glance-api.conf'
newvalues(/\S+\/\S+/)
end
newproperty(:value) do
desc 'The value of the setting to be defined.'
munge do |value|
value = value.to_s.strip
value.capitalize! if value =~ /^(true|false)$/i
value
end
newvalues(/^[\S ]*$/)
def is_to_s( currentvalue )
if resource.secret?
return '[old secret redacted]'
else
return currentvalue
end
end
def should_to_s( newvalue )
if resource.secret?
return '[new secret redacted]'
else
return newvalue
end
end
end
newparam(:secret, :boolean => true) do
desc 'Whether to hide the value from Puppet logs. Defaults to `false`.'
newvalues(:true, :false)
defaultto false
end
newparam(:ensure_absent_val) do
desc 'A value that is specified as the value property will behave as if ensure => absent was specified'
defaultto('<SERVICE DEFAULT>')
end
autorequire(:package) do
if Facter.value(:osfamily) == 'Debian'
'glance-api'
elsif Facter.value(:osfamily) == 'RedHat'
'openstack-glance'
end
end
end

View File

@ -62,8 +62,11 @@ class glance::backend::swift(
'glance_store/swift_store_endpoint_type':
value => $swift_store_endpoint_type;
'glance_store/swift_store_config_file': value => '/etc/glance/glance-api.conf';
'glance_store/swift_store_config_file': value => '/etc/glance/glance-swift.conf';
'glance_store/default_swift_reference': value => $default_swift_reference;
}
glance_swift_config {
"${default_swift_reference}/user": value => $swift_store_user;
"${default_swift_reference}/key": value => $swift_store_key;
"${default_swift_reference}/auth_address": value => $swift_store_auth_address;

View File

@ -27,12 +27,12 @@ describe 'glance::backend::swift' do
is_expected.to contain_glance_api_config('glance_store/swift_store_create_container_on_put').with_value(false)
is_expected.to contain_glance_api_config('glance_store/swift_store_endpoint_type').with_value('internalURL')
is_expected.to contain_glance_api_config('glance_store/swift_store_region').with_value(nil)
is_expected.to contain_glance_api_config('glance_store/swift_store_config_file').with_value('/etc/glance/glance-api.conf')
is_expected.to contain_glance_api_config('glance_store/swift_store_config_file').with_value('/etc/glance/glance-swift.conf')
is_expected.to contain_glance_api_config('glance_store/default_swift_reference').with_value('ref1')
is_expected.to contain_glance_api_config('ref1/key').with_value('key')
is_expected.to contain_glance_api_config('ref1/user').with_value('user')
is_expected.to contain_glance_api_config('ref1/auth_version').with_value('2')
is_expected.to contain_glance_api_config('ref1/auth_address').with_value('127.0.0.1:5000/v2.0/')
is_expected.to contain_glance_swift_config('ref1/key').with_value('key')
is_expected.to contain_glance_swift_config('ref1/user').with_value('user')
is_expected.to contain_glance_swift_config('ref1/auth_version').with_value('2')
is_expected.to contain_glance_swift_config('ref1/auth_address').with_value('127.0.0.1:5000/v2.0/')
end
end
@ -60,10 +60,10 @@ describe 'glance::backend::swift' do
is_expected.to contain_glance_api_config('glance_store/swift_store_endpoint_type').with_value('publicURL')
is_expected.to contain_glance_api_config('glance_store/swift_store_region').with_value('RegionTwo')
is_expected.to contain_glance_api_config('glance_store/default_swift_reference').with_value('swift_creds')
is_expected.to contain_glance_api_config('swift_creds/key').with_value('key2')
is_expected.to contain_glance_api_config('swift_creds/user').with_value('user2')
is_expected.to contain_glance_api_config('swift_creds/auth_version').with_value('1')
is_expected.to contain_glance_api_config('swift_creds/auth_address').with_value('127.0.0.2:8080/v1.0/')
is_expected.to contain_glance_swift_config('swift_creds/key').with_value('key2')
is_expected.to contain_glance_swift_config('swift_creds/user').with_value('user2')
is_expected.to contain_glance_swift_config('swift_creds/auth_version').with_value('1')
is_expected.to contain_glance_swift_config('swift_creds/auth_address').with_value('127.0.0.2:8080/v1.0/')
end
end

View File

@ -0,0 +1,60 @@
$LOAD_PATH.push(
File.join(
File.dirname(__FILE__),
'..',
'..',
'..',
'fixtures',
'modules',
'openstacklib',
'lib')
)
require 'spec_helper'
provider_class = Puppet::Type.type(:glance_swift_config).provider(:ini_setting)
describe provider_class do
it 'should default to the default setting when no other one is specified' do
resource = Puppet::Type::Glance_swift_config.new(
{
:name => 'DEFAULT/foo',
:value => 'bar'
}
)
provider = provider_class.new(resource)
expect(provider.section).to eq('DEFAULT')
expect(provider.setting).to eq('foo')
end
it 'should allow setting to be set explicitly' do
resource = Puppet::Type::Glance_swift_config.new(
{
:name => 'dude/foo',
:value => 'bar'
}
)
provider = provider_class.new(resource)
expect(provider.section).to eq('dude')
expect(provider.setting).to eq('foo')
end
it 'should ensure absent when <SERVICE DEFAULT> is specified as a value' do
resource = Puppet::Type::Glance_swift_config.new(
{:name => 'dude/foo', :value => '<SERVICE DEFAULT>'}
)
provider = provider_class.new(resource)
provider.exists?
expect(resource[:ensure]).to eq :absent
end
it 'should ensure absent when value matches ensure_absent_val' do
resource = Puppet::Type::Glance_swift_config.new(
{:name => 'dude/foo', :value => 'foo', :ensure_absent_val => 'foo' }
)
provider = provider_class.new(resource)
provider.exists?
expect(resource[:ensure]).to eq :absent
end
end

View File

@ -0,0 +1,41 @@
require 'puppet'
require 'puppet/type/glance_swift_config'
describe 'Puppet::Type.type(:glance_swift_config)' do
before :each do
Puppet::Type.rmtype(:glance_swift_config)
Facter.fact(:osfamily).stubs(:value).returns(platform_params[:osfamily])
@glance_swift_config = Puppet::Type.type(:glance_swift_config).new(:name => 'DEFAULT/foo', :value => 'bar')
end
shared_examples_for 'glance_swift_config' do
it 'should autorequire the package that install the file' do
catalog = Puppet::Resource::Catalog.new
package = Puppet::Type.type(:package).new(:name => platform_params[:package_name])
catalog.add_resource package, @glance_swift_config
dependency = @glance_swift_config.autorequire
expect(dependency.size).to eq(1)
expect(dependency[0].target).to eq(@glance_swift_config)
expect(dependency[0].source).to eq(package)
end
end
context 'on Debian platforms' do
let :platform_params do
{ :package_name => 'glance-api',
:osfamily => 'Debian' }
end
it_behaves_like 'glance_swift_config'
end
context 'on RedHat platforms' do
let :platform_params do
{ :package_name => 'openstack-glance',
:osfamily => 'RedHat'}
end
it_behaves_like 'glance_swift_config'
end
end