Fix missing update of property_hash
When a resource is created, the :ensure parameter should be set to 'present' so that exists returns true. In addition, the whole hash should be cleared when a resource is deleted, otherwise subsequent access might look up stale values. This change ensures property_hash is updated in create/destroy accordingly. This change also fixes the incorrect handling of "project" property in nova_flavor which is causing unexpected update. Finally, the ignored unit tests are fixed, to test the above fixes. Change-Id: I611e3d0428674e7438fe15b276667f7b379d136e
This commit is contained in:
@@ -56,6 +56,7 @@ Puppet::Type.type(:nova_aggregate).provide(
|
|||||||
self.class.request('aggregate', 'remove host', properties)
|
self.class.request('aggregate', 'remove host', properties)
|
||||||
end
|
end
|
||||||
self.class.request('aggregate', 'delete', @property_hash[:name])
|
self.class.request('aggregate', 'delete', @property_hash[:name])
|
||||||
|
@property_hash.clear
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@@ -79,6 +80,7 @@ Puppet::Type.type(:nova_aggregate).provide(
|
|||||||
self.class.request('aggregate', 'add host', properties)
|
self.class.request('aggregate', 'add host', properties)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@property_hash[:ensure] = :present
|
||||||
end
|
end
|
||||||
|
|
||||||
def availability_zone=(value)
|
def availability_zone=(value)
|
||||||
|
@@ -30,11 +30,11 @@ Puppet::Type.type(:nova_cell_v2).provide(
|
|||||||
$database_connection = 'default'
|
$database_connection = 'default'
|
||||||
end
|
end
|
||||||
new(
|
new(
|
||||||
:name => $name,
|
:name => $name,
|
||||||
:uuid => $uuid,
|
:uuid => $uuid,
|
||||||
:transport_url => $transport_url,
|
:transport_url => $transport_url,
|
||||||
:database_connection => $database_connection,
|
:database_connection => $database_connection,
|
||||||
:ensure => :present
|
:ensure => :present
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -59,12 +59,12 @@ Puppet::Type.type(:nova_cell_v2).provide(
|
|||||||
database_uri = URI.parse(conf['database']['connection'].strip)
|
database_uri = URI.parse(conf['database']['connection'].strip)
|
||||||
database_uri.path += '_cell0'
|
database_uri.path += '_cell0'
|
||||||
{
|
{
|
||||||
:transport_url => 'none:///',
|
:transport_url => 'none:///',
|
||||||
:database_connection => database_uri.to_s
|
:database_connection => database_uri.to_s
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
:transport_url => conf['DEFAULT']['transport_url'].strip,
|
:transport_url => conf['DEFAULT']['transport_url'].strip,
|
||||||
:database_connection => conf['database']['connection'].strip,
|
:database_connection => conf['database']['connection'].strip,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
@@ -95,9 +95,9 @@ Puppet::Type.type(:nova_cell_v2).provide(
|
|||||||
optional_opts, "--verbose"
|
optional_opts, "--verbose"
|
||||||
)
|
)
|
||||||
@property_hash = {
|
@property_hash = {
|
||||||
:uuid => cell_uuid.strip(),
|
:uuid => cell_uuid.strip(),
|
||||||
:ensure => :present,
|
:ensure => :present,
|
||||||
:transport_url => resource[:transport_url],
|
:transport_url => resource[:transport_url],
|
||||||
:database_connection => resource[:database_connection]
|
:database_connection => resource[:database_connection]
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
@@ -111,7 +111,7 @@ Puppet::Type.type(:nova_cell_v2).provide(
|
|||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
@property_flush[:ensure] = :absent
|
@property_hash.clear
|
||||||
end
|
end
|
||||||
|
|
||||||
def flush
|
def flush
|
||||||
|
@@ -27,12 +27,12 @@ Puppet::Type.type(:nova_flavor).provide(
|
|||||||
(opts << '--swap' << @resource[:swap]) if @resource[:swap]
|
(opts << '--swap' << @resource[:swap]) if @resource[:swap]
|
||||||
(opts << '--rxtx-factor' << @resource[:rxtx_factor]) if @resource[:rxtx_factor]
|
(opts << '--rxtx-factor' << @resource[:rxtx_factor]) if @resource[:rxtx_factor]
|
||||||
@property_hash = self.class.request('flavor', 'create', opts)
|
@property_hash = self.class.request('flavor', 'create', opts)
|
||||||
if @resource[:properties]
|
if @resource[:properties] and !(@resources[:properties].empty?)
|
||||||
prop_opts = [@resource[:name]]
|
prop_opts = [@resource[:name]]
|
||||||
prop_opts << props_to_s(@resource[:properties])
|
prop_opts << props_to_s(@resource[:properties])
|
||||||
self.class.request('flavor', 'set', prop_opts)
|
self.class.request('flavor', 'set', prop_opts)
|
||||||
end
|
end
|
||||||
if @resource[:project]
|
if @resource[:project] and @resource[:project] != ''
|
||||||
proj_opts = [@resource[:name]]
|
proj_opts = [@resource[:name]]
|
||||||
proj_opts << '--project' << @resource[:project]
|
proj_opts << '--project' << @resource[:project]
|
||||||
self.class.request('flavor', 'set', proj_opts)
|
self.class.request('flavor', 'set', proj_opts)
|
||||||
@@ -46,6 +46,7 @@ Puppet::Type.type(:nova_flavor).provide(
|
|||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
self.class.request('flavor', 'delete', @property_hash[:id])
|
self.class.request('flavor', 'delete', @property_hash[:id])
|
||||||
|
@property_hash.clear
|
||||||
end
|
end
|
||||||
|
|
||||||
mk_resource_methods
|
mk_resource_methods
|
||||||
@@ -138,7 +139,7 @@ Puppet::Type.type(:nova_flavor).provide(
|
|||||||
end
|
end
|
||||||
unless @project_flush.empty?
|
unless @project_flush.empty?
|
||||||
opts = [@resource[:name]]
|
opts = [@resource[:name]]
|
||||||
unless @project_flush[:project]
|
unless @project_flush[:project] == ''
|
||||||
opts << '--project' << @project_flush[:project]
|
opts << '--project' << @project_flush[:project]
|
||||||
self.class.request('flavor', 'set', opts)
|
self.class.request('flavor', 'set', opts)
|
||||||
else
|
else
|
||||||
|
@@ -26,9 +26,9 @@ Puppet::Type.type(:nova_service).provide(
|
|||||||
end
|
end
|
||||||
hosts.collect do |hname, host|
|
hosts.collect do |hname, host|
|
||||||
new(
|
new(
|
||||||
:ensure => :present,
|
:ensure => :present,
|
||||||
:name => hname,
|
:name => hname,
|
||||||
:ids => host[:ids],
|
:ids => host[:ids],
|
||||||
:service_name => host[:service_name]
|
:service_name => host[:service_name]
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
@@ -56,7 +56,7 @@ Puppet::Type.type(:nova_service).provide(
|
|||||||
self.class.request('compute service', 'delete', id)
|
self.class.request('compute service', 'delete', id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@property_hash[:ensure] = :absent
|
@property_hash.clear
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
|
@@ -78,9 +78,8 @@ availability_zone="simple"
|
|||||||
properties="{u\'nice\': u\'cookie\'}"
|
properties="{u\'nice\': u\'cookie\'}"
|
||||||
hosts="[u\'example\']"
|
hosts="[u\'example\']"
|
||||||
')
|
')
|
||||||
provider.exists?
|
|
||||||
provider.create
|
provider.create
|
||||||
expect(provider.exists?).to be_falsey
|
expect(provider.exists?).to be_truthy
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@@ -32,7 +32,7 @@ describe provider_class do
|
|||||||
.with('flavor', 'list', ['--long', '--all'])
|
.with('flavor', 'list', ['--long', '--all'])
|
||||||
.returns('"ID", "Name", "RAM", "Disk", "Ephemeral", "VCPUs", "Is Public", "Swap", "RXTX Factor", "Properties"')
|
.returns('"ID", "Name", "RAM", "Disk", "Ephemeral", "VCPUs", "Is Public", "Swap", "RXTX Factor", "Properties"')
|
||||||
provider.class.stubs(:openstack)
|
provider.class.stubs(:openstack)
|
||||||
.with('flavor', 'create', 'shell', ['example', '--public', '--id', '1', '--ram', '512', '--disk', '1', '--vcpus', '1'])
|
.with('flavor', 'create', '--format', 'shell', ['example', '--public', '--id', '1', '--ram', '512', '--disk', '1', '--vcpus', '1'])
|
||||||
.returns('os-flv-disabled:disabled="False"
|
.returns('os-flv-disabled:disabled="False"
|
||||||
os-flv-ext-data:ephemeral="0"
|
os-flv-ext-data:ephemeral="0"
|
||||||
disk="1"
|
disk="1"
|
||||||
@@ -43,6 +43,8 @@ ram="512"
|
|||||||
rxtx_factor="1.0"
|
rxtx_factor="1.0"
|
||||||
swap=""
|
swap=""
|
||||||
vcpus="1"')
|
vcpus="1"')
|
||||||
|
provider.create
|
||||||
|
expect(provider.exists?).to be_truthy
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user