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)