Mend nova_service provider

Option of "array_matching" automatically turns a value
into array, thus "service_name" property should be handled
as an array in nova_service provider.

Change-Id: I597a2b533a618103b64500a2aea12b3aa46b873a
This commit is contained in:
Michael Polenchuk
2016-07-07 11:23:22 +03:00
parent dd6ebe9298
commit a3230026d5
2 changed files with 7 additions and 6 deletions

View File

@@ -51,8 +51,8 @@ Puppet::Type.type(:nova_service).provide(
return unless @property_hash[:ids].kind_of?(Array)
svcname_id_map = @property_hash[:service_name].zip(@property_hash[:ids]) || {}
svcname_id_map.each do |service_name, id|
if (@resource[:service_name] == '' ||
(@resource[:service_name] == service_name))
if (@resource[:service_name].empty? ||
(@resource[:service_name].include? service_name))
self.class.request('compute service', 'delete', id)
end
end

View File

@@ -62,11 +62,12 @@ Puppet::Type.newtype(:nova_service) do
newproperty(:service_name, :array_matching => :all) do
desc "String or Array of services on a host to modify"
validate do |value|
if not value.is_a? String and not value.is_a? Array
raise ArgumentError, "service_name parameter must be String or Array"
end
raise(
ArgumentError,
'service_name parameter must be String or Array'
) unless [String, Array].any? { |type| value.is_a? type }
end
defaultto ''
defaultto []
end
end