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
This commit is contained in:
Takashi Kajinami 2023-02-21 21:11:16 +09:00
parent 4e25bbbe9f
commit ead07878ba
4 changed files with 47 additions and 22 deletions

View File

@ -42,11 +42,13 @@ Puppet::Type.type(:trove_datastore).provide(
fail("Failed to create datastore #{@resource[:name]}") fail("Failed to create datastore #{@resource[:name]}")
end end
if @resource[:version]
if trove_manage(['trove-manage', 'datastore_update', if trove_manage(['trove-manage', 'datastore_update',
"#{@resource[:name]}", "#{@resource[:version]}"]) != 0 "#{@resource[:name]}", "#{@resource[:version]}"]) != 0
fail("Failed to set version for datastore #{@resource[:name]}") fail("Failed to set version for datastore #{@resource[:name]}")
end end
end end
end
end end

View File

@ -19,10 +19,6 @@ Puppet::Type.newtype(:trove_datastore) do
end end
end end
validate do
raise(Puppet::Error, 'Version must be set') unless self[:version]
end
autorequire(:anchor) do autorequire(:anchor) do
['trove::service::end'] ['trove::service::end']
end end

View File

@ -14,8 +14,17 @@ describe 'basic trove' do
include openstack_integration::memcached include openstack_integration::memcached
include openstack_integration::keystone include openstack_integration::keystone
include openstack_integration::trove 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 # Run it twice and test for idempotency
apply_manifest(pp, :catch_failures => true) apply_manifest(pp, :catch_failures => true)

View File

@ -17,12 +17,15 @@ describe provider_class do
'foo' 'foo'
end end
let :resource do let :datastore_attrs do
Puppet::Type::Trove_datastore.new({ {
:name => datastore_name, :name => datastore_name,
:version => '0.1',
:ensure => 'present', :ensure => 'present',
}) }
end
let :resource do
Puppet::Type::Trove_datastore.new(datastore_attrs)
end end
let :provider do let :provider do
@ -51,6 +54,22 @@ describe provider_class do
end end
describe '#create' do describe '#create' do
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
context 'with version' do
before do
datastore_attrs.merge!(
:version => '0.1',
)
end
it 'creates datastore' do it 'creates datastore' do
expect(provider).to receive(:trove_manage) expect(provider).to receive(:trove_manage)
.with(['trove-manage', 'datastore_update', datastore_name, "''"]) .with(['trove-manage', 'datastore_update', datastore_name, "''"])
@ -59,9 +78,8 @@ describe provider_class do
expect(provider).to receive(:trove_manage) expect(provider).to receive(:trove_manage)
.with(['trove-manage', 'datastore_update', datastore_name, "0.1"]) .with(['trove-manage', 'datastore_update', datastore_name, "0.1"])
.and_return(0) .and_return(0)
provider.create provider.create
end end
end end
end
end end