puppet-tempest/lib/puppet/provider/tempest_glance_id_setter/openstack.rb
Takashi Kajinami affbcb0cc6 Allow arbitrary section name for *_id_setter
... so that we can set the parameters in different sections.
(eg. [database] db_flavor_ref instead of [compute] db_flavor_ref )

Implementation to inject parameters to tempset.conf is replaced by
the tempest_config type and the ini_setting provider, so that we can
use the consistent implementation to modify tempest.conf .

This change also fixes "flapping" of database/db_flavor_ref. Now
the parameter is removed by the initial tempest_config resource then
set by the tempest_glance_id_setter, when db_flavor_name is used.

Closes-Bug: #1978848
Change-Id: Ife2c563213b9b4118d3925192a2ff45253bcee2b
2022-06-17 01:51:31 +09:00

51 lines
1.5 KiB
Ruby

require File.join(File.dirname(__FILE__), '..','..','..', 'puppet/provider/tempest')
Puppet::Type.type(:tempest_glance_id_setter).provide(
:openstack,
:parent => Puppet::Provider::Tempest
) do
@credentials = Puppet::Provider::Openstack::CredentialsV3.new
def file_path
resource[:tempest_conf_path]
end
def exists?
conf = Puppet::Type::Tempest_config
.new(:title => resource[:name], :path => file_path)
entry = Puppet::Type.type(:tempest_config).provider(:ini_setting).new(conf)
entry.exists?
end
def create
conf = Puppet::Type::Tempest_config
.new(:title => resource[:name], :value => get_image_id, :path => file_path)
entry = Puppet::Type.type(:tempest_config).provider(:ini_setting).new(conf)
entry.create
end
def destroy
conf = Puppet::Type::Tempest_config
.new(:title => resource[:name], :path => file_path)
entry = Puppet::Type.type(:tempest_config).provider(:ini_setting).new(conf)
entry.destroy
end
def get_image_id
if resource[:ensure] == :present or resource[:ensure].nil?
if @image_id.nil?
images = self.class.request('image', 'list', file_path)
img = images.detect {|img| img[:name] == resource[:image_name]}
if img.nil?
raise(Puppet::Error, "Image #{resource[:image_name]} not found!")
end
@image_id = img[:id]
end
elsif resource[:ensure] != :absent
raise(Puppet::Error, "Cannot ensure to #{resource[:ensure]}")
end
@image_id
end
end