Use common function to parse python dict
Depends-on: https://review.opendev.org/931722 Change-Id: I69dcb3bb3b479248ff5e2e84ec93a4b29b9dba22
This commit is contained in:
parent
576707bee7
commit
579d10a062
@ -70,7 +70,7 @@ Puppet::Type.type(:glance_image).provide(
|
||||
|
||||
begin
|
||||
attrs = self.class.request('image', 'create', opts)
|
||||
properties = self.class.pythondict2hash(attrs[:properties]) rescue nil
|
||||
properties = self.class.parse_python_dict(attrs[:properties])
|
||||
@property_hash = {
|
||||
:ensure => :present,
|
||||
:name => attrs[:name],
|
||||
@ -130,7 +130,7 @@ Puppet::Type.type(:glance_image).provide(
|
||||
list = request('image', 'list', '--long')
|
||||
list.collect do |image|
|
||||
attrs = request('image', 'show', image[:id])
|
||||
properties = pythondict2hash(attrs[:properties]) rescue nil
|
||||
properties = parse_python_dict(attrs[:properties])
|
||||
new(
|
||||
:ensure => :present,
|
||||
:name => attrs[:name],
|
||||
@ -183,9 +183,6 @@ Puppet::Type.type(:glance_image).provide(
|
||||
private
|
||||
|
||||
def self.exclude_readonly_props(props)
|
||||
if props == nil
|
||||
return nil
|
||||
end
|
||||
hidden = [
|
||||
'os_hash_algo',
|
||||
'os_hash_value',
|
||||
@ -199,9 +196,6 @@ Puppet::Type.type(:glance_image).provide(
|
||||
end
|
||||
|
||||
def self.exclude_owner_specified_props(props)
|
||||
if props == nil
|
||||
return nil
|
||||
end
|
||||
rv = props.select { |k, v| not k.start_with?('owner_specified.') }
|
||||
return rv
|
||||
end
|
||||
@ -213,10 +207,6 @@ Puppet::Type.type(:glance_image).provide(
|
||||
}.compact
|
||||
end
|
||||
|
||||
def self.pythondict2hash(input)
|
||||
return JSON.parse(input.gsub(/'/, '"').gsub(/False/,'false').gsub(/True/,'true'))
|
||||
end
|
||||
|
||||
def fetch(uri_str, proxy_host = nil, proxy_port = nil, limit = 10)
|
||||
raise RuntimeError, 'Too many HTTP redirections' if limit == 0
|
||||
|
||||
|
@ -54,6 +54,7 @@ min_disk="1024"
|
||||
min_ram="1024"
|
||||
name="image1"
|
||||
owner="5a9e521e17014804ab8b4e8b3de488a4"
|
||||
properties="{}"
|
||||
protected="False"
|
||||
schema="/v2/schemas/image"
|
||||
size="13287936"
|
||||
@ -79,18 +80,6 @@ visibility="public"
|
||||
|
||||
end
|
||||
|
||||
describe '#pythondict2hash' do
|
||||
it 'should return a hash with key-value when provided with a python dict' do
|
||||
s = "{'key': 'value', 'key2': 'value2'}"
|
||||
expect(provider_class.pythondict2hash(s)).to eq({"key"=>"value", "key2"=>"value2"})
|
||||
end
|
||||
|
||||
it 'should convert boolean to json compatible hash when provided with a python dict' do
|
||||
s = "{'key': 'value', 'key2': False}"
|
||||
expect(provider_class.pythondict2hash(s)).to eq({"key"=>"value", "key2"=>false})
|
||||
end
|
||||
end
|
||||
|
||||
describe '.instances' do
|
||||
it 'finds every image' do
|
||||
allow(provider.class).to receive(:openstack)
|
||||
@ -415,6 +404,7 @@ file="/v2/images/8801c5b0-c505-4a15-8ca3-1d2383f8c015/file"
|
||||
id="8801c5b0-c505-4a15-8ca3-1d2383f8c015"
|
||||
name="image1"
|
||||
owner="5a9e521e17014804ab8b4e8b3de488a4"
|
||||
properties="{}"
|
||||
protected="False"
|
||||
schema="/v2/schemas/image"
|
||||
size="13287936"
|
||||
@ -451,6 +441,7 @@ visibility="public"
|
||||
name="image1"
|
||||
owner="None"
|
||||
tags="testtag"
|
||||
properties="{}"
|
||||
protected="False"
|
||||
size="1270"
|
||||
status="active"
|
Loading…
Reference in New Issue
Block a user