From 14fa1e46674aca66277e15aea10606c244ca29f5 Mon Sep 17 00:00:00 2001 From: Dan Voiculeasa Date: Tue, 29 Jun 2021 13:04:38 +0300 Subject: [PATCH] py3: nfv update urllib compatibility There is incompatible urllib usage. Use six library instead of urllib.quote to fix incompatibility. The Request object add_data method doesn't exist anymore. Use direct access to data field instead. This commit extracted urllib.parse.quote usage from Charles Short's work Iecfe9b83245847b07aaaa0ec1aadad4734a9d118. Added changes for Request.add_data usage on top of it. Story: 2008454 Task: 42727 Co-authored-by: Charles Short Signed-off-by: Dan Voiculeasa Change-Id: Ifd82ea8d4134a2a6301e5b10d4b0546833ed6193 (cherry picked from commit 522a3b3660e280d58352d1efe33bfdb8ab2e0461) --- nfv/nfv-client/nfv_client/openstack/openstack.py | 2 +- nfv/nfv-client/nfv_client/openstack/rest_api.py | 2 +- .../nfv_plugins/nfvi_plugins/openstack/openstack.py | 2 +- .../nfv_plugins/nfvi_plugins/openstack/rest_api.py | 2 +- nfv/nfv-vim/nfv_vim/api/openstack/_openstack.py | 4 ++-- nfv/nfv-vim/nfv_vim/api/openstack/_rest_api.py | 2 +- nova-api-proxy/nova-api-proxy/nova_api_proxy/apps/proxy.py | 4 ++-- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/nfv/nfv-client/nfv_client/openstack/openstack.py b/nfv/nfv-client/nfv_client/openstack/openstack.py index 0ced91ea..12949bcf 100755 --- a/nfv/nfv-client/nfv_client/openstack/openstack.py +++ b/nfv/nfv-client/nfv_client/openstack/openstack.py @@ -59,7 +59,7 @@ def get_token(auth_uri, project_name, project_domain_name, username, password, "domain": {"name": project_domain_name} }}}}) - request_info.add_data(payload) + request_info.data = payload request = urllib.request.urlopen(request_info, timeout=30) # Identity API v3 returns token id in X-Subject-Token diff --git a/nfv/nfv-client/nfv_client/openstack/rest_api.py b/nfv/nfv-client/nfv_client/openstack/rest_api.py index ac689057..0a0a5cc5 100755 --- a/nfv/nfv-client/nfv_client/openstack/rest_api.py +++ b/nfv/nfv-client/nfv_client/openstack/rest_api.py @@ -32,7 +32,7 @@ def request(token_id, method, api_cmd, api_cmd_headers=None, request_info.add_header(header_type, header_value) if api_cmd_payload is not None: - request_info.add_data(api_cmd_payload) + request_info.data = api_cmd_payload url_request = urllib.request.urlopen(request_info, timeout=timeout_in_secs) diff --git a/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/openstack/openstack.py b/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/openstack/openstack.py index f3d6eefe..ef4c1275 100755 --- a/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/openstack/openstack.py +++ b/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/openstack/openstack.py @@ -58,7 +58,7 @@ def get_token(directory): "name": directory.auth_project, "domain": {"name": directory.auth_project_domain_name} }}}}) - request_info.add_data(payload) + request_info.data = payload # WARNING: Any change to the timeout must be reflected in the config.ini # file for the nfvi plugins. diff --git a/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/openstack/rest_api.py b/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/openstack/rest_api.py index 09fba977..018169f8 100755 --- a/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/openstack/rest_api.py +++ b/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/openstack/rest_api.py @@ -309,7 +309,7 @@ def _rest_api_request(token_id, method, api_cmd, api_cmd_headers, request_info.add_header(header_type, header_value) if api_cmd_payload is not None: - request_info.add_data(api_cmd_payload) + request_info.data = api_cmd_payload DLOG.verbose("Rest-API method=%s, api_cmd=%s, api_cmd_headers=%s, " "api_cmd_payload=%s" % (method, api_cmd, api_cmd_headers, diff --git a/nfv/nfv-vim/nfv_vim/api/openstack/_openstack.py b/nfv/nfv-vim/nfv_vim/api/openstack/_openstack.py index a0b879f3..57a3eb28 100755 --- a/nfv/nfv-vim/nfv_vim/api/openstack/_openstack.py +++ b/nfv/nfv-vim/nfv_vim/api/openstack/_openstack.py @@ -53,7 +53,7 @@ def validate_token(directory, admin_token, token_id): } }}) - request_info.add_data(payload) + request_info.data = payload request = urllib.request.urlopen(request_info) # Identity API v3 returns token id in X-Subject-Token @@ -114,7 +114,7 @@ def get_token(directory): "name": directory.auth_project, "domain": {"name": directory.auth_project_domain_name} }}}}) - request_info.add_data(payload) + request_info.data = payload request = urllib.request.urlopen(request_info) # Identity API v3 returns token id in X-Subject-Token diff --git a/nfv/nfv-vim/nfv_vim/api/openstack/_rest_api.py b/nfv/nfv-vim/nfv_vim/api/openstack/_rest_api.py index d4f09e2d..c77f29d7 100755 --- a/nfv/nfv-vim/nfv_vim/api/openstack/_rest_api.py +++ b/nfv/nfv-vim/nfv_vim/api/openstack/_rest_api.py @@ -35,7 +35,7 @@ def rest_api_request(token, method, url, headers=None, body=None): request_info.add_header("X-Auth-Token", token.get_id()) if body is not None and '' != body: - request_info.add_data(body) + request_info.data = body # Enable Debug # handler = urllib.request.HTTPHandler(debuglevel=1) diff --git a/nova-api-proxy/nova-api-proxy/nova_api_proxy/apps/proxy.py b/nova-api-proxy/nova-api-proxy/nova_api_proxy/apps/proxy.py index c11bf7ab..ef11964e 100644 --- a/nova-api-proxy/nova-api-proxy/nova_api_proxy/apps/proxy.py +++ b/nova-api-proxy/nova-api-proxy/nova_api_proxy/apps/proxy.py @@ -15,7 +15,7 @@ from paste.proxy import parse_headers from paste.proxy import TransparentProxy from six.moves import http_client as httplib -import urllib +from six.moves import urllib from oslo_log import log as logging @@ -90,7 +90,7 @@ class DebugProxy(Application): body = '' path = (environ.get('SCRIPT_NAME', '') + environ.get('PATH_INFO', '')) - path = urllib.quote(path) + path = urllib.parse.quote(path) if 'QUERY_STRING' in environ: path += '?' + environ['QUERY_STRING'] LOG.debug("REQ header: (%s)" % headers)