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:
parent
c02c1269ef
commit
c023e8bff9
@ -33,7 +33,7 @@
|
||||
# Optional
|
||||
#
|
||||
# [*metadata*]
|
||||
# String with key/value pairs. ie "key=value,key=value"
|
||||
# A key => value hash used to set the metadata for the aggregate.
|
||||
# Optional
|
||||
#
|
||||
# [*hosts*]
|
||||
@ -89,28 +89,12 @@ Puppet::Type.newtype(:nova_aggregate) do
|
||||
|
||||
newproperty(:metadata) do
|
||||
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|
|
||||
if value.is_a?(Hash)
|
||||
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
|
||||
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
|
||||
|
@ -140,23 +140,11 @@ Puppet::Type.newtype(:nova_flavor) do
|
||||
newproperty(:properties) do
|
||||
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|
|
||||
if value.is_a?(Hash)
|
||||
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
|
||||
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
|
||||
|
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':
|
||||
ensure => present,
|
||||
availability_zone => 'zone1',
|
||||
metadata => 'test=property',
|
||||
metadata => {'test' => 'property'},
|
||||
require => Class['nova::api'],
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,7 @@ describe Puppet::Type.type(:nova_aggregate).provider(:openstack) do
|
||||
:availability_zone => 'simple',
|
||||
:hosts => ['example'],
|
||||
:ensure => 'present',
|
||||
:metadata => 'nice=cookie',
|
||||
:metadata => {'nice' => 'cookie'},
|
||||
}
|
||||
end
|
||||
|
||||
@ -105,7 +105,7 @@ hosts="[\'example\']"
|
||||
:availability_zone => 'simple',
|
||||
:hosts => ['known'],
|
||||
:ensure => 'present',
|
||||
:metadata => 'nice=cookie',
|
||||
:metadata => {'nice' => 'cookie'},
|
||||
:filter_hosts => 'true'
|
||||
}
|
||||
end
|
||||
|
@ -20,7 +20,7 @@ describe Puppet::Type.type(:nova_aggregate) do
|
||||
:name => 'new_aggr',
|
||||
: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
|
||||
|
||||
it 'should raise error if wrong type for availability zone' do
|
||||
|
Loading…
Reference in New Issue
Block a user