Merge "Python 2 to Python 3 compatibility" into f/centos8
This commit is contained in:
commit
0199e093e1
|
@ -16,12 +16,13 @@ BuildRequires: python3-wheel
|
||||||
Requires: python3-httplib2
|
Requires: python3-httplib2
|
||||||
Requires: python3-prettytable
|
Requires: python3-prettytable
|
||||||
Requires: bash-completion
|
Requires: bash-completion
|
||||||
Requires: python3-neutronclient
|
Requires: python3-dateutil
|
||||||
Requires: python3-keystoneclient
|
Requires: python3-keystoneclient
|
||||||
Requires: python3-oslo-i18n
|
Requires: python3-oslo-i18n
|
||||||
Requires: python3-oslo-serialization
|
Requires: python3-oslo-serialization
|
||||||
Requires: python3-oslo-utils
|
Requires: python3-oslo-utils
|
||||||
Requires: python3-requests-toolbelt
|
Requires: python3-requests-toolbelt
|
||||||
|
|
||||||
# Needed for python2 and python3 compatible
|
# Needed for python2 and python3 compatible
|
||||||
Requires: python3-six
|
Requires: python3-six
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# Copyright 2013, 2017 Wind River, Inc.
|
# Copyright 2013-2021 Wind River, Inc.
|
||||||
# Copyright 2012 Openstack Foundation
|
# Copyright 2012 Openstack Foundation
|
||||||
# All Rights Reserved.
|
# All Rights Reserved.
|
||||||
#
|
#
|
||||||
|
@ -15,9 +15,11 @@
|
||||||
# under the License.
|
# under the License.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
import hashlib
|
||||||
import httplib2
|
import httplib2
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
from oslo_utils import encodeutils
|
||||||
import requests
|
import requests
|
||||||
from requests_toolbelt import MultipartEncoder
|
from requests_toolbelt import MultipartEncoder
|
||||||
import socket
|
import socket
|
||||||
|
@ -37,11 +39,11 @@ except ImportError:
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
|
|
||||||
from cgtsclient import exc as exceptions
|
from cgtsclient import exc as exceptions
|
||||||
from neutronclient.common import utils
|
|
||||||
|
|
||||||
_logger = logging.getLogger(__name__)
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
CHUNKSIZE = 1024 * 64 # 64kB
|
CHUNKSIZE = 1024 * 64 # 64kB
|
||||||
|
SENSITIVE_HEADERS = ('X-Auth-Token',)
|
||||||
|
|
||||||
# httplib2 retries requests on socket.timeout which
|
# httplib2 retries requests on socket.timeout which
|
||||||
# is not idempotent and can lead to orhan objects.
|
# is not idempotent and can lead to orhan objects.
|
||||||
|
@ -156,6 +158,32 @@ class HTTPClient(httplib2.Http):
|
||||||
'headers': resp_headers,
|
'headers': resp_headers,
|
||||||
'body': body})
|
'body': body})
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def http_log_req(_logger, args, kwargs):
|
||||||
|
if not _logger.isEnabledFor(logging.DEBUG):
|
||||||
|
return
|
||||||
|
|
||||||
|
string_parts = ['curl -i']
|
||||||
|
for element in args:
|
||||||
|
if element in ('GET', 'POST', 'DELETE', 'PUT'):
|
||||||
|
string_parts.append(' -X %s' % element)
|
||||||
|
else:
|
||||||
|
string_parts.append(' %s' % element)
|
||||||
|
|
||||||
|
for (key, value) in kwargs['headers'].items():
|
||||||
|
if key in SENSITIVE_HEADERS:
|
||||||
|
v = value.encode('utf-8')
|
||||||
|
h = hashlib.sha256(v)
|
||||||
|
d = h.hexdigest()
|
||||||
|
value = "{SHA256}%s" % d
|
||||||
|
header = ' -H "%s: %s"' % (key, value)
|
||||||
|
string_parts.append(header)
|
||||||
|
|
||||||
|
if 'body' in kwargs and kwargs['body']:
|
||||||
|
string_parts.append(" -d '%s'" % (kwargs['body']))
|
||||||
|
req = encodeutils.safe_encode("".join(string_parts))
|
||||||
|
_logger.debug("REQ: %s", req)
|
||||||
|
|
||||||
def _cs_request(self, *args, **kwargs):
|
def _cs_request(self, *args, **kwargs):
|
||||||
kargs = {}
|
kargs = {}
|
||||||
kargs.setdefault('headers', kwargs.get('headers', {}))
|
kargs.setdefault('headers', kwargs.get('headers', {}))
|
||||||
|
@ -172,24 +200,22 @@ class HTTPClient(httplib2.Http):
|
||||||
|
|
||||||
if 'body' in kwargs:
|
if 'body' in kwargs:
|
||||||
kargs['body'] = kwargs['body']
|
kargs['body'] = kwargs['body']
|
||||||
args = utils.safe_encode_list(args)
|
|
||||||
kargs = utils.safe_encode_dict(kargs)
|
|
||||||
if self.log_credentials:
|
if self.log_credentials:
|
||||||
log_kargs = kargs
|
log_kargs = kargs
|
||||||
else:
|
else:
|
||||||
log_kargs = self._strip_credentials(kargs)
|
log_kargs = self._strip_credentials(kargs)
|
||||||
|
|
||||||
utils.http_log_req(_logger, args, log_kargs)
|
self.http_log_req(_logger, args, log_kargs)
|
||||||
try:
|
try:
|
||||||
resp, body = self.request(*args, **kargs)
|
resp, body = self.request(*args, **kargs)
|
||||||
except httplib2.SSLHandshakeError as e:
|
except requests.exceptions.SSLError as e:
|
||||||
raise exceptions.SslCertificateValidationError(reason=e)
|
raise exceptions.SslCertificateValidationError(reason=str(e))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# Wrap the low-level connection error (socket timeout, redirect
|
# Wrap the low-level connection error (socket timeout, redirect
|
||||||
# limit, decompression error, etc) into our custom high-level
|
# limit, decompression error, etc) into our custom high-level
|
||||||
# connection exception (it is excepted in the upper layers of code)
|
# connection exception (it is excepted in the upper layers of code)
|
||||||
_logger.debug("throwing ConnectionFailed : %s", e)
|
_logger.debug("throwing ConnectionFailed : %s", e)
|
||||||
raise exceptions.CommunicationError(e)
|
raise exceptions.CommunicationError(str(e))
|
||||||
finally:
|
finally:
|
||||||
# Temporary Fix for gate failures. RPC calls and HTTP requests
|
# Temporary Fix for gate failures. RPC calls and HTTP requests
|
||||||
# seem to be stepping on each other resulting in bogus fd's being
|
# seem to be stepping on each other resulting in bogus fd's being
|
||||||
|
@ -199,7 +225,7 @@ class HTTPClient(httplib2.Http):
|
||||||
# Read body into string if it isn't obviously image data
|
# Read body into string if it isn't obviously image data
|
||||||
body_str = None
|
body_str = None
|
||||||
if 'content-type' in resp and resp['content-type'] != 'application/octet-stream':
|
if 'content-type' in resp and resp['content-type'] != 'application/octet-stream':
|
||||||
body_str = ''.join([chunk for chunk in body])
|
body_str = ''.join([chunk for chunk in body.decode('utf8')])
|
||||||
self.http_log_resp(_logger, resp, body_str)
|
self.http_log_resp(_logger, resp, body_str)
|
||||||
body = body_str
|
body = body_str
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
python-neutronclient
|
|
||||||
keyring
|
keyring
|
||||||
oslo.i18n # Apache-2.0
|
oslo.i18n # Apache-2.0
|
||||||
oslo.serialization>=1.10.0,!=2.19.1 # Apache-2.0
|
oslo.serialization>=1.10.0,!=2.19.1 # Apache-2.0
|
||||||
oslo.utils>=3.5.0 # Apache-2.0
|
oslo.utils>=3.5.0 # Apache-2.0
|
||||||
requests-toolbelt
|
requests-toolbelt
|
||||||
|
python-dateutil
|
||||||
|
|
|
@ -8,9 +8,9 @@ Build-Depends: python-setuptools,
|
||||||
python-pbr,
|
python-pbr,
|
||||||
python-keystoneclient,
|
python-keystoneclient,
|
||||||
python-fixtures,
|
python-fixtures,
|
||||||
|
python-dateutil,
|
||||||
python-httplib2,
|
python-httplib2,
|
||||||
python-dateutil,
|
python-dateutil,
|
||||||
python-neutronclient,
|
|
||||||
python-six,
|
python-six,
|
||||||
python-mock
|
python-mock
|
||||||
Standards-Version: 3.9.6
|
Standards-Version: 3.9.6
|
||||||
|
@ -23,7 +23,7 @@ Depends: ${misc:Depends},
|
||||||
python-httplib2,
|
python-httplib2,
|
||||||
python-prettytable,
|
python-prettytable,
|
||||||
bash-completion,
|
bash-completion,
|
||||||
python-neutronclient,
|
|
||||||
python-keystoneclient,
|
python-keystoneclient,
|
||||||
|
python-dateutil,
|
||||||
python-six
|
python-six
|
||||||
Description: This package contains the cgts-client project.
|
Description: This package contains the cgts-client project.
|
||||||
|
|
|
@ -14,8 +14,8 @@ BuildRequires: fdupes
|
||||||
Requires: python-httplib2
|
Requires: python-httplib2
|
||||||
Requires: python-prettytable
|
Requires: python-prettytable
|
||||||
Requires: bash-completion
|
Requires: bash-completion
|
||||||
Requires: python-neutronclient
|
|
||||||
Requires: python-keystoneclient
|
Requires: python-keystoneclient
|
||||||
|
Requires: python-dateutil
|
||||||
# Needed for python2 and python3 compatible
|
# Needed for python2 and python3 compatible
|
||||||
Requires: python-six
|
Requires: python-six
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue