Enable image import conversion & image output format

Glance image conversion configuration is not enabled by
puppet-glance in glance-image-import.conf.

Adding image_import_plugins & output format parameters to enable
glance image conversion.

Change-Id: I098aa0cabf2518b8861d5b58b885d9bdef54a7f6
Closes-Bug: #1807366
This commit is contained in:
PranaliD 2018-12-04 08:53:18 +00:00 committed by Pranali Deore
parent 79c0a51dd6
commit 091c01b7b8
11 changed files with 280 additions and 0 deletions

View File

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

View File

@ -0,0 +1,57 @@
Puppet::Type.newtype(:glance_image_import_config) do
ensurable
newparam(:name, :namevar => true) do
desc 'Section/setting name to manage from glance-image-import.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

@ -114,6 +114,14 @@
# (optional) The amount of time to let an image remain in the cache without being accessed.
# Defaults to $::os_service_default.
#
# [*image_import_plugins*]
# (optional) (Array) List of enabled Image Import Plugins.
# Defaults to $::os_service_default.
#
# [*image_conversion_output_format*]
# (optional) Desired output format for image conversion plugin.
# Defaults to $::os_service_default.
#
# [*use_syslog*]
# (optional) Use syslog for logging.
# Defaults to undef
@ -355,6 +363,8 @@ class glance::api(
$image_cache_max_size = $::os_service_default,
$image_cache_stall_time = $::os_service_default,
$image_cache_dir = '/var/lib/glance/image-cache',
$image_import_plugins = $::os_service_default,
$image_conversion_output_format = $::os_service_default,
$enabled_import_methods = $::os_service_default,
$node_staging_uri = $::os_service_default,
$image_member_quota = $::os_service_default,
@ -494,6 +504,18 @@ class glance::api(
'glance_store/os_region_name': value => $os_region_name;
}
if $image_import_plugins != $::os_service_default {
$image_import_plugins_real = sprintf('[%s]', join(any2array($image_import_plugins), ','))
} else {
$image_import_plugins_real = $image_import_plugins
}
glance_image_import_config {
'image_import_opts/image_import_plugins': value => $image_import_plugins_real;
'image_conversion/output_format': value => $image_conversion_output_format;
}
# configure api service to connect registry service
glance_api_config {
'DEFAULT/registry_host': value => $registry_host;

View File

@ -32,6 +32,9 @@
# [*cache_config*]
# (optional) Allow configuration of glance-cache.conf configurations.
#
# [*image_import_config*]
# (optional) Allow configuration of glance-image-import.conf configurations.
#
# NOTE: The configuration MUST NOT be already handled by this module
# or Puppet catalog compilation will fail with duplicate resources.
#
@ -41,6 +44,7 @@ class glance::config (
$registry_config = {},
$registry_paste_ini_config = {},
$cache_config = {},
$image_import_config = {},
) {
include ::glance::deps
@ -50,10 +54,12 @@ class glance::config (
validate_hash($registry_config)
validate_hash($registry_paste_ini_config)
validate_hash($cache_config)
validate_hash($image_import_config)
create_resources('glance_api_config', $api_config)
create_resources('glance_api_paste_ini', $api_paste_ini_config)
create_resources('glance_registry_config', $registry_config)
create_resources('glance_registry_paste_ini', $registry_paste_ini_config)
create_resources('glance_cache_config', $cache_config)
create_resources('glance_image_import_config', $image_import_config)
}

View File

@ -40,6 +40,7 @@ class glance::deps {
Anchor['glance::config::begin'] -> Glance_api_config<||> ~> Anchor['glance::config::end']
Anchor['glance::config::begin'] -> Glance_api_paste_ini<||> ~> Anchor['glance::config::end']
Anchor['glance::config::begin'] -> Glance_cache_config<||> ~> Anchor['glance::config::end']
Anchor['glance::config::begin'] -> Glance_image_import_config<||> ~> Anchor['glance::config::end']
Anchor['glance::config::begin'] -> Glance_registry_config<||> ~> Anchor['glance::config::end']
Anchor['glance::config::begin'] -> Glance_registry_paste_ini<||> ~> Anchor['glance::config::end']
Anchor['glance::config::begin'] -> Glance_swift_config<||> ~> Anchor['glance::config::end']

View File

@ -0,0 +1,7 @@
---
features:
- |
Add new parameter 'image_import_plugins', to enable plugins
used by image import process.
Add parameter 'output_format', to provide desired output
format for image conversion plugin.

View File

@ -11,6 +11,7 @@ describe 'basic glance config resource' do
File <||> -> Glance_api_config <||>
File <||> -> Glance_registry_config <||>
File <||> -> Glance_cache_config <||>
File <||> -> Glance_image_import_config <||>
file { '/etc/glance' :
ensure => directory,
@ -24,6 +25,9 @@ describe 'basic glance config resource' do
file { '/etc/glance/glance-cache.conf' :
ensure => file,
}
file { '/etc/glance/glance-image-import.conf' :
ensure => file,
}
glance_api_config { 'DEFAULT/thisshouldexist' :
value => 'foo',
@ -79,6 +83,24 @@ describe 'basic glance config resource' do
ensure_absent_val => 'toto',
}
glance_image_import_config { 'DEFAULT/thisshouldexist' :
value => 'foo',
}
glance_image_import_config { 'DEFAULT/thisshouldnotexist' :
value => '<SERVICE DEFAULT>',
}
glance_image_import_config { 'DEFAULT/thisshouldexist2' :
value => '<SERVICE DEFAULT>',
ensure_absent_val => 'toto',
}
glance_image_import_config { 'DEFAULT/thisshouldnotexist2' :
value => 'toto',
ensure_absent_val => 'toto',
}
EOS
@ -120,5 +142,16 @@ describe 'basic glance config resource' do
end
end
describe file('/etc/glance/glance-image-import.conf') do
it { is_expected.to exist }
it { is_expected.to contain('thisshouldexist=foo') }
it { is_expected.to contain('thisshouldexist2=<SERVICE DEFAULT>') }
describe '#content' do
subject { super().content }
it { is_expected.not_to match /thisshouldnotexist/ }
end
end
end
end

View File

@ -33,6 +33,8 @@ describe 'glance::api' do
:scrub_time => '<SERVICE DEFAULT>',
:default_store => false,
:image_cache_dir => '/var/lib/glance/image-cache',
:image_import_plugins => '<SERVICE DEFAULT>',
:image_conversion_output_format => '<SERVICE DEFAULT>',
:enabled_import_methods => '<SERVICE DEFAULT>',
:node_staging_uri => '<SERVICE DEFAULT>',
:image_member_quota => '<SERVICE DEFAULT>',
@ -75,6 +77,8 @@ describe 'glance::api' do
:delayed_delete => 'true',
:scrub_time => '10',
:image_cache_dir => '/tmp/glance',
:image_import_plugins => 'image_conversion',
:image_conversion_output_format => 'raw',
:enabled_import_methods => 'glance-direct,web-download',
:node_staging_uri => '/tmp/staging',
:image_member_quota => '128',
@ -152,6 +156,20 @@ describe 'glance::api' do
"[%s]" % param_hash[:enabled_import_methods])
end
it 'is_expected.to lay down default image_import_plugins config' do
# Verify brackets "[]" are added to satisfy the ListOpt syntax.
is_expected.to contain_glance_image_import_config("image_import_opts/image_import_plugins").with_value(
"[%s]" % param_hash[:image_import_plugins])
end
it 'is_expected.to lay down default image_conversion image_import config' do
[
'image_conversion_output_format'
].each do |config|
is_expected.to contain_glance_image_import_config("image_conversion/output_format").with_value(param_hash[config.intern])
end
end
it 'is_expected.to lay down default cache config' do
[
'registry_host',

View File

@ -61,6 +61,18 @@ describe 'glance::config' do
end
end
shared_examples_for 'glance_image_import_config' do
let :params do
{ :image_import_config => config_hash }
end
it 'configures arbitrary glance-image-import configurations' do
is_expected.to contain_glance_image_import_config('DEFAULT/foo').with_value('fooValue')
is_expected.to contain_glance_image_import_config('DEFAULT/bar').with_value('barValue')
is_expected.to contain_glance_image_import_config('DEFAULT/baz').with_ensure('absent')
end
end
on_supported_os({
:supported_os => OSDefaults.get_supported_os
}).each do |os,facts|
@ -72,6 +84,7 @@ describe 'glance::config' do
it_configures 'glance_api_config'
it_configures 'glance_registry_config'
it_configures 'glance_cache_config'
it_configures 'glance_image_import_config'
end
end
end

View File

@ -0,0 +1,72 @@
$LOAD_PATH.push(
File.join(
File.dirname(__FILE__),
'..',
'..',
'..',
'fixtures',
'modules',
'inifile',
'lib')
)
$LOAD_PATH.push(
File.join(
File.dirname(__FILE__),
'..',
'..',
'..',
'fixtures',
'modules',
'openstacklib',
'lib')
)
require 'spec_helper'
provider_class = Puppet::Type.type(:glance_image_import_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_image_import_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_image_import_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_image_import_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_image_import_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_image_import_config'
describe 'Puppet::Type.type(:glance_image_import_config)' do
before :each do
Puppet::Type.rmtype(:glance_image_import_config)
Facter.fact(:osfamily).stubs(:value).returns(platform_params[:osfamily])
@glance_image_import_config = Puppet::Type.type(:glance_image_import_config).new(:name => 'DEFAULT/foo', :value => 'bar')
end
shared_examples_for 'glance_image_import_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_image_import_config
dependency = @glance_image_import_config.autorequire
expect(dependency.size).to eq(1)
expect(dependency[0].target).to eq(@glance_image_import_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_image_import_config'
end
context 'on RedHat platforms' do
let :platform_params do
{ :package_name => 'openstack-glance',
:osfamily => 'RedHat'}
end
it_behaves_like 'glance_image_import_config'
end
end