nova_aggregate: Fix match for array hosts
The property is not fully applied because of lack of array_matching definition. Change-Id: I1a9bba3e597bc61329c4526b051787723f2a7dc9
This commit is contained in:
parent
fc2f08cd45
commit
82a9b003cc
@ -37,10 +37,9 @@
|
|||||||
# Optional
|
# Optional
|
||||||
#
|
#
|
||||||
# [*hosts*]
|
# [*hosts*]
|
||||||
# A comma separated list with hosts or a single host. ie "host1,host2"
|
# An array of hosts or a single host. ie "host1,host2"
|
||||||
# Optional
|
# Optional
|
||||||
#
|
#
|
||||||
|
|
||||||
require 'puppet'
|
require 'puppet'
|
||||||
|
|
||||||
Puppet::Type.newtype(:nova_aggregate) do
|
Puppet::Type.newtype(:nova_aggregate) do
|
||||||
@ -116,16 +115,32 @@ Puppet::Type.newtype(:nova_aggregate) do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
newproperty(:hosts) do
|
newproperty(:hosts, :array_matching => :all) do
|
||||||
desc 'Single host or comma separated list of hosts'
|
desc 'Single host or array of hosts'
|
||||||
#convert DSL/string form to internal form
|
|
||||||
munge do |value|
|
def should
|
||||||
if value.is_a?(Array)
|
val = super
|
||||||
return value
|
val.flatten
|
||||||
elsif value.is_a?(String)
|
end
|
||||||
|
|
||||||
|
def should=(values)
|
||||||
|
super
|
||||||
|
@should = @should.flatten
|
||||||
|
end
|
||||||
|
|
||||||
|
def issync?(is)
|
||||||
|
return false unless is.is_a? Array
|
||||||
|
is.sort == should.sort
|
||||||
|
end
|
||||||
|
|
||||||
|
validate do |value|
|
||||||
|
if value.is_a?(String)
|
||||||
|
if value.include?(',')
|
||||||
|
warning('Using comma separated string for hosts is deprecated. Use an array instead.')
|
||||||
|
end
|
||||||
return value.split(",").map{|el| el.strip()}.sort
|
return value.split(",").map{|el| el.strip()}.sort
|
||||||
else
|
else
|
||||||
raise ArgumentError, "Invalid hosts #{value}. Requires a String or an Array, not a #{value.class}"
|
raise ArgumentError, "Invalid hosts #{value}. Requires a String, not a #{value.class}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -133,5 +148,4 @@ Puppet::Type.newtype(:nova_aggregate) do
|
|||||||
validate do
|
validate do
|
||||||
raise ArgumentError, 'Name type must be set' unless self[:name]
|
raise ArgumentError, 'Name type must be set' unless self[:name]
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -0,0 +1,10 @@
|
|||||||
|
---
|
||||||
|
upgrade:
|
||||||
|
- |
|
||||||
|
The ``nova_aggregate`` resource now requires an array value for its
|
||||||
|
``hosts`` property in case multiple hosts should belong to the aggregate.
|
||||||
|
|
||||||
|
fixes:
|
||||||
|
- |
|
||||||
|
Fixed ``nova_aggregate`` resource so that the resource ensures all values
|
||||||
|
given for the ``hosts`` property present.
|
@ -30,21 +30,21 @@ describe Puppet::Type.type(:nova_aggregate) do
|
|||||||
expect(described_class.new(:name => 'agg0',
|
expect(described_class.new(:name => 'agg0',
|
||||||
:availability_zone => 'myzone',
|
:availability_zone => 'myzone',
|
||||||
:metadata => "a=b, c=d",
|
:metadata => "a=b, c=d",
|
||||||
:hosts => "host1, host2")).to_not be_nil
|
:hosts => ['host1', 'host2'])).to_not be_nil
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should be able to create an more complex instance with hash for metadata" do
|
it "should be able to create an more complex instance with hash for metadata" do
|
||||||
expect(described_class.new(:name => 'agg0',
|
expect(described_class.new(:name => 'agg0',
|
||||||
:availability_zone => 'myzone',
|
:availability_zone => 'myzone',
|
||||||
:metadata => { 'a' => 'b', 'c' => 'd' },
|
:metadata => { 'a' => 'b', 'c' => 'd' },
|
||||||
:hosts => "host1, host2")).to_not be_nil
|
:hosts => ['host1', 'host2'])).to_not be_nil
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should be able to create an more complex instance with hash for metadata and values containing commas" do
|
it "should be able to create an more complex instance with hash for metadata and values containing commas" do
|
||||||
expect(described_class.new(:name => 'agg0',
|
expect(described_class.new(:name => 'agg0',
|
||||||
:availability_zone => 'myzone',
|
:availability_zone => 'myzone',
|
||||||
:metadata => { 'a' => 'b,e,f,g', 'c' => 'd,h,i,j' },
|
:metadata => { 'a' => 'b,e,f,g', 'c' => 'd,h,i,j' },
|
||||||
:hosts => "host1, host2")).to_not be_nil
|
:hosts => ['host1', 'host2'])).to_not be_nil
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should be able to create a instance and have the default values" do
|
it "should be able to create a instance and have the default values" do
|
||||||
@ -59,40 +59,40 @@ describe Puppet::Type.type(:nova_aggregate) do
|
|||||||
c = described_class.new(:name => 'agg0',
|
c = described_class.new(:name => 'agg0',
|
||||||
:availability_zone => 'myzone',
|
:availability_zone => 'myzone',
|
||||||
:metadata => " a = b , c= d ",
|
:metadata => " a = b , c= d ",
|
||||||
:hosts => " host1, host2 ")
|
:hosts => 'host1')
|
||||||
expect(c[:name]).to eq("agg0")
|
expect(c[:name]).to eq("agg0")
|
||||||
expect(c[:availability_zone]).to eq("myzone")
|
expect(c[:availability_zone]).to eq("myzone")
|
||||||
expect(c[:metadata]).to eq({"a" => "b", "c" => "d"})
|
expect(c[:metadata]).to eq({"a" => "b", "c" => "d"})
|
||||||
expect(c[:hosts]).to eq(["host1" , "host2"])
|
expect(c[:hosts]).to eq(['host1'])
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should return the given values with hash for metadata" do
|
it "should return the given values with hash for metadata" do
|
||||||
c = described_class.new(:name => 'agg0',
|
c = described_class.new(:name => 'agg0',
|
||||||
:availability_zone => 'myzone',
|
:availability_zone => 'myzone',
|
||||||
:metadata => { 'a' => 'b', 'c' => 'd' },,
|
:metadata => { 'a' => 'b', 'c' => 'd' },,
|
||||||
:hosts => " host1, host2 ")
|
:hosts => 'host1')
|
||||||
expect(c[:name]).to eq("agg0")
|
expect(c[:name]).to eq("agg0")
|
||||||
expect(c[:availability_zone]).to eq("myzone")
|
expect(c[:availability_zone]).to eq("myzone")
|
||||||
expect(c[:metadata]).to eq({"a" => "b", "c" => "d"})
|
expect(c[:metadata]).to eq({"a" => "b", "c" => "d"})
|
||||||
expect(c[:hosts]).to eq(["host1" , "host2"])
|
expect(c[:hosts]).to eq(['host1'])
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should return the given values with hash for metadata and values containing commas" do
|
it "should return the given values with hash for metadata and values containing commas" do
|
||||||
c = described_class.new(:name => 'agg0',
|
c = described_class.new(:name => 'agg0',
|
||||||
:availability_zone => 'myzone',
|
:availability_zone => 'myzone',
|
||||||
:metadata => { 'a' => 'b,e,f,g', 'c' => 'd,h,i,j' },
|
:metadata => { 'a' => 'b,e,f,g', 'c' => 'd,h,i,j' },
|
||||||
:hosts => " host1, host2 ")
|
:hosts => 'host1')
|
||||||
expect(c[:name]).to eq("agg0")
|
expect(c[:name]).to eq("agg0")
|
||||||
expect(c[:availability_zone]).to eq("myzone")
|
expect(c[:availability_zone]).to eq("myzone")
|
||||||
expect(c[:metadata]).to eq({"a" => "b", "c" => "d"})
|
expect(c[:metadata]).to eq({"a" => "b", "c" => "d"})
|
||||||
expect(c[:hosts]).to eq(["host1" , "host2"])
|
expect(c[:hosts]).to eq(['host1'])
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should return the given values" do
|
it "should return the given values" do
|
||||||
c = described_class.new(:name => 'agg0',
|
c = described_class.new(:name => 'agg0',
|
||||||
:availability_zone => "",
|
:availability_zone => "",
|
||||||
:metadata => "",
|
:metadata => "",
|
||||||
:hosts => "")
|
:hosts => [])
|
||||||
expect(c[:name]).to eq("agg0")
|
expect(c[:name]).to eq("agg0")
|
||||||
expect(c[:availability_zone]).to eq("")
|
expect(c[:availability_zone]).to eq("")
|
||||||
expect(c[:metadata]).to eq({})
|
expect(c[:metadata]).to eq({})
|
||||||
|
@ -25,7 +25,7 @@ describe Puppet::Type.type(:nova_aggregate) do
|
|||||||
|
|
||||||
it 'should raise error if wrong type for availability zone' do
|
it 'should raise error if wrong type for availability zone' do
|
||||||
incorrect_input = {
|
incorrect_input = {
|
||||||
:name => 'new_aggr',
|
:name => 'new_aggr',
|
||||||
:availability_zone => {'zone'=>'23'},
|
:availability_zone => {'zone'=>'23'},
|
||||||
}
|
}
|
||||||
expect { Puppet::Type.type(:nova_aggregate).new(incorrect_input) }.to raise_error(Puppet::ResourceError, /availability zone must be a String/)
|
expect { Puppet::Type.type(:nova_aggregate).new(incorrect_input) }.to raise_error(Puppet::ResourceError, /availability zone must be a String/)
|
||||||
@ -33,7 +33,7 @@ describe Puppet::Type.type(:nova_aggregate) do
|
|||||||
|
|
||||||
it 'should raise error if non-boolean-y input for filter_hosts' do
|
it 'should raise error if non-boolean-y input for filter_hosts' do
|
||||||
incorrect_input = {
|
incorrect_input = {
|
||||||
:name => 'new_aggr',
|
:name => 'new_aggr',
|
||||||
:filter_hosts => 'some non boolean-y value',
|
:filter_hosts => 'some non boolean-y value',
|
||||||
}
|
}
|
||||||
expect { Puppet::Type.type(:nova_aggregate).new(incorrect_input) }.to raise_error(Puppet::ResourceError, /Valid values are true, false/)
|
expect { Puppet::Type.type(:nova_aggregate).new(incorrect_input) }.to raise_error(Puppet::ResourceError, /Valid values are true, false/)
|
||||||
|
Loading…
Reference in New Issue
Block a user