Convert measurable attributes to properties

The parameters are used for values which affects how puppet interact
with the resource, while the properties should be used for values which
can be measured in the target system.

This allows us to make sure that these values are actually synced with
the existing resources.

Change-Id: Ie62c898f7d029caff797fd9eba4c5ddb36a90b78
Signed-off-by: Takashi Kajinami <kajinamit@oss.nttdata.com>
This commit is contained in:
Takashi Kajinami
2025-10-02 18:33:16 +09:00
parent b1464bb83b
commit 2c0b027dfc
7 changed files with 16 additions and 14 deletions

View File

@@ -13,9 +13,7 @@ Puppet::Type.type(:cinder_qos).provide(
def create def create
properties = [] properties = []
unless resource[:consumer].empty? properties << '--consumer' << resource[:consumer].to_s
properties << '--consumer' << resource[:consumer]
end
if resource[:properties] if resource[:properties]
resource[:properties].each do |k, v| resource[:properties].each do |k, v|
properties << '--property' << "#{k}=#{v}" properties << '--property' << "#{k}=#{v}"
@@ -76,7 +74,7 @@ Puppet::Type.type(:cinder_qos).provide(
:ensure => :present, :ensure => :present,
:id => qos[:id], :id => qos[:id],
:properties => parse_python_dict(properties), :properties => parse_python_dict(properties),
:consumer => qos[:consumer], :consumer => qos[:consumer].downcase,
:associations => string2array(qos[:associations]) :associations => string2array(qos[:associations])
}) })
end end

View File

@@ -23,7 +23,7 @@ Puppet::Type.type(:cinder_type).provide(
self.class.request('volume type', 'create', properties) self.class.request('volume type', 'create', properties)
@property_hash[:ensure] = :present @property_hash[:ensure] = :present
@property_hash[:properties] = resource[:properties] @property_hash[:properties] = resource[:properties]
@property_hash[:is_public] = resource[:is_public] @property_hash[:is_public] = resource[:is_public].downcase.to_sym
@property_hash[:name] = name @property_hash[:name] = name
unless @resource[:access_project_ids].nil? unless @resource[:access_project_ids].nil?
set_access_project_ids(resource[:access_project_ids]) set_access_project_ids(resource[:access_project_ids])
@@ -85,10 +85,10 @@ Puppet::Type.type(:cinder_type).provide(
if type[:is_public] == 'False' if type[:is_public] == 'False'
type_details = request('volume type', 'show', type[:id]) type_details = request('volume type', 'show', type[:id])
type[:access_project_ids] = string2array(type_details[:access_project_ids]) type[:access_project_ids] = string2array(type_details[:access_project_ids])
type[:is_public] = false type[:is_public] = :false
else else
type[:access_project_ids] = [] type[:access_project_ids] = []
type[:is_public] = true type[:is_public] = :true
end end
end end

View File

@@ -31,9 +31,10 @@ Puppet::Type.newtype(:cinder_qos) do
end end
end end
newparam(:consumer) do newproperty(:consumer) do
desc 'The consumer QOS' desc 'The consumer QOS'
defaultto('') newvalues('front-end', 'back-end', 'both')
defaultto('both')
end end
autorequire(:cinder_qos) do autorequire(:cinder_qos) do

View File

@@ -19,10 +19,10 @@ Puppet::Type.newtype(:cinder_type) do
end end
end end
newparam(:is_public, :boolean => true) do newproperty(:is_public, :boolean => true) do
desc 'Whether the type is public or not. Default to `true`' desc 'Whether the type is public or not. Default to `true`'
newvalues(:true, :false) newvalues(:true, :false)
defaultto true defaultto :true
end end
newproperty(:access_project_ids, :array_matching => :all) do newproperty(:access_project_ids, :array_matching => :all) do

View File

@@ -38,6 +38,9 @@ describe 'basic cinder' do
cinder_qos { 'testqos2': cinder_qos { 'testqos2':
associations => ['qostype1', 'qostype2'] associations => ['qostype1', 'qostype2']
} }
cinder_qos { 'testqos3':
consumer => 'front-end',
}
EOS EOS

View File

@@ -34,7 +34,7 @@ describe provider_class do
describe '#create' do describe '#create' do
it 'creates a qos' do it 'creates a qos' do
expect(provider_class).to receive(:openstack) expect(provider_class).to receive(:openstack)
.with('volume qos', 'create', '--format', 'shell', ['--property', 'key1=value1', '--property', 'key2=value2', 'QoS_1']) .with('volume qos', 'create', '--format', 'shell', ['--consumer', 'both', '--property', 'key1=value1', '--property', 'key2=value2', 'QoS_1'])
.and_return('id="e0df397a-72d5-4494-9e26-4ac37632ff04" .and_return('id="e0df397a-72d5-4494-9e26-4ac37632ff04"
name="QoS_1" name="QoS_1"
properties="{\'key1\': \'value1\', \'key2\': \'value2\'}" properties="{\'key1\': \'value1\', \'key2\': \'value2\'}"

View File

@@ -82,8 +82,8 @@ access_project_ids="54f4d231201b4944a5fa4587a09bda23, 54f4d231201b4944a5fa4587a0
expect(instances.count).to eq(2) expect(instances.count).to eq(2)
expect(instances[0].name).to eq('type-1') expect(instances[0].name).to eq('type-1')
expect(instances[1].name).to eq('type-2') expect(instances[1].name).to eq('type-2')
expect(instances[0].is_public).to be true expect(instances[0].is_public).to be :true
expect(instances[1].is_public).to be false expect(instances[1].is_public).to be :false
expect(instances[0].access_project_ids).to match_array([]) expect(instances[0].access_project_ids).to match_array([])
expect(instances[1].access_project_ids).to match_array(['54f4d231201b4944a5fa4587a09bda23', '54f4d231201b4944a5fa4587a09bda28']) expect(instances[1].access_project_ids).to match_array(['54f4d231201b4944a5fa4587a09bda23', '54f4d231201b4944a5fa4587a09bda28'])
expect(instances[0].properties).to eq({'key1'=>'value1'}) expect(instances[0].properties).to eq({'key1'=>'value1'})