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)
|
||||
end
|
||||
self.class.request('aggregate', 'delete', @property_hash[:name])
|
||||
@property_hash.clear
|
||||
end
|
||||
|
||||
def create
|
||||
@@ -79,6 +80,7 @@ Puppet::Type.type(:nova_aggregate).provide(
|
||||
self.class.request('aggregate', 'add host', properties)
|
||||
end
|
||||
end
|
||||
@property_hash[:ensure] = :present
|
||||
end
|
||||
|
||||
def availability_zone=(value)
|
||||
|
@@ -30,11 +30,11 @@ Puppet::Type.type(:nova_cell_v2).provide(
|
||||
$database_connection = 'default'
|
||||
end
|
||||
new(
|
||||
:name => $name,
|
||||
:uuid => $uuid,
|
||||
:transport_url => $transport_url,
|
||||
:name => $name,
|
||||
:uuid => $uuid,
|
||||
:transport_url => $transport_url,
|
||||
:database_connection => $database_connection,
|
||||
:ensure => :present
|
||||
:ensure => :present
|
||||
)
|
||||
end
|
||||
end
|
||||
@@ -59,12 +59,12 @@ Puppet::Type.type(:nova_cell_v2).provide(
|
||||
database_uri = URI.parse(conf['database']['connection'].strip)
|
||||
database_uri.path += '_cell0'
|
||||
{
|
||||
:transport_url => 'none:///',
|
||||
:transport_url => 'none:///',
|
||||
:database_connection => database_uri.to_s
|
||||
}
|
||||
else
|
||||
{
|
||||
:transport_url => conf['DEFAULT']['transport_url'].strip,
|
||||
:transport_url => conf['DEFAULT']['transport_url'].strip,
|
||||
:database_connection => conf['database']['connection'].strip,
|
||||
}
|
||||
end
|
||||
@@ -95,9 +95,9 @@ Puppet::Type.type(:nova_cell_v2).provide(
|
||||
optional_opts, "--verbose"
|
||||
)
|
||||
@property_hash = {
|
||||
:uuid => cell_uuid.strip(),
|
||||
:ensure => :present,
|
||||
:transport_url => resource[:transport_url],
|
||||
:uuid => cell_uuid.strip(),
|
||||
:ensure => :present,
|
||||
:transport_url => resource[:transport_url],
|
||||
:database_connection => resource[:database_connection]
|
||||
}
|
||||
end
|
||||
@@ -111,7 +111,7 @@ Puppet::Type.type(:nova_cell_v2).provide(
|
||||
end
|
||||
|
||||
def destroy
|
||||
@property_flush[:ensure] = :absent
|
||||
@property_hash.clear
|
||||
end
|
||||
|
||||
def flush
|
||||
|
@@ -27,12 +27,12 @@ Puppet::Type.type(:nova_flavor).provide(
|
||||
(opts << '--swap' << @resource[:swap]) if @resource[:swap]
|
||||
(opts << '--rxtx-factor' << @resource[:rxtx_factor]) if @resource[:rxtx_factor]
|
||||
@property_hash = self.class.request('flavor', 'create', opts)
|
||||
if @resource[:properties]
|
||||
if @resource[:properties] and !(@resources[:properties].empty?)
|
||||
prop_opts = [@resource[:name]]
|
||||
prop_opts << props_to_s(@resource[:properties])
|
||||
self.class.request('flavor', 'set', prop_opts)
|
||||
end
|
||||
if @resource[:project]
|
||||
if @resource[:project] and @resource[:project] != ''
|
||||
proj_opts = [@resource[:name]]
|
||||
proj_opts << '--project' << @resource[:project]
|
||||
self.class.request('flavor', 'set', proj_opts)
|
||||
@@ -46,6 +46,7 @@ Puppet::Type.type(:nova_flavor).provide(
|
||||
|
||||
def destroy
|
||||
self.class.request('flavor', 'delete', @property_hash[:id])
|
||||
@property_hash.clear
|
||||
end
|
||||
|
||||
mk_resource_methods
|
||||
@@ -138,7 +139,7 @@ Puppet::Type.type(:nova_flavor).provide(
|
||||
end
|
||||
unless @project_flush.empty?
|
||||
opts = [@resource[:name]]
|
||||
unless @project_flush[:project]
|
||||
unless @project_flush[:project] == ''
|
||||
opts << '--project' << @project_flush[:project]
|
||||
self.class.request('flavor', 'set', opts)
|
||||
else
|
||||
|
@@ -26,9 +26,9 @@ Puppet::Type.type(:nova_service).provide(
|
||||
end
|
||||
hosts.collect do |hname, host|
|
||||
new(
|
||||
:ensure => :present,
|
||||
:name => hname,
|
||||
:ids => host[:ids],
|
||||
:ensure => :present,
|
||||
:name => hname,
|
||||
:ids => host[:ids],
|
||||
:service_name => host[:service_name]
|
||||
)
|
||||
end
|
||||
@@ -56,7 +56,7 @@ Puppet::Type.type(:nova_service).provide(
|
||||
self.class.request('compute service', 'delete', id)
|
||||
end
|
||||
end
|
||||
@property_hash[:ensure] = :absent
|
||||
@property_hash.clear
|
||||
end
|
||||
|
||||
def create
|
||||
|
@@ -78,9 +78,8 @@ availability_zone="simple"
|
||||
properties="{u\'nice\': u\'cookie\'}"
|
||||
hosts="[u\'example\']"
|
||||
')
|
||||
provider.exists?
|
||||
provider.create
|
||||
expect(provider.exists?).to be_falsey
|
||||
expect(provider.exists?).to be_truthy
|
||||
end
|
||||
end
|
||||
|
||||
|
@@ -32,7 +32,7 @@ describe provider_class do
|
||||
.with('flavor', 'list', ['--long', '--all'])
|
||||
.returns('"ID", "Name", "RAM", "Disk", "Ephemeral", "VCPUs", "Is Public", "Swap", "RXTX Factor", "Properties"')
|
||||
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"
|
||||
os-flv-ext-data:ephemeral="0"
|
||||
disk="1"
|
||||
@@ -43,6 +43,8 @@ ram="512"
|
||||
rxtx_factor="1.0"
|
||||
swap=""
|
||||
vcpus="1"')
|
||||
provider.create
|
||||
expect(provider.exists?).to be_truthy
|
||||
end
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user