Browse Source

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
(cherry picked from commit 091c01b7b8)
(cherry picked from commit a245923a28)
changes/59/698559/1
PranaliD 1 year ago
parent
commit
e8abc91c6d
11 changed files with 280 additions and 0 deletions
  1. +10
    -0
      lib/puppet/provider/glance_image_import_config/ini_setting.rb
  2. +57
    -0
      lib/puppet/type/glance_image_import_config.rb
  3. +22
    -0
      manifests/api.pp
  4. +6
    -0
      manifests/config.pp
  5. +1
    -0
      manifests/deps.pp
  6. +7
    -0
      releasenotes/notes/enable_image_conversion_parameters-d47ac86850ad9a90.yaml
  7. +33
    -0
      spec/acceptance/glance_config_spec.rb
  8. +18
    -0
      spec/classes/glance_api_spec.rb
  9. +13
    -0
      spec/classes/glance_config_spec.rb
  10. +72
    -0
      spec/unit/provider/glance_image_import_config/ini_setting_spec.rb
  11. +41
    -0
      spec/unit/type/glance_image_import_config_spec.rb

+ 10
- 0
lib/puppet/provider/glance_image_import_config/ini_setting.rb 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

+ 57
- 0
lib/puppet/type/glance_image_import_config.rb 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

+ 22
- 0
manifests/api.pp 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
@@ -352,6 +360,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,
@@ -497,6 +507,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;

+ 6
- 0
manifests/config.pp 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.
#
@@ -51,6 +54,7 @@ class glance::config (
$registry_config = {},
$registry_paste_ini_config = {},
$cache_config = {},
$image_import_config = {},
# deprecated
$glare_config = undef,
$glare_paste_ini_config = undef,
@@ -68,10 +72,12 @@ you should use puppet-glare module for configuring Glare service.")
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)
}

+ 1
- 0
manifests/deps.pp 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']

+ 7
- 0
releasenotes/notes/enable_image_conversion_parameters-d47ac86850ad9a90.yaml 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.

+ 33
- 0
spec/acceptance/glance_config_spec.rb 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

+ 18
- 0
spec/classes/glance_api_spec.rb View File

@@ -32,6 +32,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>',
@@ -72,6 +74,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',
@@ -149,6 +153,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',

+ 13
- 0
spec/classes/glance_config_spec.rb View File

@@ -59,6 +59,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|
@@ -70,6 +82,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

+ 72
- 0
spec/unit/provider/glance_image_import_config/ini_setting_spec.rb 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

+ 41
- 0
spec/unit/type/glance_image_import_config_spec.rb 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

Loading…
Cancel
Save