nova_flavor: Fix broken idempotency with properties
Make sure that nova_flavor resource is idempotent when the "properties" property is set. Also fix the typo causing undefined method error. Closes-Bug: #2059949 Change-Id: I17a9d92c44b8dfe329b22b309d7a0408df707d1a
This commit is contained in:
parent
5eacb81147
commit
820695b463
@ -27,7 +27,7 @@ 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] and !(@resources[:properties].empty?)
|
||||
if @resource[:properties] and !(@resource[:properties].empty?)
|
||||
prop_opts = [@resource[:name]]
|
||||
prop_opts << props_to_s(@resource[:properties])
|
||||
self.class.request('flavor', 'set', prop_opts)
|
||||
@ -118,7 +118,7 @@ Puppet::Type.type(:nova_flavor).provide(
|
||||
project_name = ''
|
||||
end
|
||||
|
||||
properties = Hash[attrs[:properties].scan(/(\S+)='([^']*)'/)] rescue nil
|
||||
properties = JSON.parse(attrs[:properties].gsub(/'/, '"'))
|
||||
new(
|
||||
:ensure => :present,
|
||||
:name => attrs[:name],
|
||||
|
@ -40,7 +40,8 @@ describe 'basic nova' do
|
||||
disk => '1',
|
||||
vcpus => '1',
|
||||
is_public => 'False',
|
||||
project_name => 'services'
|
||||
project_name => 'services',
|
||||
properties => {'foo' => 'bar'}
|
||||
}
|
||||
EOS
|
||||
|
||||
|
@ -138,6 +138,53 @@ domain_id="domain_one_id"
|
||||
end
|
||||
end
|
||||
|
||||
describe '#instances' do
|
||||
it 'finds existing services' do
|
||||
expect(described_class).to receive(:openstack)
|
||||
.with('flavor', 'list', '--quiet', '--format', 'csv', ['--long', '--all'])
|
||||
.and_return('"ID","Name","RAM","Disk","Ephemeral","VCPUs","Is Public","Swap","RXTX Factor","Properties"
|
||||
"1","m1.tiny",128,2,0,1,True,0,1.0,"{}"
|
||||
"42","m1.nano",256,2,0,1,False,0,1.0,"{\'key1\': \'val1\', \'key2\': \'val2\'}"
|
||||
')
|
||||
|
||||
expect(described_class).to receive(:openstack)
|
||||
.with('flavor', 'show', '--format', 'shell', ['1', '-c', 'access_project_ids'])
|
||||
.and_return('access_project_ids="None"
|
||||
')
|
||||
expect(described_class).to receive(:openstack)
|
||||
.with('flavor', 'show', '--format', 'shell', ['42', '-c', 'access_project_ids'])
|
||||
.and_return('access_project_ids="None"
|
||||
')
|
||||
|
||||
instances = described_class.instances
|
||||
expect(instances.count).to eq(2)
|
||||
expect(instances[0].name).to eq('m1.tiny')
|
||||
expect(instances[0].id).to eq('1')
|
||||
expect(instances[0].ram).to eq('128')
|
||||
expect(instances[0].disk).to eq('2')
|
||||
expect(instances[0].ephemeral).to eq('0')
|
||||
expect(instances[0].vcpus).to eq('1')
|
||||
expect(instances[0].is_public).to eq(true)
|
||||
expect(instances[0].swap).to eq('0')
|
||||
expect(instances[0].rxtx_factor).to eq('1.0')
|
||||
expect(instances[0].properties).to eq({})
|
||||
expect(instances[0].project).to eq('')
|
||||
expect(instances[0].project_name).to eq('')
|
||||
expect(instances[1].name).to eq('m1.nano')
|
||||
expect(instances[1].id).to eq('42')
|
||||
expect(instances[1].ram).to eq('256')
|
||||
expect(instances[1].disk).to eq('2')
|
||||
expect(instances[1].ephemeral).to eq('0')
|
||||
expect(instances[1].vcpus).to eq('1')
|
||||
expect(instances[1].is_public).to eq(false)
|
||||
expect(instances[1].swap).to eq('0')
|
||||
expect(instances[1].rxtx_factor).to eq('1.0')
|
||||
expect(instances[1].properties).to eq({'key1' => 'val1', 'key2' => 'val2'})
|
||||
expect(instances[1].project).to eq('')
|
||||
expect(instances[1].project_name).to eq('')
|
||||
end
|
||||
end
|
||||
|
||||
describe '#flush' do
|
||||
context '.project' do
|
||||
it 'updates flavor' do
|
||||
|
Loading…
Reference in New Issue
Block a user