Skip to content

Commit

Permalink
Allow 1-element arrays for primitives in cs_group
Browse files Browse the repository at this point in the history
Having only one primitive in a group is a perfectly valid use
case. For example, one might have constraints related to an arbitrary
number of primitives created with create_resources, and the simplest
way of doing that is to place them all of them in a group, and have
the constraint point to that. Disallowing the possibility of ending up
with just one primitive in the group does not make much sense.

Update the check to allow 1-element arrays. Also, remove a misleading
comment that also looks like it was copied from some other code that
talked about colocations, not groups.

Fixes issue voxpupuli#152.
  • Loading branch information
fghaas authored and roidelapluie committed Sep 15, 2016
1 parent 16b15f6 commit 3b43295
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions lib/puppet/type/cs_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,20 @@
desc "An array of primitives to have in this group. Must be listed in the
order that you wish them to start."

# We want this to be an array, even if it has only one
# value. Prior to 4.x (and unless using the future parser in
# 3.x), Puppet would munge single-parameter arrays into scalar
# values. See also
# https://tickets.puppetlabs.com/browse/PUP-1299.
munge do |value|
Array(value)
end

# Have to redefine should= here so we can sort the array that is given to
# us by the manifest. While were checking on the class of our value we
# are going to go ahead and do some validation too. The way Corosync
# colocation works we need to only accept two value arrays.
def should=(value)
super
raise Puppet::Error, 'Puppet::Type::Cs_Group: primitives property must be at least a 2-element array.' unless value.is_a?(Array) && value.length > 1
@should
# are going to go ahead and do some validation too.
validate do |value|
raise Puppet::Error, "Puppet::Type::Cs_Group: primitives property must be at least a 1-element array." unless value.is_a? Array and value.length >= 1
end
end

Expand Down

0 comments on commit 3b43295

Please sign in to comment.