diff --git a/lib/puppet/provider/trove_datastore/trove.rb b/lib/puppet/provider/trove_datastore/trove.rb index ec01af49..009ec4f7 100644 --- a/lib/puppet/provider/trove_datastore/trove.rb +++ b/lib/puppet/provider/trove_datastore/trove.rb @@ -42,9 +42,11 @@ Puppet::Type.type(:trove_datastore).provide( fail("Failed to create datastore #{@resource[:name]}") end - if trove_manage(['trove-manage', 'datastore_update', - "#{@resource[:name]}", "#{@resource[:version]}"]) != 0 - fail("Failed to set version for datastore #{@resource[:name]}") + if @resource[:version] + if trove_manage(['trove-manage', 'datastore_update', + "#{@resource[:name]}", "#{@resource[:version]}"]) != 0 + fail("Failed to set version for datastore #{@resource[:name]}") + end end end diff --git a/lib/puppet/type/trove_datastore.rb b/lib/puppet/type/trove_datastore.rb index ebe84317..1c0c6101 100644 --- a/lib/puppet/type/trove_datastore.rb +++ b/lib/puppet/type/trove_datastore.rb @@ -19,10 +19,6 @@ Puppet::Type.newtype(:trove_datastore) do end end - validate do - raise(Puppet::Error, 'Version must be set') unless self[:version] - end - autorequire(:anchor) do ['trove::service::end'] end diff --git a/spec/acceptance/10_basic_trove_spec.rb b/spec/acceptance/10_basic_trove_spec.rb index 3c5a18b9..fa698c8d 100644 --- a/spec/acceptance/10_basic_trove_spec.rb +++ b/spec/acceptance/10_basic_trove_spec.rb @@ -14,8 +14,17 @@ describe 'basic trove' do include openstack_integration::memcached include openstack_integration::keystone include openstack_integration::trove - EOS + trove_datastore { 'mysql': + } + -> trove_datastore_version { '5.7.29': + datastore => 'mysql', + manager => 'mysql', + image_id => 'dummy', + packages => '', + active => 1, + } + EOS # Run it twice and test for idempotency apply_manifest(pp, :catch_failures => true) diff --git a/spec/unit/provider/trove_datastore/trove_spec.rb b/spec/unit/provider/trove_datastore/trove_spec.rb index 853d1238..359b7ac7 100644 --- a/spec/unit/provider/trove_datastore/trove_spec.rb +++ b/spec/unit/provider/trove_datastore/trove_spec.rb @@ -17,12 +17,15 @@ describe provider_class do 'foo' end + let :datastore_attrs do + { + :name => datastore_name, + :ensure => 'present', + } + end + let :resource do - Puppet::Type::Trove_datastore.new({ - :name => datastore_name, - :version => '0.1', - :ensure => 'present', - }) + Puppet::Type::Trove_datastore.new(datastore_attrs) end let :provider do @@ -51,17 +54,32 @@ describe provider_class do end describe '#create' do - it 'creates datastore' do - expect(provider).to receive(:trove_manage) - .with(['trove-manage', 'datastore_update', datastore_name, "''"]) - .and_return(0) + context 'without version' do + it 'creates datastore' do + expect(provider).to receive(:trove_manage) + .with(['trove-manage', 'datastore_update', datastore_name, "''"]) + .and_return(0) + provider.create + end + end - expect(provider).to receive(:trove_manage) - .with(['trove-manage', 'datastore_update', datastore_name, "0.1"]) - .and_return(0) + context 'with version' do + before do + datastore_attrs.merge!( + :version => '0.1', + ) + end - provider.create + it 'creates datastore' do + expect(provider).to receive(:trove_manage) + .with(['trove-manage', 'datastore_update', datastore_name, "''"]) + .and_return(0) + + expect(provider).to receive(:trove_manage) + .with(['trove-manage', 'datastore_update', datastore_name, "0.1"]) + .and_return(0) + provider.create + end end end - end