Merge "Remove six and python 2.7 full support"

This commit is contained in:
Zuul 2020-04-23 14:12:38 +00:00 committed by Gerrit Code Review
commit 5819dcb008
10 changed files with 35 additions and 52 deletions

View File

@ -16,7 +16,6 @@ import weakref
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 importutils from oslo_utils import importutils
import six
from stevedore import enabled from stevedore import enabled
from heat.common import exception from heat.common import exception
@ -95,7 +94,7 @@ class ClientBackend(object):
context) context)
except (ImportError, RuntimeError, cfg.NoSuchOptError) as err: except (ImportError, RuntimeError, cfg.NoSuchOptError) as err:
msg = _('Invalid cloud_backend setting in heat.conf ' msg = _('Invalid cloud_backend setting in heat.conf '
'detected - %s') % six.text_type(err) 'detected - %s') % str(err)
LOG.error(msg) LOG.error(msg)
raise exception.Invalid(reason=msg) raise exception.Invalid(reason=msg)

View File

@ -21,7 +21,6 @@ from oslo_config import cfg
from oslo_utils import excutils from oslo_utils import excutils
import requests import requests
import six
from heat.common import config from heat.common import config
from heat.common import exception as heat_exception from heat.common import exception as heat_exception
@ -29,8 +28,7 @@ from heat.common import exception as heat_exception
cfg.CONF.import_opt('client_retry_limit', 'heat.common.config') cfg.CONF.import_opt('client_retry_limit', 'heat.common.config')
@six.add_metaclass(abc.ABCMeta) class ClientPlugin(object, metaclass=abc.ABCMeta):
class ClientPlugin(object):
# Module which contains all exceptions classes which the client # Module which contains all exceptions classes which the client
# may emit # may emit
@ -139,11 +137,10 @@ class ClientPlugin(object):
if self.exceptions_module: if self.exceptions_module:
if isinstance(self.exceptions_module, list): if isinstance(self.exceptions_module, list):
for m in self.exceptions_module: for m in self.exceptions_module:
if type(ex) in six.itervalues(m.__dict__): if type(ex) in m.__dict__.values():
return True return True
else: else:
return type(ex) in six.itervalues( return type(ex) in self.exceptions_module.__dict__.values()
self.exceptions_module.__dict__)
return False return False
def is_not_found(self, ex): def is_not_found(self, ex):

View File

@ -13,13 +13,10 @@
import abc import abc
import six
from heat.common import exception from heat.common import exception
@six.add_metaclass(abc.ABCMeta) class MicroversionMixin(object, metaclass=abc.ABCMeta):
class MicroversionMixin(object):
"""Mixin For microversion support.""" """Mixin For microversion support."""
def client(self, version=None): def client(self, version=None):

View File

@ -18,6 +18,7 @@ from email.mime import text
import os import os
import pkgutil import pkgutil
import string import string
from urllib import parse as urlparse
from neutronclient.common import exceptions as q_exceptions from neutronclient.common import exceptions as q_exceptions
from novaclient import api_versions from novaclient import api_versions
@ -27,8 +28,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 netutils from oslo_utils import netutils
import six
from six.moves.urllib import parse as urlparse
import tenacity import tenacity
from heat.common import exception from heat.common import exception
@ -225,7 +224,7 @@ class NovaClientPlugin(microversion_mixin.MicroversionMixin,
""" """
# not checking with is_uuid_like as most tests use strings e.g. '1234' # not checking with is_uuid_like as most tests use strings e.g. '1234'
if isinstance(server, six.string_types): if isinstance(server, str):
server = self.fetch_server(server) server = self.fetch_server(server)
if server is None: if server is None:
return False return False
@ -607,7 +606,7 @@ echo -e '%s\tALL=(ALL)\tNOPASSWD: ALL' >> /etc/sudoers
"nova server metadata needs to be a Map.")) "nova server metadata needs to be a Map."))
return dict((key, (value if isinstance(value, return dict((key, (value if isinstance(value,
six.string_types) str)
else jsonutils.dumps(value)) else jsonutils.dumps(value))
) for (key, value) in metadata.items()) ) for (key, value) in metadata.items())
@ -675,7 +674,7 @@ echo -e '%s\tALL=(ALL)\tNOPASSWD: ALL' >> /etc/sudoers
except exceptions.UnsupportedConsoleType as ex: except exceptions.UnsupportedConsoleType as ex:
url = ex.message url = ex.message
except Exception as e: except Exception as e:
url = _('Cannot get console url: %s') % six.text_type(e) url = _('Cannot get console url: %s') % str(e)
return url return url

View File

@ -16,7 +16,6 @@
from oslo_config import cfg from oslo_config import cfg
from saharaclient.api import base as sahara_base from saharaclient.api import base as sahara_base
from saharaclient import client as sahara_client from saharaclient import client as sahara_client
import six
from heat.common import exception from heat.common import exception
from heat.common.i18n import _ from heat.common.i18n import _
@ -117,7 +116,7 @@ class SaharaClientPlugin(client_plugin.ClientPlugin):
raise exception.Error( raise exception.Error(
_("Error retrieving %(entity)s list from sahara: " _("Error retrieving %(entity)s list from sahara: "
"%(err)s") % dict(entity=resource_name, "%(err)s") % dict(entity=resource_name,
err=six.text_type(ex))) err=str(ex)))
num_matches = len(obj_list) num_matches = len(obj_list)
if num_matches == 0: if num_matches == 0:
raise exception.EntityNotFound(entity=resource_name or 'entity', raise exception.EntityNotFound(entity=resource_name or 'entity',

View File

@ -17,10 +17,9 @@ import hashlib
import logging import logging
import random import random
import time import time
from urllib import parse
from oslo_config import cfg from oslo_config import cfg
import six
from six.moves.urllib import parse
from swiftclient import client as sc from swiftclient import client as sc
from swiftclient import exceptions from swiftclient import exceptions
from swiftclient import utils as swiftclient_utils from swiftclient import utils as swiftclient_utils
@ -98,8 +97,8 @@ class SwiftClientPlugin(client_plugin.ClientPlugin):
if key_header not in self.client().head_account(): if key_header not in self.client().head_account():
self.client().post_account({ self.client().post_account({
key_header: hashlib.sha224( key_header: hashlib.sha224(
six.b(six.text_type( str(random.getrandbits(256)).encode(
random.getrandbits(256)))).hexdigest()[:32]}) "latin-1")).hexdigest()[:32]})
key = self.client().head_account()[key_header] key = self.client().head_account()[key_header]
@ -173,5 +172,5 @@ class SwiftClientPlugin(client_plugin.ClientPlugin):
'container %(container)s, ' 'container %(container)s, '
'reason: %(reason)s.') % 'reason: %(reason)s.') %
{'container': files_container, {'container': files_container,
'reason': six.text_type(cex)}) 'reason': str(cex)})
return files return files

View File

@ -11,8 +11,6 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import six
from oslo_log import log as logging from oslo_log import log as logging
from zaqarclient.queues.v2 import client as zaqarclient from zaqarclient.queues.v2 import client as zaqarclient
from zaqarclient.transport import errors as zaqar_errors from zaqarclient.transport import errors as zaqar_errors
@ -75,7 +73,7 @@ class ZaqarClientPlugin(client_plugin.ClientPlugin):
return isinstance(ex, zaqar_errors.ResourceNotFound) return isinstance(ex, zaqar_errors.ResourceNotFound)
def get_queue(self, queue_name): def get_queue(self, queue_name):
if not isinstance(queue_name, six.string_types): if not isinstance(queue_name, str):
raise TypeError(_('Queue name must be a string')) raise TypeError(_('Queue name must be a string'))
if not (0 < len(queue_name) <= 64): if not (0 < len(queue_name) <= 64):
raise ValueError(_('Queue name length must be 1-64')) raise ValueError(_('Queue name length must be 1-64'))

View File

@ -13,8 +13,6 @@
import collections import collections
import six
from heat.common.i18n import _ from heat.common.i18n import _
from heat.common import exception from heat.common import exception
@ -31,7 +29,7 @@ class Conditions(object):
self._resolved = {} self._resolved = {}
def validate(self): def validate(self):
for name, cond in six.iteritems(self._conditions): for name, cond in self._conditions.items():
self._check_condition_type(name, cond) self._check_condition_type(name, cond)
function.validate(cond) function.validate(cond)
@ -56,7 +54,7 @@ class Conditions(object):
if isinstance(condition_name, bool): if isinstance(condition_name, bool):
return condition_name return condition_name
if not (isinstance(condition_name, six.string_types) and if not (isinstance(condition_name, str) and
condition_name in self._conditions): condition_name in self._conditions):
raise ValueError(_('Invalid condition "%s"') % condition_name) raise ValueError(_('Invalid condition "%s"') % condition_name)

View File

@ -15,7 +15,6 @@ import croniter
import eventlet import eventlet
import netaddr import netaddr
import pytz import pytz
import six
from neutron_lib.api import validators from neutron_lib.api import validators
from oslo_utils import timeutils from oslo_utils import timeutils
@ -35,7 +34,7 @@ class IPConstraint(constraints.BaseCustomConstraint):
def validate(self, value, context, template=None): def validate(self, value, context, template=None):
self._error_message = 'Invalid IP address' self._error_message = 'Invalid IP address'
if not isinstance(value, six.string_types): if not isinstance(value, str):
return False return False
msg = validators.validate_ip_address(value) msg = validators.validate_ip_address(value)
if msg is not None: if msg is not None:
@ -59,7 +58,7 @@ class DNSNameConstraint(constraints.BaseCustomConstraint):
self._error_message = ("'%(value)s' not in valid format." self._error_message = ("'%(value)s' not in valid format."
" Reason: %(reason)s") % { " Reason: %(reason)s") % {
'value': value, 'value': value,
'reason': six.text_type(ex)} 'reason': str(ex)}
return False return False
return True return True
@ -114,7 +113,7 @@ class CIDRConstraint(constraints.BaseCustomConstraint):
return False return False
return True return True
except Exception as ex: except Exception as ex:
self._error_message = 'Invalid net cidr %s ' % six.text_type(ex) self._error_message = 'Invalid net cidr %s ' % str(ex)
return False return False
@ -158,7 +157,7 @@ class CRONExpressionConstraint(constraints.BaseCustomConstraint):
return True return True
except Exception as ex: except Exception as ex:
self._error_message = _( self._error_message = _(
'Invalid CRON expression: %s') % six.text_type(ex) 'Invalid CRON expression: %s') % str(ex)
return False return False
@ -172,7 +171,7 @@ class TimezoneConstraint(constraints.BaseCustomConstraint):
return True return True
except Exception as ex: except Exception as ex:
self._error_message = _( self._error_message = _(
'Invalid timezone: %s') % six.text_type(ex) 'Invalid timezone: %s') % str(ex)
return False return False
@ -190,5 +189,5 @@ class ExpirationConstraint(constraints.BaseCustomConstraint):
except Exception as ex: except Exception as ex:
self._error_message = (_( self._error_message = (_(
'Expiration {0} is invalid: {1}').format(value, 'Expiration {0} is invalid: {1}').format(value,
six.text_type(ex))) str(ex)))
return False return False

View File

@ -21,7 +21,6 @@ from oslo_config import cfg
from oslo_log import log from oslo_log import log
from oslo_utils import reflection from oslo_utils import reflection
from oslo_utils import strutils from oslo_utils import strutils
import six
from heat.common import cache from heat.common import cache
from heat.common import exception from heat.common import exception
@ -149,7 +148,7 @@ class Schema(collections.Mapping):
if isinstance(self.schema, AnyIndexDict): if isinstance(self.schema, AnyIndexDict):
self.schema.value.validate(context) self.schema.value.validate(context)
else: else:
for nested_schema in six.itervalues(self.schema): for nested_schema in self.schema.values():
nested_schema.validate(context) nested_schema.validate(context)
def _validate_default(self, context): def _validate_default(self, context):
@ -195,9 +194,9 @@ class Schema(collections.Mapping):
elif self.type == self.NUMBER: elif self.type == self.NUMBER:
return Schema.str_to_num(value) return Schema.str_to_num(value)
elif self.type == self.STRING: elif self.type == self.STRING:
return six.text_type(value) return str(value)
elif self.type == self.BOOLEAN: elif self.type == self.BOOLEAN:
return strutils.bool_from_string(six.text_type(value), return strutils.bool_from_string(str(value),
strict=True) strict=True)
except ValueError: except ValueError:
raise ValueError(_('Value "%(val)s" is invalid for data type ' raise ValueError(_('Value "%(val)s" is invalid for data type '
@ -215,7 +214,7 @@ class Schema(collections.Mapping):
if type(constraint) not in skipped: if type(constraint) not in skipped:
constraint.validate(value, self, context) constraint.validate(value, self, context)
except ValueError as ex: except ValueError as ex:
raise exception.StackValidationFailed(message=six.text_type(ex)) raise exception.StackValidationFailed(message=str(ex))
def __getitem__(self, key): def __getitem__(self, key):
if key == self.TYPE: if key == self.TYPE:
@ -265,7 +264,7 @@ class AnyIndexDict(collections.Mapping):
self.value = value self.value = value
def __getitem__(self, key): def __getitem__(self, key):
if key != self.ANYTHING and not isinstance(key, six.integer_types): if key != self.ANYTHING and not isinstance(key, int):
raise KeyError(_('Invalid key %s') % key) raise KeyError(_('Invalid key %s') % key)
return self.value return self.value
@ -277,7 +276,6 @@ class AnyIndexDict(collections.Mapping):
return 1 return 1
@six.python_2_unicode_compatible
class Constraint(collections.Mapping): class Constraint(collections.Mapping):
"""Parent class for constraints on allowable values for a Property. """Parent class for constraints on allowable values for a Property.
@ -353,7 +351,7 @@ class Range(Constraint):
self.max = max self.max = max
for param in (min, max): for param in (min, max):
if not isinstance(param, (float, six.integer_types, type(None))): if not isinstance(param, (float, int, type(None))):
raise exception.InvalidSchemaError( raise exception.InvalidSchemaError(
message=_('min/max must be numeric')) message=_('min/max must be numeric'))
@ -422,7 +420,7 @@ class Length(Range):
super(Length, self).__init__(min, max, description) super(Length, self).__init__(min, max, description)
for param in (min, max): for param in (min, max):
if not isinstance(param, (six.integer_types, type(None))): if not isinstance(param, (int, type(None))):
msg = _('min/max length must be integral') msg = _('min/max length must be integral')
raise exception.InvalidSchemaError(message=msg) raise exception.InvalidSchemaError(message=msg)
@ -471,7 +469,7 @@ class Modulo(Constraint):
'an offset value specified.')) 'an offset value specified.'))
for param in (step, offset): for param in (step, offset):
if not isinstance(param, (float, six.integer_types, type(None))): if not isinstance(param, (float, int, type(None))):
raise exception.InvalidSchemaError( raise exception.InvalidSchemaError(
message=_('step/offset must be numeric')) message=_('step/offset must be numeric'))
@ -543,7 +541,7 @@ class AllowedValues(Constraint):
def __init__(self, allowed, description=None): def __init__(self, allowed, description=None):
super(AllowedValues, self).__init__(description) super(AllowedValues, self).__init__(description)
if (not isinstance(allowed, collections.Sequence) or if (not isinstance(allowed, collections.Sequence) or
isinstance(allowed, six.string_types)): isinstance(allowed, str)):
raise exception.InvalidSchemaError( raise exception.InvalidSchemaError(
message=_('AllowedValues must be a list')) message=_('AllowedValues must be a list'))
self.allowed = tuple(allowed) self.allowed = tuple(allowed)
@ -589,7 +587,7 @@ class AllowedPattern(Constraint):
def __init__(self, pattern, description=None): def __init__(self, pattern, description=None):
super(AllowedPattern, self).__init__(description) super(AllowedPattern, self).__init__(description)
if not isinstance(pattern, six.string_types): if not isinstance(pattern, str):
raise exception.InvalidSchemaError( raise exception.InvalidSchemaError(
message=_('AllowedPattern must be a string')) message=_('AllowedPattern must be a string'))
self.pattern = pattern self.pattern = pattern
@ -701,13 +699,13 @@ class BaseCustomConstraint(object):
try: try:
self.validate_with_client(context.clients, value_to_validate) self.validate_with_client(context.clients, value_to_validate)
except self.expected_exceptions as e: except self.expected_exceptions as e:
self._error_message = six.text_type(e) self._error_message = str(e)
return False return False
else: else:
return True return True
class_name = reflection.get_class_name(self, fully_qualified=False) class_name = reflection.get_class_name(self, fully_qualified=False)
cache_value_prefix = "{0}:{1}".format(class_name, cache_value_prefix = "{0}:{1}".format(class_name,
six.text_type(context.tenant_id)) str(context.tenant_id))
validation_result = check_cache_or_validate_value( validation_result = check_cache_or_validate_value(
cache_value_prefix, value) cache_value_prefix, value)
# if validation failed we should not store it in cache # if validation failed we should not store it in cache