From 228627990d3e752d2a883a74fdab1fe0d4483abf Mon Sep 17 00:00:00 2001 From: Clayton O'Neill Date: Sat, 17 Sep 2016 15:18:28 +0000 Subject: [PATCH] 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 --- lib/puppet/type/cinder_type.rb | 1 + spec/acceptance/basic_cinder_spec.rb | 1 + spec/unit/type/cinder_type_spec.rb | 26 +++++++++++++++++++++++--- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/lib/puppet/type/cinder_type.rb b/lib/puppet/type/cinder_type.rb index 67ac5daf..4b5e132d 100644 --- a/lib/puppet/type/cinder_type.rb +++ b/lib/puppet/type/cinder_type.rb @@ -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 ' + defaultto [] def insync?(is) return false unless is.is_a? Array is.sort == should.sort diff --git a/spec/acceptance/basic_cinder_spec.rb b/spec/acceptance/basic_cinder_spec.rb index f1bf3c6b..6486d019 100644 --- a/spec/acceptance/basic_cinder_spec.rb +++ b/spec/acceptance/basic_cinder_spec.rb @@ -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 diff --git a/spec/unit/type/cinder_type_spec.rb b/spec/unit/type/cinder_type_spec.rb index a9e8352c..5f2bd170 100644 --- a/spec/unit/type/cinder_type_spec.rb +++ b/spec/unit/type/cinder_type_spec.rb @@ -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)