Merge "Convert measurable attributes to properties"

This commit is contained in:
Zuul
2025-10-07 03:59:22 +00:00
committed by Gerrit Code Review
7 changed files with 16 additions and 14 deletions

View File

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

View File

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

View File

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

View File

@@ -19,10 +19,10 @@ Puppet::Type.newtype(:cinder_type) do
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`'
newvalues(:true, :false)
defaultto true
defaultto :true
end
newproperty(:access_project_ids, :array_matching => :all) do

View File

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

View File

@@ -34,7 +34,7 @@ describe provider_class do
describe '#create' do
it 'creates a qos' do
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"
name="QoS_1"
properties="{\'key1\': \'value1\', \'key2\': \'value2\'}"

View File

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