Fix cinder_type to work with no properties param

If the properties parameter isn't specified, then it defaults to nil.
However, when the provider iterates over the properties, it assumes
properties will be an array, and fails when it's nil.

Change-Id: Ie5342b0dde70394a32639e378aee9c7e6aa64a87
This commit is contained in:
Clayton O'Neill 2016-09-17 15:18:28 +00:00
parent d611f48bb8
commit 228627990d
3 changed files with 25 additions and 3 deletions

View File

@ -10,6 +10,7 @@ Puppet::Type.newtype(:cinder_type) do
newproperty(:properties, :array_matching => :all) do
desc 'The properties of the cinder type. Should be an array, all items should match pattern <key=value1[,value2 ...]>'
defaultto []
def insync?(is)
return false unless is.is_a? Array
is.sort == should.sort

View File

@ -60,6 +60,7 @@ describe 'basic cinder' do
class { '::cinder::scheduler::filter': }
class { '::cinder::volume': }
class { '::cinder::cron::db_purge': }
cinder::type { 'test-type': }
# TODO: create a backend and spawn a volume
EOS

View File

@ -7,7 +7,7 @@ describe Puppet::Type.type(:cinder_type) do
Puppet::Type.rmtype(:cinder_type)
end
it 'should reject an invalid propertie value' do
it 'should reject an invalid property value' do
incorrect_input = {
:name => 'test_type',
:properties => ['some_key1 = some_value2']
@ -15,14 +15,34 @@ describe Puppet::Type.type(:cinder_type) do
expect { Puppet::Type.type(:cinder_type).new(incorrect_input) }.to raise_error(Puppet::ResourceError, /Parameter properties failed/)
end
it 'should autorequire cinder-api service' do
it 'should default to no properties' do
catalog = Puppet::Resource::Catalog.new
anchor = Puppet::Type.type(:anchor).new(:name => 'cinder::service::end')
correct_input = {
:name => 'test_type',
:properties => ['some_key1=value', 'some_key2=value1,value2']
}
cinder_type = Puppet::Type.type(:cinder_type).new(correct_input)
expect(cinder_type[:properties]).to eq([])
catalog.add_resource anchor, cinder_type
dependency = cinder_type.autorequire
expect(dependency.size).to eq(1)
expect(dependency[0].target).to eq(cinder_type)
expect(dependency[0].source).to eq(anchor)
end
it 'should autorequire cinder-api service' do
catalog = Puppet::Resource::Catalog.new
anchor = Puppet::Type.type(:anchor).new(:name => 'cinder::service::end')
properties = ['some_key1=value', 'some_key2=value1,value2']
correct_input = {
:name => 'test_type',
:properties => properties,
}
cinder_type = Puppet::Type.type(:cinder_type).new(correct_input)
expect(cinder_type[:properties]).to eq(properties)
catalog.add_resource anchor, cinder_type
dependency = cinder_type.autorequire
expect(dependency.size).to eq(1)