Use :commands interface for trove-manage

The trove_manage function is quite redundant because it requires
the full argument even including the trove-manage command itself.

This refactors the function using the :commands definition.

Change-Id: Icce7f9a984484c64fe4fec63cfaa93b50d3b4f14
This commit is contained in:
Takashi Kajinami 2023-11-16 15:51:07 +09:00
parent f99ea85cd3
commit d1d0a1ebc5
5 changed files with 16 additions and 23 deletions

View File

@ -11,6 +11,9 @@ class Puppet::Provider::Trove < Puppet::Provider::Openstack
extend Puppet::Provider::Openstack::Auth
initvars # so commands will work
commands :trove_manage => 'trove-manage'
def self.request(service, action, properties=nil)
begin
super
@ -106,8 +109,6 @@ class Puppet::Provider::Trove < Puppet::Provider::Openstack
end
def trove_manage(*args)
cmd = args.join(" ")
output = `#{cmd}`
$?.exitstatus
execute([command(:trove_manage)] + args)
end
end

View File

@ -37,18 +37,11 @@ Puppet::Type.type(:trove_datastore).provide(
end
def create
if trove_manage(['trove-manage', 'datastore_update',
"#{@resource[:name]}", "''"]) != 0
fail("Failed to create datastore #{@resource[:name]}")
end
trove_manage(['datastore_update', "#{@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
trove_manage(['datastore_update', "#{@resource[:name]}", "#{@resource[:version]}"])
end
end
end

View File

@ -34,13 +34,12 @@ Puppet::Type.type(:trove_datastore_version).provide(
end
def create
cmd = ['trove-manage', 'datastore_version_update',
"#{@resource[:datastore]}", "#{@resource[:name]}",
"#{@resource[:manager]}", "#{@resource[:image_id]}",
"#{@resource[:packages]}", "#{@resource[:active]}"]
if trove_manage(cmd) != 0
fail("Failed to create datastore version #{@resource[:name]}")
end
trove_manage([
'datastore_version_update',
"#{@resource[:datastore]}", "#{@resource[:name]}",
"#{@resource[:manager]}", "#{@resource[:image_id]}",
"#{@resource[:packages]}", "#{@resource[:active]}"
])
end
def destroy

View File

@ -57,7 +57,7 @@ describe provider_class do
context 'without version' do
it 'creates datastore' do
expect(provider).to receive(:trove_manage)
.with(['trove-manage', 'datastore_update', datastore_name, "''"])
.with(['datastore_update', datastore_name, "''"])
.and_return(0)
provider.create
end
@ -72,11 +72,11 @@ describe provider_class do
it 'creates datastore' do
expect(provider).to receive(:trove_manage)
.with(['trove-manage', 'datastore_update', datastore_name, "''"])
.with(['datastore_update', datastore_name, "''"])
.and_return(0)
expect(provider).to receive(:trove_manage)
.with(['trove-manage', 'datastore_update', datastore_name, "0.1"])
.with(['datastore_update', datastore_name, "0.1"])
.and_return(0)
provider.create
end

View File

@ -50,7 +50,7 @@ describe provider_class do
describe '#create' do
it 'should call trove-manage' do
expect(provider). to receive(:trove_manage).with(
['trove-manage', 'datastore_version_update', datastore_name,
['datastore_version_update', datastore_name,
datastore_version, 'mysql', '1234', 'mysql', '1']
).and_return(0)