Add common function to parse python list
Add the common function to parse python list representation to a puppet array value, to replace the same implementation maintained in a few modules. Change-Id: I4ec8a47fe865796e7c6cdebe8faafb0b8504e074
This commit is contained in:
parent
93d082e579
commit
762978b0df
@ -163,4 +163,8 @@ class Puppet::Provider::Openstack < Puppet::Provider
|
|||||||
def self.parse_python_dict(text)
|
def self.parse_python_dict(text)
|
||||||
return JSON.parse(text.gsub(/'/, '"').gsub(/: False([,}])/,': false\1').gsub(/: True([,}])/,': true\1'))
|
return JSON.parse(text.gsub(/'/, '"').gsub(/: False([,}])/,': false\1').gsub(/: True([,}])/,': true\1'))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.parse_python_list(text)
|
||||||
|
return JSON.parse(text.gsub(/'/, '"'))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -229,4 +229,17 @@ name="test"
|
|||||||
expect(Puppet::Provider::Openstack.parse_python_dict(s)).to eq({'key'=>'value', 'key2'=>false})
|
expect(Puppet::Provider::Openstack.parse_python_dict(s)).to eq({'key'=>'value', 'key2'=>false})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#parse_python_list' do
|
||||||
|
it 'should return an array when provided with a python list' do
|
||||||
|
s = "['foo', 'bar', 'baz']"
|
||||||
|
expect(Puppet::Provider::Openstack.parse_python_list(s)).to eq(['foo', 'bar', 'baz'])
|
||||||
|
|
||||||
|
s = '[]'
|
||||||
|
expect(Puppet::Provider::Openstack.parse_python_list(s)).to eq([])
|
||||||
|
|
||||||
|
s = '[1, 2, 3]'
|
||||||
|
expect(Puppet::Provider::Openstack.parse_python_list(s)).to eq([1, 2, 3])
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user