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