Replace usage of uriescape
The uriescape function from puppetlabs-stdlib is no longer functional in Puppet 8, because the URI.escape, which is internally used by that function, is no longer available in Ruby 3+. This replaces the function by own function to avoid the failure in Puppet 8. Closes-Bug: #2057860 Change-Id: I7b4db4c1e64416e20d8470cbff0b8497c6a0cfc9
This commit is contained in:
parent
5eacb81147
commit
2dcad6d8dc
19
lib/puppet/functions/encode_url_queries_for_python.rb
Normal file
19
lib/puppet/functions/encode_url_queries_for_python.rb
Normal file
@ -0,0 +1,19 @@
|
||||
Puppet::Functions.create_function(:encode_url_queries_for_python) do
|
||||
|
||||
def encode_url_queries_for_python(*args)
|
||||
require 'uri'
|
||||
|
||||
if (args.size != 1) then
|
||||
raise Puppet::ParseError, 'encode_url_queries_for_python(): Wrong number of arguments'
|
||||
end
|
||||
queries = args[0]
|
||||
if queries.class != Hash
|
||||
raise Puppet::ParseError, "encode_url_queries_for_python(): Requires a Hash, got #{queries.class}"
|
||||
end
|
||||
|
||||
if queries.empty?
|
||||
return ''
|
||||
end
|
||||
return '?' + URI.encode_www_form(queries).gsub(/%/, '%%')
|
||||
end
|
||||
end
|
@ -233,13 +233,7 @@ class nova::migration::libvirt(
|
||||
$postfix = ''
|
||||
}
|
||||
|
||||
if empty($client_extraparams) {
|
||||
$extra_params =''
|
||||
} else {
|
||||
$extra_params_before_python_escape = join(uriescape(join_keys_to_values($client_extraparams, '=')), '&')
|
||||
# Must escape % as nova interprets it incorrectly.
|
||||
$extra_params = sprintf('?%s', regsubst($extra_params_before_python_escape, '%', '%%', 'G'))
|
||||
}
|
||||
$extra_params = encode_url_queries_for_python($client_extraparams)
|
||||
|
||||
$live_migration_uri = "qemu+${transport}://${prefix}%s${postfix}/system${extra_params}"
|
||||
|
||||
|
@ -0,0 +1,9 @@
|
||||
require 'spec_helper'
|
||||
require 'puppet'
|
||||
|
||||
describe 'encode_url_queries_for_python', :type => :puppet_function do
|
||||
|
||||
it { is_expected.to run.with_params({}).and_return('') }
|
||||
it { is_expected.to run.with_params({'a' => 1, 'b' => 2}).and_return('?a=1&b=2') }
|
||||
it { is_expected.to run.with_params({'a' => 'b%c'}).and_return('?a=b%%25c') }
|
||||
end
|
Loading…
Reference in New Issue
Block a user