Use common function to parse python dict

Depends-on: https://review.opendev.org/931722
Change-Id: I11afea8ef57ec3d003c283cdc2c8ba57476db82f
This commit is contained in:
Takashi Kajinami
2024-10-10 10:26:14 +09:00
parent 8e97291497
commit da7785c6fa
3 changed files with 3 additions and 20 deletions

View File

@@ -15,7 +15,7 @@ Puppet::Type.type(:nova_aggregate).provide(
def self.instances
request('aggregate', 'list').collect do |el|
attrs = request('aggregate', 'show', el[:name])
properties = pythondict2hash(attrs[:properties])
properties = parse_python_dict(attrs[:properties])
new(
:ensure => :present,
:name => attrs[:name],
@@ -66,7 +66,7 @@ Puppet::Type.type(:nova_aggregate).provide(
end
attrs = self.class.request('aggregate', 'create', properties)
properties = self.class.pythondict2hash(attrs[:properties])
properties = self.class.parse_python_dict(attrs[:properties])
@property_hash = {
:ensure => :present,
:name => attrs[:name],
@@ -130,9 +130,4 @@ Puppet::Type.type(:nova_aggregate).provide(
def self.string2list(input)
return input[1..-2].split(",").map { |x| x.match(/'(.*?)'/)[1] }
end
def self.pythondict2hash(input)
return JSON.parse(input.gsub(/'/, '"'))
end
end

View File

@@ -118,7 +118,7 @@ Puppet::Type.type(:nova_flavor).provide(
project_name = ''
end
properties = JSON.parse(attrs[:properties].gsub(/'/, '"'))
properties = parse_python_dict(attrs[:properties])
new(
:ensure => :present,
:name => attrs[:name],

View File

@@ -93,18 +93,6 @@ hosts="[\'example\']"
expect(provider.exists?).to be_falsey
end
end
describe '#pythondict2hash' do
it 'should return a hash with key-value when provided with a unicode python dict' do
s = "{'key': 'value', 'key2': 'value2'}"
expect(described_class.pythondict2hash(s)).to eq({"key"=>"value", "key2"=>"value2"})
end
it 'should return a hash with key-value when provided with a python dict' do
s = "{'key': 'value', 'key2': 'value2'}"
expect(described_class.pythondict2hash(s)).to eq({"key"=>"value", "key2"=>"value2"})
end
end
end