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,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

View File

@ -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

View File

@ -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)

View File

@ -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