From ead07878ba361697a10abd7b5b73d4f5c4fbfba2 Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Tue, 21 Feb 2023 21:11:16 +0900 Subject: [PATCH] trove_datastore: Make version optional datastore version can't be used until the version is registered but we can't register the version before we register datastore before applying catalog. This makes version optional to avoid that dependency look. Partial-Bug: #2007961 Change-Id: Ieba9c10b49f41980555e2734bb29415fcf0b585f --- lib/puppet/provider/trove_datastore/trove.rb | 8 ++-- lib/puppet/type/trove_datastore.rb | 4 -- spec/acceptance/10_basic_trove_spec.rb | 11 ++++- .../provider/trove_datastore/trove_spec.rb | 46 +++++++++++++------ 4 files changed, 47 insertions(+), 22 deletions(-) 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