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:
@@ -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
|
||||
|
@@ -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
|
||||
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -38,6 +38,9 @@ describe 'basic cinder' do
|
||||
cinder_qos { 'testqos2':
|
||||
associations => ['qostype1', 'qostype2']
|
||||
}
|
||||
cinder_qos { 'testqos3':
|
||||
consumer => 'front-end',
|
||||
}
|
||||
EOS
|
||||
|
||||
|
||||
|
@@ -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\'}"
|
||||
|
@@ -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'})
|
||||
|
Reference in New Issue
Block a user