Use only Hash value for properties
Drop support for string value and accept only hash values, to make the interface consistent with cinder_* resources. This allows us to avoid wrong interpretation of input values. Change-Id: I29a79e4a66ce91647a216511213c2a59eb49c12b
This commit is contained in:
@@ -33,7 +33,7 @@
|
|||||||
# Optional
|
# Optional
|
||||||
#
|
#
|
||||||
# [*metadata*]
|
# [*metadata*]
|
||||||
# String with key/value pairs. ie "key=value,key=value"
|
# A key => value hash used to set the metadata for the aggregate.
|
||||||
# Optional
|
# Optional
|
||||||
#
|
#
|
||||||
# [*hosts*]
|
# [*hosts*]
|
||||||
@@ -89,28 +89,12 @@ Puppet::Type.newtype(:nova_aggregate) do
|
|||||||
|
|
||||||
newproperty(:metadata) do
|
newproperty(:metadata) do
|
||||||
desc 'The metadata of the aggregate'
|
desc 'The metadata of the aggregate'
|
||||||
#convert DSL/string form to internal form which is a single hash
|
|
||||||
munge do |value|
|
|
||||||
if value.is_a?(Hash)
|
|
||||||
return value
|
|
||||||
end
|
|
||||||
internal = Hash.new
|
|
||||||
value.split(",").map{|el| el.strip()}.each do |pair|
|
|
||||||
key, value = pair.split("=", 2)
|
|
||||||
internal[key.strip()] = value.strip()
|
|
||||||
end
|
|
||||||
return internal
|
|
||||||
end
|
|
||||||
|
|
||||||
validate do |value|
|
validate do |value|
|
||||||
if value.is_a?(Hash)
|
if value.is_a?(Hash)
|
||||||
return true
|
return true
|
||||||
elsif value.is_a?(String)
|
|
||||||
value.split(",").each do |kv|
|
|
||||||
raise ArgumentError, "Key/value pairs must be separated by an =" unless value.include?("=")
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
raise ArgumentError, "Invalid metadata #{value}. Requires a String or a Hash, not a #{value.class}"
|
raise ArgumentError, "Invalid metadata #{value}. Requires a Hash, not a #{value.class}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@@ -140,23 +140,11 @@ Puppet::Type.newtype(:nova_flavor) do
|
|||||||
newproperty(:properties) do
|
newproperty(:properties) do
|
||||||
desc "The set of flavor properties"
|
desc "The set of flavor properties"
|
||||||
|
|
||||||
munge do |value|
|
|
||||||
return value if value.is_a? Hash
|
|
||||||
|
|
||||||
# wrap property value in commas
|
|
||||||
value.gsub!(/=(\w+)/, '=\'\1\'')
|
|
||||||
Hash[value.scan(/(\S+)='([^']*)'/)]
|
|
||||||
end
|
|
||||||
|
|
||||||
validate do |value|
|
validate do |value|
|
||||||
if value.is_a?(Hash)
|
if value.is_a?(Hash)
|
||||||
return true
|
return true
|
||||||
elsif value.is_a?(String)
|
|
||||||
value.split(',').each do |property|
|
|
||||||
raise ArgumentError, "Key/value pairs should be separated by an =" unless property.include?('=')
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
raise ArgumentError, "Invalid properties #{value}. Requires a String or a Hash, not a #{value.class}"
|
raise ArgumentError, "Invalid properties #{value}. Requires a Hash, not a #{value.class}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
6
releasenotes/notes/properties-hash-1d78c19fa202742b.yaml
Normal file
6
releasenotes/notes/properties-hash-1d78c19fa202742b.yaml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
upgrade:
|
||||||
|
- |
|
||||||
|
The ``properties`` property of ``nova_flavor`` resource and
|
||||||
|
the ``metadata`` property of ``nova_aggregate`` resource now accept only
|
||||||
|
Hash values.
|
@@ -20,7 +20,7 @@ describe 'basic nova' do
|
|||||||
nova_aggregate { 'test_aggregate':
|
nova_aggregate { 'test_aggregate':
|
||||||
ensure => present,
|
ensure => present,
|
||||||
availability_zone => 'zone1',
|
availability_zone => 'zone1',
|
||||||
metadata => 'test=property',
|
metadata => {'test' => 'property'},
|
||||||
require => Class['nova::api'],
|
require => Class['nova::api'],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -19,7 +19,7 @@ describe Puppet::Type.type(:nova_aggregate).provider(:openstack) do
|
|||||||
:availability_zone => 'simple',
|
:availability_zone => 'simple',
|
||||||
:hosts => ['example'],
|
:hosts => ['example'],
|
||||||
:ensure => 'present',
|
:ensure => 'present',
|
||||||
:metadata => 'nice=cookie',
|
:metadata => {'nice' => 'cookie'},
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -105,7 +105,7 @@ hosts="[\'example\']"
|
|||||||
:availability_zone => 'simple',
|
:availability_zone => 'simple',
|
||||||
:hosts => ['known'],
|
:hosts => ['known'],
|
||||||
:ensure => 'present',
|
:ensure => 'present',
|
||||||
:metadata => 'nice=cookie',
|
:metadata => {'nice' => 'cookie'},
|
||||||
:filter_hosts => 'true'
|
:filter_hosts => 'true'
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
@@ -20,7 +20,7 @@ describe Puppet::Type.type(:nova_aggregate) do
|
|||||||
:name => 'new_aggr',
|
:name => 'new_aggr',
|
||||||
:metadata => 'some_id,sd'
|
:metadata => 'some_id,sd'
|
||||||
}
|
}
|
||||||
expect { Puppet::Type.type(:nova_aggregate).new(incorrect_input) }.to raise_error(Puppet::ResourceError, /Key\/value pairs must be separated by an =/)
|
expect { Puppet::Type.type(:nova_aggregate).new(incorrect_input) }.to raise_error(Puppet::ResourceError, /Invalid metadata/)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should raise error if wrong type for availability zone' do
|
it 'should raise error if wrong type for availability zone' do
|
||||||
|
Reference in New Issue
Block a user