Remove parse logic for openstacclient < 1.9.0
... because that version is quite old and we don't expect it is still used. This also updates the output string used in unit tests according to the one in newer versions. Change-Id: I18a8ced73197efe96964d760c3a97703f8d8b6b9
This commit is contained in:
parent
f1d7e27866
commit
b8dfd90084
@ -119,38 +119,10 @@ Puppet::Type.type(:keystone_identity_provider).provide(
|
||||
remote_ids
|
||||
end
|
||||
|
||||
# bug/python-openstackclient/1478995: when fixed, parsing will be done by OSC.
|
||||
def self.clean_remote_ids(remote_ids)
|
||||
version = system_request('--version', '').sub(/openstack\s+/i, '').strip
|
||||
if Gem::Version.new(version) < Gem::Version.new('1.9.0')
|
||||
clean_remote_ids_old(remote_ids)
|
||||
else
|
||||
remote_ids.split(',').map(&:strip)
|
||||
end
|
||||
remote_ids.split(',').map(&:strip)
|
||||
end
|
||||
|
||||
def self.clean_remote_ids_old(remote_ids)
|
||||
remote_ids_clean = []
|
||||
if remote_ids != '[]'
|
||||
python_array_of_unicode_string = %r/
|
||||
u # the u character
|
||||
(?<delimiter>["']) # followed by a delimiter
|
||||
(?<value> # which holds the value
|
||||
.+? # composed of non-delimiter
|
||||
)
|
||||
(\k<delimiter>) # ended by the delimiter
|
||||
/x
|
||||
remote_ids_clean = JSON.parse(remote_ids.gsub(
|
||||
python_array_of_unicode_string,
|
||||
'"\k<value>"'))
|
||||
end
|
||||
rescue JSON::ParserError
|
||||
raise(Puppet::Error,
|
||||
"Could not parse #{remote_ids} into a valid structure. " \
|
||||
'Please submit a bug report.')
|
||||
else
|
||||
remote_ids_clean
|
||||
end
|
||||
def self.remote_ids_cli(remote_ids)
|
||||
remote_ids.map { |e| ['--remote-id', e.to_s] }.flatten
|
||||
end
|
||||
|
@ -47,7 +47,7 @@ describe Puppet::Type.type(:keystone_identity_provider).provider(:openstack) do
|
||||
description="Nice id provider"
|
||||
enabled="True"
|
||||
id="idp_one"
|
||||
remote_ids="[u'entityid_idp1', u'http://entityid_idp2/saml/meta', u'3']"
|
||||
remote_ids="entityid_idp1, http://entityid_idp2/saml/meta, 3"
|
||||
EOR
|
||||
)
|
||||
provider.create
|
||||
@ -104,7 +104,7 @@ EOR
|
||||
description="Nice id provider"
|
||||
enabled="True"
|
||||
id="idp_one"
|
||||
remote_ids="[u'entityid_idp1', u'http://entityid_idp2/saml/meta', u'3']"
|
||||
remote_ids="entityid_idp1, http://entityid_idp2/saml/meta, 3"
|
||||
EOR
|
||||
)
|
||||
provider.create
|
||||
@ -151,7 +151,7 @@ EOR
|
||||
description="None"
|
||||
enabled="True"
|
||||
id="idp_one"
|
||||
remote_ids="[u'entityid_idp1', u'http://entityid_idp2/saml/meta', u'3']"
|
||||
remote_ids="entityid_idp1, http://entityid_idp2/saml/meta, 3"
|
||||
EOR
|
||||
)
|
||||
described_class.expects(:openstack)
|
||||
@ -165,13 +165,9 @@ EOR
|
||||
description="Idp two description"
|
||||
enabled="False"
|
||||
id="idp_two"
|
||||
remote_ids="[]"
|
||||
remote_ids=""
|
||||
EOR
|
||||
)
|
||||
described_class.expects(:openstack)
|
||||
.with('--version', '', [])
|
||||
.twice
|
||||
.returns("openstack 1.7.0\n")
|
||||
instances =
|
||||
Puppet::Type::Keystone_identity_provider::ProviderOpenstack.instances
|
||||
expect(instances.count).to eq(2)
|
||||
@ -261,38 +257,14 @@ EOR
|
||||
end
|
||||
|
||||
describe '#clean_remote_ids' do
|
||||
context 'before python-openstackclient/+bug/1478995' do
|
||||
let(:edge_cases_remote_ids) do
|
||||
{
|
||||
%q|[u'http://remoteid?id=idp_one&name=ldap', u"http://remoteid_2?id='idp'"]| =>
|
||||
['http://remoteid?id=idp_one&name=ldap', "http://remoteid_2?id='idp'"],
|
||||
%q|[u'http://remoteid?id=idp_one&name=ldap']| => ['http://remoteid?id=idp_one&name=ldap']
|
||||
}
|
||||
end
|
||||
it 'should handle tricky cases' do
|
||||
described_class.expects(:openstack)
|
||||
.with('--version', '', [])
|
||||
.twice
|
||||
.returns("openstack 1.7.0\n")
|
||||
edge_cases_remote_ids.each do |edge_case, solution|
|
||||
expect(described_class.clean_remote_ids(edge_case)).to eq(solution)
|
||||
end
|
||||
end
|
||||
let(:remote_ids) do
|
||||
[
|
||||
"http://remoteid?id=idp_one&name=ldap, http://remoteid_2?id='idp'",
|
||||
['http://remoteid?id=idp_one&name=ldap', "http://remoteid_2?id='idp'"]
|
||||
]
|
||||
end
|
||||
context 'after python-openstackclient/+bug/1478995' do
|
||||
let(:remote_ids) do
|
||||
[
|
||||
"http://remoteid?id=idp_one&name=ldap, http://remoteid_2?id='idp'",
|
||||
['http://remoteid?id=idp_one&name=ldap', "http://remoteid_2?id='idp'"]
|
||||
]
|
||||
end
|
||||
it 'should handle the new output' do
|
||||
described_class.expects(:openstack)
|
||||
.with('--version', '', [])
|
||||
.once
|
||||
.returns("openstack 1.9.0\n")
|
||||
expect(described_class.clean_remote_ids(remote_ids[0])).to eq(remote_ids[1])
|
||||
end
|
||||
it 'should handle the new output' do
|
||||
expect(described_class.clean_remote_ids(remote_ids[0])).to eq(remote_ids[1])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user