Remove six
Replace the following items with Python 3 style code. - six.PY2 - six.text_type - six.string_type - six.binary_type - six.iterkeys - six.moves - six.itervalues Implements: blueprint six-removal Change-Id: I6195ceeeed2ebe1586973eaeef7fa9f29698fec2
This commit is contained in:
parent
ebb12611ca
commit
44f22cf2a5
|
@ -21,12 +21,6 @@
|
||||||
:synopsis: Infrastructure-as-a-Service Cloud platform.
|
:synopsis: Infrastructure-as-a-Service Cloud platform.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import six
|
|
||||||
|
|
||||||
import gettext
|
import gettext
|
||||||
|
|
||||||
|
gettext.install('ec2api')
|
||||||
if six.PY2:
|
|
||||||
gettext.install('ec2api', unicode=1)
|
|
||||||
else:
|
|
||||||
gettext.install('ec2api')
|
|
||||||
|
|
|
@ -28,7 +28,6 @@ from oslo_log import log as logging
|
||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
from oslo_utils import timeutils
|
from oslo_utils import timeutils
|
||||||
import requests
|
import requests
|
||||||
import six
|
|
||||||
import webob
|
import webob
|
||||||
import webob.dec
|
import webob.dec
|
||||||
import webob.exc
|
import webob.exc
|
||||||
|
@ -345,16 +344,16 @@ def ec2_error_ex(ex, req, unexpected=False):
|
||||||
if unexpected and status >= 500:
|
if unexpected and status >= 500:
|
||||||
message = _('Unknown error occurred.')
|
message = _('Unknown error occurred.')
|
||||||
elif getattr(ex, 'message', None):
|
elif getattr(ex, 'message', None):
|
||||||
message = six.text_type(ex.message)
|
message = str(ex.message)
|
||||||
elif ex.args and any(arg for arg in ex.args):
|
elif ex.args and any(arg for arg in ex.args):
|
||||||
message = " ".join(map(six.text_type, ex.args))
|
message = " ".join(map(str, ex.args))
|
||||||
else:
|
else:
|
||||||
message = six.text_type(ex)
|
message = str(ex)
|
||||||
if unexpected:
|
if unexpected:
|
||||||
# Log filtered environment for unexpected errors.
|
# Log filtered environment for unexpected errors.
|
||||||
env = req.environ.copy()
|
env = req.environ.copy()
|
||||||
for k in list(env.keys()):
|
for k in list(env.keys()):
|
||||||
if not isinstance(env[k], six.string_types):
|
if not isinstance(env[k], str):
|
||||||
env.pop(k)
|
env.pop(k)
|
||||||
log_fun(_('Environment: %s') % jsonutils.dumps(env))
|
log_fun(_('Environment: %s') % jsonutils.dumps(env))
|
||||||
return faults.ec2_error_response(request_id, code, message, status=status)
|
return faults.ec2_error_response(request_id, code, message, status=status)
|
||||||
|
@ -394,6 +393,6 @@ class Executor(wsgi.Application):
|
||||||
resp = webob.Response()
|
resp = webob.Response()
|
||||||
resp.status = 200
|
resp.status = 200
|
||||||
resp.headers['Content-Type'] = 'text/xml'
|
resp.headers['Content-Type'] = 'text/xml'
|
||||||
resp.body = six.binary_type(result)
|
resp.body = bytes(result)
|
||||||
|
|
||||||
return resp
|
return resp
|
||||||
|
|
|
@ -19,7 +19,6 @@ APIRequest class
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
import six
|
|
||||||
|
|
||||||
from ec2api.api import cloud
|
from ec2api.api import cloud
|
||||||
from ec2api.api import ec2utils
|
from ec2api.api import ec2utils
|
||||||
|
@ -67,7 +66,7 @@ class APIRequest(object):
|
||||||
if isinstance(args[key], dict):
|
if isinstance(args[key], dict):
|
||||||
if args[key] == {}:
|
if args[key] == {}:
|
||||||
continue
|
continue
|
||||||
first_subkey = next(six.iterkeys(args[key]))
|
first_subkey = next(iter(args[key].keys()))
|
||||||
if first_subkey.isdigit():
|
if first_subkey.isdigit():
|
||||||
s = args[key]
|
s = args[key]
|
||||||
args[key] = [convert_dicts_to_lists(s[k])
|
args[key] = [convert_dicts_to_lists(s[k])
|
||||||
|
|
|
@ -23,8 +23,6 @@ import collections
|
||||||
|
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
import six
|
|
||||||
import six.moves
|
|
||||||
|
|
||||||
from ec2api.api import address
|
from ec2api.api import address
|
||||||
from ec2api.api import availability_zone
|
from ec2api.api import availability_zone
|
||||||
|
@ -60,7 +58,7 @@ def module_and_param_types(module, *args, **kwargs):
|
||||||
def func_wrapped(*args, **kwargs):
|
def func_wrapped(*args, **kwargs):
|
||||||
impl_func = getattr(module, func.__name__)
|
impl_func = getattr(module, func.__name__)
|
||||||
context = args[1]
|
context = args[1]
|
||||||
params = collections.OrderedDict(six.moves.zip(
|
params = collections.OrderedDict(zip(
|
||||||
func.__code__.co_varnames[2:], param_types))
|
func.__code__.co_varnames[2:], param_types))
|
||||||
param_num = 0
|
param_num = 0
|
||||||
mandatory_params_num = (func.__code__.co_argcount - 2 -
|
mandatory_params_num = (func.__code__.co_argcount - 2 -
|
||||||
|
|
|
@ -18,15 +18,13 @@ import fnmatch
|
||||||
import inspect
|
import inspect
|
||||||
import operator
|
import operator
|
||||||
|
|
||||||
from oslo_config import cfg
|
|
||||||
from oslo_log import log as logging
|
|
||||||
import six
|
|
||||||
|
|
||||||
from ec2api.api import ec2utils
|
from ec2api.api import ec2utils
|
||||||
from ec2api.api import validator
|
from ec2api.api import validator
|
||||||
from ec2api.db import api as db_api
|
from ec2api.db import api as db_api
|
||||||
from ec2api import exception
|
from ec2api import exception
|
||||||
from ec2api.i18n import _
|
from ec2api.i18n import _
|
||||||
|
from oslo_config import cfg
|
||||||
|
from oslo_log import log as logging
|
||||||
|
|
||||||
|
|
||||||
ec2_opts = [
|
ec2_opts = [
|
||||||
|
@ -68,12 +66,8 @@ class OnCrashCleaner(object):
|
||||||
function(*args, **kwargs)
|
function(*args, **kwargs)
|
||||||
except Exception:
|
except Exception:
|
||||||
if inspect.ismethod(function):
|
if inspect.ismethod(function):
|
||||||
if six.PY2:
|
cmodule = function.__self__.__class__.__module__
|
||||||
cmodule = function.im_class.__module__
|
cname = function.__self__.__class__.__name__
|
||||||
cname = function.im_class.__name__
|
|
||||||
else:
|
|
||||||
cmodule = function.__self__.__class__.__module__
|
|
||||||
cname = function.__self__.__class__.__name__
|
|
||||||
name = '%s.%s.%s' % (cmodule, cname, function.__name__)
|
name = '%s.%s.%s' % (cmodule, cname, function.__name__)
|
||||||
elif inspect.isfunction(function):
|
elif inspect.isfunction(function):
|
||||||
name = '%s.%s' % (function.__module__, function.__name__)
|
name = '%s.%s' % (function.__module__, function.__name__)
|
||||||
|
|
|
@ -21,7 +21,6 @@ from oslo_config import cfg
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
from oslo_utils import timeutils
|
from oslo_utils import timeutils
|
||||||
import six
|
|
||||||
|
|
||||||
from ec2api import clients
|
from ec2api import clients
|
||||||
from ec2api.db import api as db_api
|
from ec2api.db import api as db_api
|
||||||
|
@ -103,7 +102,7 @@ def dict_from_dotted_str(items):
|
||||||
for key, value in items:
|
for key, value in items:
|
||||||
parts = key.split(".")
|
parts = key.split(".")
|
||||||
key = str(camelcase_to_underscore(parts[0]))
|
key = str(camelcase_to_underscore(parts[0]))
|
||||||
if isinstance(value, six.string_types):
|
if isinstance(value, str):
|
||||||
# NOTE(vish): Automatically convert strings back
|
# NOTE(vish): Automatically convert strings back
|
||||||
# into their respective values
|
# into their respective values
|
||||||
value = _try_convert(value)
|
value = _try_convert(value)
|
||||||
|
@ -146,10 +145,10 @@ def _render_data(el, data):
|
||||||
el.text = str(data).lower()
|
el.text = str(data).lower()
|
||||||
elif isinstance(data, datetime.datetime):
|
elif isinstance(data, datetime.datetime):
|
||||||
el.text = _database_to_isoformat(data)
|
el.text = _database_to_isoformat(data)
|
||||||
elif isinstance(data, six.binary_type):
|
elif isinstance(data, bytes):
|
||||||
el.text = data.decode("utf-8")
|
el.text = data.decode("utf-8")
|
||||||
elif data is not None:
|
elif data is not None:
|
||||||
el.text = six.text_type(data)
|
el.text = str(data)
|
||||||
|
|
||||||
|
|
||||||
def _database_to_isoformat(datetimeobj):
|
def _database_to_isoformat(datetimeobj):
|
||||||
|
|
|
@ -33,7 +33,6 @@ from oslo_concurrency import processutils
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
import six
|
|
||||||
|
|
||||||
from ec2api.api import common
|
from ec2api.api import common
|
||||||
from ec2api.api import ec2utils
|
from ec2api.api import ec2utils
|
||||||
|
@ -42,6 +41,7 @@ from ec2api import clients
|
||||||
from ec2api.db import api as db_api
|
from ec2api.db import api as db_api
|
||||||
from ec2api import exception
|
from ec2api import exception
|
||||||
from ec2api.i18n import _
|
from ec2api.i18n import _
|
||||||
|
import urllib.parse as parse
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -226,7 +226,7 @@ def register_image(context, name=None, image_location=None,
|
||||||
|
|
||||||
# Resolve the import type
|
# Resolve the import type
|
||||||
metadata['image_location'] = image_location
|
metadata['image_location'] = image_location
|
||||||
parsed_url = six.moves.urllib.parse.urlparse(image_location)
|
parsed_url = parse.urlparse(image_location)
|
||||||
is_s3_import = (parsed_url.scheme == '') or (parsed_url.scheme == 's3')
|
is_s3_import = (parsed_url.scheme == '') or (parsed_url.scheme == 's3')
|
||||||
is_url_import = not is_s3_import
|
is_url_import = not is_s3_import
|
||||||
|
|
||||||
|
@ -847,7 +847,7 @@ def _s3_create(context, metadata):
|
||||||
"""Gets a manifest from s3 and makes an image."""
|
"""Gets a manifest from s3 and makes an image."""
|
||||||
|
|
||||||
# Parse the metadata into bucket and manifest path
|
# Parse the metadata into bucket and manifest path
|
||||||
parsed_url = six.moves.urllib.parse.urlparse(metadata['image_location'])
|
parsed_url = parse.urlparse(metadata['image_location'])
|
||||||
if parsed_url.hostname is not None:
|
if parsed_url.hostname is not None:
|
||||||
# Handle s3://<BUCKET_NAME>/<KEY_PATH> case
|
# Handle s3://<BUCKET_NAME>/<KEY_PATH> case
|
||||||
bucket_name = parsed_url.hostname
|
bucket_name = parsed_url.hostname
|
||||||
|
@ -862,7 +862,7 @@ def _s3_create(context, metadata):
|
||||||
image_location = '/'.join([bucket_name, manifest_path])
|
image_location = '/'.join([bucket_name, manifest_path])
|
||||||
key = s3_client.get_object(Bucket=bucket_name, Key=manifest_path)
|
key = s3_client.get_object(Bucket=bucket_name, Key=manifest_path)
|
||||||
body = key['Body']
|
body = key['Body']
|
||||||
if isinstance(body, six.string_types):
|
if isinstance(body, str):
|
||||||
manifest = body
|
manifest = body
|
||||||
else:
|
else:
|
||||||
# TODO(andrey-mp): check big objects
|
# TODO(andrey-mp): check big objects
|
||||||
|
|
|
@ -23,7 +23,6 @@ from novaclient import exceptions as nova_exception
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
from oslo_utils import timeutils
|
from oslo_utils import timeutils
|
||||||
import six
|
|
||||||
|
|
||||||
from ec2api.api import common
|
from ec2api.api import common
|
||||||
from ec2api.api import ec2utils
|
from ec2api.api import ec2utils
|
||||||
|
@ -1047,7 +1046,7 @@ def _get_groups_name_to_id(context):
|
||||||
|
|
||||||
|
|
||||||
def _get_ip_info_for_instance(os_instance):
|
def _get_ip_info_for_instance(os_instance):
|
||||||
addresses = list(itertools.chain(*six.itervalues(os_instance.addresses)))
|
addresses = list(itertools.chain(*os_instance.addresses.values()))
|
||||||
fixed_ip = next((addr['addr'] for addr in addresses
|
fixed_ip = next((addr['addr'] for addr in addresses
|
||||||
if (addr['version'] == 4 and
|
if (addr['version'] == 4 and
|
||||||
addr['OS-EXT-IPS:type'] == 'fixed')), None)
|
addr['OS-EXT-IPS:type'] == 'fixed')), None)
|
||||||
|
@ -1688,7 +1687,7 @@ _NAME_TO_CODE = {
|
||||||
}
|
}
|
||||||
_CODE_TO_NAMES = {code: [item[0] for item in _NAME_TO_CODE.items()
|
_CODE_TO_NAMES = {code: [item[0] for item in _NAME_TO_CODE.items()
|
||||||
if item[1] == code]
|
if item[1] == code]
|
||||||
for code in set(six.itervalues(_NAME_TO_CODE))}
|
for code in set(_NAME_TO_CODE.values())}
|
||||||
|
|
||||||
|
|
||||||
def inst_state_name_to_code(name):
|
def inst_state_name_to_code(name):
|
||||||
|
|
|
@ -17,7 +17,6 @@ import copy
|
||||||
|
|
||||||
import netaddr
|
import netaddr
|
||||||
from novaclient import exceptions as nova_exception
|
from novaclient import exceptions as nova_exception
|
||||||
import six
|
|
||||||
|
|
||||||
from ec2api.api import common
|
from ec2api.api import common
|
||||||
from ec2api.api import ec2utils
|
from ec2api.api import ec2utils
|
||||||
|
@ -596,7 +595,7 @@ def _get_active_route_destinations(context, route_table):
|
||||||
if (item['vpc_id'] == route_table['vpc_id'] and
|
if (item['vpc_id'] == route_table['vpc_id'] and
|
||||||
(ec2utils.get_ec2_id_kind(item['id']) != 'vgw' or
|
(ec2utils.get_ec2_id_kind(item['id']) != 'vgw' or
|
||||||
item['id'] in vpn_connections))}
|
item['id'] in vpn_connections))}
|
||||||
for vpn in six.itervalues(vpn_connections):
|
for vpn in vpn_connections.values():
|
||||||
if vpn['vpn_gateway_id'] in destinations:
|
if vpn['vpn_gateway_id'] in destinations:
|
||||||
destinations[vpn['vpn_gateway_id']]['vpn_connection'] = vpn
|
destinations[vpn['vpn_gateway_id']]['vpn_connection'] = vpn
|
||||||
return destinations
|
return destinations
|
||||||
|
|
|
@ -16,7 +16,6 @@ import re
|
||||||
|
|
||||||
import netaddr
|
import netaddr
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
import six
|
|
||||||
|
|
||||||
from ec2api import exception
|
from ec2api import exception
|
||||||
from ec2api.i18n import _
|
from ec2api.i18n import _
|
||||||
|
@ -26,7 +25,7 @@ LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def validate_str(val, parameter_name, max_length=None):
|
def validate_str(val, parameter_name, max_length=None):
|
||||||
if (isinstance(val, six.string_types) and
|
if (isinstance(val, str) and
|
||||||
(max_length is None or max_length and len(val) <= max_length)):
|
(max_length is None or max_length and len(val) <= max_length)):
|
||||||
return True
|
return True
|
||||||
raise exception.ValidationError(
|
raise exception.ValidationError(
|
||||||
|
|
|
@ -19,7 +19,6 @@ from lxml import etree
|
||||||
import netaddr
|
import netaddr
|
||||||
from neutronclient.common import exceptions as neutron_exception
|
from neutronclient.common import exceptions as neutron_exception
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
import six
|
|
||||||
|
|
||||||
from ec2api.api import common
|
from ec2api.api import common
|
||||||
from ec2api.api import ec2utils
|
from ec2api.api import ec2utils
|
||||||
|
@ -322,7 +321,7 @@ def _format_customer_config(vpn_connection, customer_gateways, os_ikepolicies,
|
||||||
|
|
||||||
def _stop_vpn_connection(neutron, vpn_connection):
|
def _stop_vpn_connection(neutron, vpn_connection):
|
||||||
connection_ids = vpn_connection['os_ipsec_site_connections']
|
connection_ids = vpn_connection['os_ipsec_site_connections']
|
||||||
for os_connection_id in six.itervalues(connection_ids):
|
for os_connection_id in connection_ids.values():
|
||||||
try:
|
try:
|
||||||
neutron.delete_ipsec_site_connection(os_connection_id)
|
neutron.delete_ipsec_site_connection(os_connection_id)
|
||||||
except neutron_exception.NotFound:
|
except neutron_exception.NotFound:
|
||||||
|
|
|
@ -18,7 +18,6 @@ from oslo_config import cfg
|
||||||
from oslo_context import context
|
from oslo_context import context
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
from oslo_utils import timeutils
|
from oslo_utils import timeutils
|
||||||
import six
|
|
||||||
|
|
||||||
from ec2api import clients
|
from ec2api import clients
|
||||||
from ec2api import exception
|
from ec2api import exception
|
||||||
|
@ -71,7 +70,7 @@ class RequestContext(context.RequestContext):
|
||||||
self.project_id = project_id
|
self.project_id = project_id
|
||||||
self.remote_address = remote_address
|
self.remote_address = remote_address
|
||||||
timestamp = timeutils.utcnow()
|
timestamp = timeutils.utcnow()
|
||||||
if isinstance(timestamp, six.string_types):
|
if isinstance(timestamp, str):
|
||||||
timestamp = timeutils.parse_strtime(timestamp)
|
timestamp = timeutils.parse_strtime(timestamp)
|
||||||
self.timestamp = timestamp
|
self.timestamp = timestamp
|
||||||
|
|
||||||
|
|
|
@ -20,11 +20,8 @@ SHOULD include dedicated exception logging.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys
|
|
||||||
|
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
import six
|
|
||||||
|
|
||||||
from ec2api.i18n import _
|
from ec2api.i18n import _
|
||||||
|
|
||||||
|
@ -55,8 +52,7 @@ class EC2APIException(Exception):
|
||||||
if not message:
|
if not message:
|
||||||
try:
|
try:
|
||||||
message = self.msg_fmt % kwargs
|
message = self.msg_fmt % kwargs
|
||||||
except Exception:
|
except Exception as e:
|
||||||
exc_info = sys.exc_info()
|
|
||||||
# kwargs doesn't match a variable in the message
|
# kwargs doesn't match a variable in the message
|
||||||
# log the issue and the kwargs
|
# log the issue and the kwargs
|
||||||
LOG.exception('Exception in string format operation for '
|
LOG.exception('Exception in string format operation for '
|
||||||
|
@ -65,11 +61,11 @@ class EC2APIException(Exception):
|
||||||
LOG.error('%s: %s' % (name, value))
|
LOG.error('%s: %s' % (name, value))
|
||||||
|
|
||||||
if CONF.fatal_exception_format_errors:
|
if CONF.fatal_exception_format_errors:
|
||||||
six.reraise(*exc_info)
|
raise e
|
||||||
else:
|
else:
|
||||||
# at least get the core message out if something happened
|
# at least get the core message out if something happened
|
||||||
message = self.msg_fmt
|
message = self.msg_fmt
|
||||||
elif not isinstance(message, six.string_types):
|
elif not isinstance(message, str):
|
||||||
LOG.error("Message '%(msg)s' for %(ex)s exception is not "
|
LOG.error("Message '%(msg)s' for %(ex)s exception is not "
|
||||||
"a string",
|
"a string",
|
||||||
{'msg': message, 'ex': self.__class__.__name__})
|
{'msg': message, 'ex': self.__class__.__name__})
|
||||||
|
|
|
@ -20,8 +20,7 @@ import httplib2
|
||||||
from oslo_cache import core as cache_core
|
from oslo_cache import core as cache_core
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
import six
|
import urllib.parse as urlparse
|
||||||
import six.moves.urllib.parse as urlparse
|
|
||||||
import webob
|
import webob
|
||||||
|
|
||||||
from ec2api import context as ec2_context
|
from ec2api import context as ec2_context
|
||||||
|
@ -118,7 +117,7 @@ class MetadataRequestHandler(wsgi.Application):
|
||||||
msg = _('An unknown error has occurred. '
|
msg = _('An unknown error has occurred. '
|
||||||
'Please try your request again.')
|
'Please try your request again.')
|
||||||
return webob.exc.HTTPInternalServerError(
|
return webob.exc.HTTPInternalServerError(
|
||||||
explanation=six.text_type(msg))
|
explanation=str(msg))
|
||||||
|
|
||||||
def _proxy_request(self, req, requester):
|
def _proxy_request(self, req, requester):
|
||||||
headers = self._build_proxy_request_headers(requester)
|
headers = self._build_proxy_request_headers(requester)
|
||||||
|
@ -167,7 +166,7 @@ class MetadataRequestHandler(wsgi.Application):
|
||||||
)
|
)
|
||||||
LOG.warning(msg)
|
LOG.warning(msg)
|
||||||
return webob.exc.HTTPInternalServerError(
|
return webob.exc.HTTPInternalServerError(
|
||||||
explanation=six.text_type(msg))
|
explanation=str(msg))
|
||||||
else:
|
else:
|
||||||
raise Exception(_('Unexpected response code: %s') % resp.status)
|
raise Exception(_('Unexpected response code: %s') % resp.status)
|
||||||
|
|
||||||
|
@ -213,9 +212,9 @@ class MetadataRequestHandler(wsgi.Application):
|
||||||
msg = _('X-Instance-ID header is missing from request.')
|
msg = _('X-Instance-ID header is missing from request.')
|
||||||
elif project_id is None:
|
elif project_id is None:
|
||||||
msg = _('X-Tenant-ID header is missing from request.')
|
msg = _('X-Tenant-ID header is missing from request.')
|
||||||
elif not isinstance(os_instance_id, six.string_types):
|
elif not isinstance(os_instance_id, str):
|
||||||
msg = _('Multiple X-Instance-ID headers found within request.')
|
msg = _('Multiple X-Instance-ID headers found within request.')
|
||||||
elif not isinstance(project_id, six.string_types):
|
elif not isinstance(project_id, str):
|
||||||
msg = _('Multiple X-Tenant-ID headers found within request.')
|
msg = _('Multiple X-Tenant-ID headers found within request.')
|
||||||
else:
|
else:
|
||||||
msg = None
|
msg = None
|
||||||
|
@ -277,7 +276,7 @@ class MetadataRequestHandler(wsgi.Application):
|
||||||
self.cache_region)
|
self.cache_region)
|
||||||
|
|
||||||
def _add_response_data(self, response, data):
|
def _add_response_data(self, response, data):
|
||||||
if isinstance(data, six.text_type):
|
if isinstance(data, str):
|
||||||
response.text = data
|
response.text = data
|
||||||
else:
|
else:
|
||||||
response.body = data
|
response.body = data
|
||||||
|
|
|
@ -19,7 +19,6 @@ from novaclient import exceptions as nova_exception
|
||||||
from oslo_cache import core as cache_core
|
from oslo_cache import core as cache_core
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
import six
|
|
||||||
|
|
||||||
from ec2api.api import clients
|
from ec2api.api import clients
|
||||||
from ec2api.api import ec2utils
|
from ec2api.api import ec2utils
|
||||||
|
@ -293,7 +292,7 @@ def _format_metadata_item(data):
|
||||||
elif isinstance(data, list):
|
elif isinstance(data, list):
|
||||||
return '\n'.join(data)
|
return '\n'.join(data)
|
||||||
else:
|
else:
|
||||||
return six.text_type(data)
|
return str(data)
|
||||||
|
|
||||||
|
|
||||||
def _find_path_in_tree(data, path_tokens):
|
def _find_path_in_tree(data, path_tokens):
|
||||||
|
|
|
@ -40,8 +40,7 @@ from oslo_config import cfg
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
from oslo_utils import fileutils
|
from oslo_utils import fileutils
|
||||||
import routes
|
import routes
|
||||||
import six
|
from urllib import parse
|
||||||
from six.moves.urllib import parse
|
|
||||||
import webob
|
import webob
|
||||||
|
|
||||||
from ec2api import paths
|
from ec2api import paths
|
||||||
|
@ -176,7 +175,7 @@ class BaseRequestHandler(object):
|
||||||
self.set_status(404)
|
self.set_status(404)
|
||||||
|
|
||||||
def finish(self, body=''):
|
def finish(self, body=''):
|
||||||
if isinstance(body, six.binary_type):
|
if isinstance(body, bytes):
|
||||||
self.response.body = body
|
self.response.body = body
|
||||||
else:
|
else:
|
||||||
self.response.body = body.encode("utf-8")
|
self.response.body = body.encode("utf-8")
|
||||||
|
@ -187,11 +186,11 @@ class BaseRequestHandler(object):
|
||||||
def render_xml(self, value):
|
def render_xml(self, value):
|
||||||
assert isinstance(value, dict) and len(value) == 1
|
assert isinstance(value, dict) and len(value) == 1
|
||||||
self.set_header("Content-Type", "application/xml; charset=UTF-8")
|
self.set_header("Content-Type", "application/xml; charset=UTF-8")
|
||||||
name = next(six.iterkeys(value))
|
name = next(iter(value.keys()))
|
||||||
parts = []
|
parts = []
|
||||||
parts.append('<' + name +
|
parts.append('<' + name +
|
||||||
' xmlns="http://s3.amazonaws.com/doc/2006-03-01/">')
|
' xmlns="http://s3.amazonaws.com/doc/2006-03-01/">')
|
||||||
self._render_parts(next(six.itervalues(value)), parts)
|
self._render_parts(next(iter(value.values())), parts)
|
||||||
parts.append('</' + name + '>')
|
parts.append('</' + name + '>')
|
||||||
self.finish('<?xml version="1.0" encoding="UTF-8"?>\n' +
|
self.finish('<?xml version="1.0" encoding="UTF-8"?>\n' +
|
||||||
''.join(parts))
|
''.join(parts))
|
||||||
|
@ -200,9 +199,9 @@ class BaseRequestHandler(object):
|
||||||
if not parts:
|
if not parts:
|
||||||
parts = []
|
parts = []
|
||||||
|
|
||||||
if isinstance(value, six.string_types):
|
if isinstance(value, str):
|
||||||
parts.append(utils.xhtml_escape(value))
|
parts.append(utils.xhtml_escape(value))
|
||||||
elif isinstance(value, six.integer_types):
|
elif isinstance(value, int):
|
||||||
parts.append(str(value))
|
parts.append(str(value))
|
||||||
elif isinstance(value, datetime.datetime):
|
elif isinstance(value, datetime.datetime):
|
||||||
parts.append(value.strftime("%Y-%m-%dT%H:%M:%S.000Z"))
|
parts.append(value.strftime("%Y-%m-%dT%H:%M:%S.000Z"))
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
# See http://code.google.com/p/python-nose/issues/detail?id=373
|
# See http://code.google.com/p/python-nose/issues/detail?id=373
|
||||||
# The code below enables nosetests to work with i18n _() blocks
|
# The code below enables nosetests to work with i18n _() blocks
|
||||||
from six.moves import builtins
|
import builtins
|
||||||
setattr(builtins, '_', lambda x: x)
|
setattr(builtins, '_', lambda x: x)
|
||||||
|
|
||||||
# NOTE(ft): this is required by test_s3.S3APITestCase to switch execution
|
# NOTE(ft): this is required by test_s3.S3APITestCase to switch execution
|
||||||
|
|
|
@ -17,7 +17,6 @@ from unittest import mock
|
||||||
|
|
||||||
from oslo_context import context
|
from oslo_context import context
|
||||||
from oslo_utils import timeutils
|
from oslo_utils import timeutils
|
||||||
import six
|
|
||||||
|
|
||||||
from ec2api.api import apirequest
|
from ec2api.api import apirequest
|
||||||
from ec2api.tests.unit import base
|
from ec2api.tests.unit import base
|
||||||
|
@ -100,7 +99,7 @@ class EC2RequesterTestCase(base.BaseTestCase):
|
||||||
def test_render_response_utf8(self):
|
def test_render_response_utf8(self):
|
||||||
req = apirequest.APIRequest("FakeAction", "FakeVersion", {})
|
req = apirequest.APIRequest("FakeAction", "FakeVersion", {})
|
||||||
resp = {
|
resp = {
|
||||||
'utf8': six.unichr(40960) + u'abcd' + six.unichr(1972)
|
'utf8': chr(40960) + u'abcd' + chr(1972)
|
||||||
}
|
}
|
||||||
data = req._render_response(resp, 'uuid').decode()
|
data = req._render_response(resp, 'uuid').decode()
|
||||||
self.assertIn('<utf8>ꀀabcd޴</utf8>', data)
|
self.assertIn('<utf8>ꀀabcd޴</utf8>', data)
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
import os
|
import os
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
|
|
||||||
import six
|
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
from cinderclient import exceptions as cinder_exception
|
from cinderclient import exceptions as cinder_exception
|
||||||
|
@ -970,7 +969,7 @@ class S3TestCase(base.BaseTestCase):
|
||||||
'-out', public_key,
|
'-out', public_key,
|
||||||
'-subj', subject)
|
'-subj', subject)
|
||||||
text = "some @#!%^* test text"
|
text = "some @#!%^* test text"
|
||||||
process_input = text.encode("ascii") if six.PY3 else text
|
process_input = text.encode("ascii")
|
||||||
enc, _err = processutils.execute('openssl',
|
enc, _err = processutils.execute('openssl',
|
||||||
'rsautl',
|
'rsautl',
|
||||||
'-certin',
|
'-certin',
|
||||||
|
@ -982,6 +981,5 @@ class S3TestCase(base.BaseTestCase):
|
||||||
self.configure(x509_root_private_key=private_key)
|
self.configure(x509_root_private_key=private_key)
|
||||||
dec = image_api._decrypt_text(enc)
|
dec = image_api._decrypt_text(enc)
|
||||||
self.assertIsInstance(dec, bytes)
|
self.assertIsInstance(dec, bytes)
|
||||||
if six.PY3:
|
dec = dec.decode('ascii')
|
||||||
dec = dec.decode('ascii')
|
|
||||||
self.assertEqual(text, dec)
|
self.assertEqual(text, dec)
|
||||||
|
|
|
@ -20,7 +20,6 @@ import random
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
|
|
||||||
from novaclient import exceptions as nova_exception
|
from novaclient import exceptions as nova_exception
|
||||||
import six
|
|
||||||
|
|
||||||
from ec2api.api import instance as instance_api
|
from ec2api.api import instance as instance_api
|
||||||
import ec2api.clients
|
import ec2api.clients
|
||||||
|
@ -703,7 +702,8 @@ class InstanceTestCase(base.ApiTestCase):
|
||||||
utcnow.return_value = datetime.datetime(2015, 1, 19, 23, 34, 45, 123)
|
utcnow.return_value = datetime.datetime(2015, 1, 19, 23, 34, 45, 123)
|
||||||
resp = self.execute(operation,
|
resp = self.execute(operation,
|
||||||
{'InstanceId': fakes.ID_EC2_INSTANCE_2})
|
{'InstanceId': fakes.ID_EC2_INSTANCE_2})
|
||||||
expected_data = (base64.b64encode(six.b(getter.return_value))
|
expected_data = (base64.b64encode(getter.return_value.
|
||||||
|
encode("latin-1"))
|
||||||
.decode("utf-8"))
|
.decode("utf-8"))
|
||||||
self.assertEqual({'instanceId': fakes.ID_EC2_INSTANCE_2,
|
self.assertEqual({'instanceId': fakes.ID_EC2_INSTANCE_2,
|
||||||
'timestamp': '2015-01-19T23:34:45.000Z',
|
'timestamp': '2015-01-19T23:34:45.000Z',
|
||||||
|
|
|
@ -18,7 +18,6 @@ from unittest import mock
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from oslo_config import fixture as config_fixture
|
from oslo_config import fixture as config_fixture
|
||||||
from oslotest import base as test_base
|
from oslotest import base as test_base
|
||||||
import six
|
|
||||||
import testtools
|
import testtools
|
||||||
import webob
|
import webob
|
||||||
|
|
||||||
|
@ -366,7 +365,7 @@ class ProxyTestCase(test_base.BaseTestCase):
|
||||||
@mock.patch('ec2api.metadata.api.instance_api')
|
@mock.patch('ec2api.metadata.api.instance_api')
|
||||||
@mock.patch('ec2api.metadata.MetadataRequestHandler._validate_signature')
|
@mock.patch('ec2api.metadata.MetadataRequestHandler._validate_signature')
|
||||||
def test_get_metadata_items(self, validate, instance_api, db_api, nova):
|
def test_get_metadata_items(self, validate, instance_api, db_api, nova):
|
||||||
FAKE_USER_DATA = u'fake_user_data-' + six.unichr(1071)
|
FAKE_USER_DATA = u'fake_user_data-' + chr(1071)
|
||||||
nova.return_value.servers.list.return_value = [
|
nova.return_value.servers.list.return_value = [
|
||||||
fakes.OSInstance(fakes.OS_INSTANCE_1)]
|
fakes.OSInstance(fakes.OS_INSTANCE_1)]
|
||||||
keypair = mock.Mock(public_key=fakes.PUBLIC_KEY_KEY_PAIR)
|
keypair = mock.Mock(public_key=fakes.PUBLIC_KEY_KEY_PAIR)
|
||||||
|
|
|
@ -19,7 +19,6 @@ from unittest import mock
|
||||||
from novaclient import exceptions as nova_exception
|
from novaclient import exceptions as nova_exception
|
||||||
from oslo_cache import core as cache_core
|
from oslo_cache import core as cache_core
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
import six
|
|
||||||
|
|
||||||
from ec2api import exception
|
from ec2api import exception
|
||||||
from ec2api.metadata import api
|
from ec2api.metadata import api
|
||||||
|
@ -29,7 +28,7 @@ from ec2api.tests.unit import matchers
|
||||||
from ec2api.tests.unit import tools
|
from ec2api.tests.unit import tools
|
||||||
|
|
||||||
CONF = cfg.CONF
|
CONF = cfg.CONF
|
||||||
FAKE_USER_DATA = u'fake_user_data-' + six.unichr(1071)
|
FAKE_USER_DATA = u'fake_user_data-' + chr(1071)
|
||||||
|
|
||||||
|
|
||||||
class MetadataApiTestCase(base.ApiTestCase):
|
class MetadataApiTestCase(base.ApiTestCase):
|
||||||
|
|
|
@ -32,7 +32,6 @@ python-neutronclient>=6.7.0 # Apache-2.0
|
||||||
python-novaclient>=10.1.0 # Apache-2.0
|
python-novaclient>=10.1.0 # Apache-2.0
|
||||||
python-openstackclient>=3.14.0 # Apache-2.0
|
python-openstackclient>=3.14.0 # Apache-2.0
|
||||||
Routes>=2.4.1 # MIT
|
Routes>=2.4.1 # MIT
|
||||||
six>=1.11.0 # MIT
|
|
||||||
SQLAlchemy>=1.2.5 # MIT
|
SQLAlchemy>=1.2.5 # MIT
|
||||||
sqlalchemy-migrate>=0.11.0 # Apache-2.0
|
sqlalchemy-migrate>=0.11.0 # Apache-2.0
|
||||||
WebOb>=1.7.4 # MIT
|
WebOb>=1.7.4 # MIT
|
||||||
|
|
Loading…
Reference in New Issue