Remove six and python 2.7 full support

Six is in use to help us to keep support for python 2.7.
Since the ussuri cycle we decide to remove the python 2.7
support so we can go ahead and also remove six usage from
the python code.

Review process and help
-----------------------
Removing six introduce a lot of changes and an huge amount of modified files
To simplify reviews we decided to split changes into several patches to avoid
painful reviews and avoid mistakes.

To review this patch you can use the six documentation [1] to obtain help and
understand choices.

Additional informations
-----------------------
Changes related to 'six.b(data)' [2]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

six.b [2] encode the given datas in latin-1 in python3 so I did the same
things in this patch.

Latin-1 is equal to iso-8859-1 [3].

This encoding is the default encoding [4] of certain descriptive HTTP
headers.

I suggest to keep latin-1 for the moment and to move to another encoding
in a follow-up patch if needed to move to most powerful encoding (utf8).

HTML4 support utf8 charset and utf8 is the default charset for HTML5 [5].

Note that this commit message is autogenerated and not necesserly contains
changes related to 'six.b'

[1] https://six.readthedocs.io/
[2] https://six.readthedocs.io/#six.b
[3] https://docs.python.org/3/library/codecs.html#standard-encodings
[4] https://www.w3schools.com/charsets/ref_html_8859.asp
[5] https://www.w3schools.com/html/html_charset.asp

Patch 13 of a serie of 28 patches

Change-Id: I09aa3b7ddd93087c3f92c76c893c609cb9473842
This commit is contained in:
Hervé Beraud 2019-11-20 19:37:26 +01:00
parent f5d6c01cad
commit 5fa48d67a2
10 changed files with 113 additions and 133 deletions

View File

@ -12,11 +12,10 @@
import collections
import copy
import functools
import itertools
import operator
import six
from heat.common import exception
from heat.engine import function
from heat.engine import properties
@ -111,7 +110,7 @@ class ResourceDefinition(object):
self._dep_names = None
self._all_dep_attrs = None
assert isinstance(self.description, six.string_types)
assert isinstance(self.description, str)
if properties is not None:
assert isinstance(properties, (collections.Mapping,
@ -126,7 +125,7 @@ class ResourceDefinition(object):
if depends is not None:
assert isinstance(depends, (collections.Sequence,
function.Function))
assert not isinstance(depends, six.string_types)
assert not isinstance(depends, str)
self._hash ^= _hash_data(depends)
if deletion_policy is not None:
@ -139,13 +138,13 @@ class ResourceDefinition(object):
self._hash ^= _hash_data(update_policy)
if external_id is not None:
assert isinstance(external_id, (six.string_types,
assert isinstance(external_id, (str,
function.Function))
self._hash ^= _hash_data(external_id)
self._deletion_policy = self.RETAIN
if condition is not None:
assert isinstance(condition, (six.string_types, bool,
assert isinstance(condition, (str, bool,
function.Function))
self._hash ^= _hash_data(condition)
@ -255,7 +254,7 @@ class ResourceDefinition(object):
path(PROPERTIES))
metadata_deps = function.dependencies(self._metadata,
path(METADATA))
implicit_depends = six.moves.map(lambda rp: rp.name,
implicit_depends = map(lambda rp: rp.name,
itertools.chain(prop_deps,
metadata_deps))
@ -287,9 +286,7 @@ class ResourceDefinition(object):
if getattr(res, 'strict_dependency', True):
return res
return six.moves.filter(None,
six.moves.map(get_resource,
self.required_resource_names()))
return filter(None, map(get_resource, self.required_resource_names()))
def set_translation_rules(self, rules=None, client_resolve=True):
"""Helper method to update properties with translation rules."""
@ -434,12 +431,12 @@ def _hash_data(data):
if isinstance(data, function.Function):
data = copy.deepcopy(data)
if not isinstance(data, six.string_types):
if not isinstance(data, str):
if isinstance(data, collections.Sequence):
return hash(tuple(_hash_data(d) for d in data))
if isinstance(data, collections.Mapping):
item_hashes = (hash(k) ^ _hash_data(v) for k, v in data.items())
return six.moves.reduce(operator.xor, item_hashes, 0)
return functools.reduce(operator.xor, item_hashes, 0)
return hash(data)

View File

@ -11,6 +11,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import functools
import sys
import types
@ -18,7 +19,6 @@ import eventlet
from oslo_log import log as logging
from oslo_utils import encodeutils
from oslo_utils import excutils
import six
from heat.common.i18n import _
from heat.common import timeutils
@ -39,9 +39,9 @@ def task_description(task):
if name is not None and isinstance(task, (types.MethodType,
types.FunctionType)):
if getattr(task, '__self__', None) is not None:
return '%s from %s' % (six.text_type(name), task.__self__)
return '%s from %s' % (str(name), task.__self__)
else:
return six.text_type(name)
return str(name)
return encodeutils.safe_decode(repr(task))
@ -56,7 +56,7 @@ class Timeout(BaseException):
def __init__(self, task_runner, timeout):
"""Initialise with the TaskRunner and a timeout period in seconds."""
message = _('%s Timed out') % six.text_type(task_runner)
message = _('%s Timed out') % str(task_runner)
super(Timeout, self).__init__(message)
self._duration = timeutils.Duration(timeout)
@ -90,7 +90,6 @@ class TimedCancel(Timeout):
return False
@six.python_2_unicode_compatible
class ExceptionGroup(Exception):
"""Container for multiple exceptions.
@ -110,7 +109,6 @@ class ExceptionGroup(Exception):
return str([str(ex) for ex in self.exceptions])
@six.python_2_unicode_compatible
class TaskRunner(object):
"""Wrapper for a resumable task (co-routine)."""
@ -141,12 +139,12 @@ class TaskRunner(object):
def __str__(self):
"""Return a human-readable string representation of the task."""
text = 'Task %s' % self.name
return six.text_type(text)
return str(text)
def _sleep(self, wait_time):
"""Sleep for the specified number of seconds."""
if ENABLE_SLEEP and wait_time is not None:
LOG.debug('%s sleeping', six.text_type(self))
LOG.debug('%s sleeping', str(self))
eventlet.sleep(wait_time)
def __call__(self, wait_time=1, timeout=None, progress_callback=None):
@ -173,7 +171,7 @@ class TaskRunner(object):
assert self._runner is None, "Task already started"
assert not self._done, "Task already cancelled"
LOG.debug('%s starting', six.text_type(self))
LOG.debug('%s starting', str(self))
if timeout is not None:
self._timeout = Timeout(self, timeout)
@ -185,7 +183,7 @@ class TaskRunner(object):
else:
self._runner = False
self._done = True
LOG.debug('%s done (not resumable)', six.text_type(self))
LOG.debug('%s done (not resumable)', str(self))
def step(self):
"""Run another step of the task.
@ -205,15 +203,15 @@ class TaskRunner(object):
self._timeout.trigger(self._runner)
else:
LOG.debug('%s running', six.text_type(self))
LOG.debug('%s running', str(self))
try:
poll_period = next(self._runner)
except StopIteration:
self._done = True
LOG.debug('%s complete', six.text_type(self))
LOG.debug('%s complete', str(self))
else:
if isinstance(poll_period, six.integer_types):
if isinstance(poll_period, int):
self._poll_period = max(poll_period, 1)
else:
self._poll_period = 1
@ -269,7 +267,7 @@ class TaskRunner(object):
return
if not self.started() or grace_period is None:
LOG.debug('%s cancelled', six.text_type(self))
LOG.debug('%s cancelled', str(self))
self._done = True
if self.started():
self._runner.close()
@ -311,7 +309,7 @@ def wrappertask(task): # noqa: C901
self.cleanup()
"""
@six.wraps(task)
@functools.wraps(task)
def wrapper(*args, **kwargs):
parent = task(*args, **kwargs)
@ -399,7 +397,7 @@ class DependencyTaskGroup(object):
if name is None:
name = '(%s) %s' % (getattr(task, '__name__',
task_description(task)),
six.text_type(dependencies))
str(dependencies))
self.name = name
def __repr__(self):
@ -413,7 +411,7 @@ class DependencyTaskGroup(object):
thrown_exceptions = []
try:
while any(six.itervalues(self._runners)):
while any(self._runners.values()):
try:
for k, r in self._ready():
r.start()
@ -423,36 +421,31 @@ class DependencyTaskGroup(object):
if self._graph:
try:
yield
except Exception:
thrown_exceptions.append(sys.exc_info())
except Exception as err:
thrown_exceptions.append(err)
raise
for k, r in self._running():
if r.step():
del self._graph[k]
except Exception:
exc_info = None
try:
exc_info = sys.exc_info()
except Exception as err:
if self.aggregate_exceptions:
self._cancel_recursively(k, r)
else:
self.cancel_all(grace_period=self.error_wait_time)
raised_exceptions.append(exc_info)
finally:
del exc_info
raised_exceptions.append(err)
except: # noqa
with excutils.save_and_reraise_exception():
self.cancel_all()
if raised_exceptions:
if self.aggregate_exceptions:
raise ExceptionGroup(v for t, v, tb in raised_exceptions)
raise ExceptionGroup(err for err in raised_exceptions)
else:
if thrown_exceptions:
six.reraise(*thrown_exceptions[-1])
raise thrown_exceptions[-1]
else:
six.reraise(*raised_exceptions[0])
raise raised_exceptions[0]
finally:
del raised_exceptions
del thrown_exceptions
@ -464,7 +457,7 @@ class DependencyTaskGroup(object):
def get_grace_period(key):
return grace_period
for k, r in six.iteritems(self._runners):
for k, r in self._runners.items():
if not r.started() or r.done():
gp = None
else:
@ -472,13 +465,13 @@ class DependencyTaskGroup(object):
try:
r.cancel(grace_period=gp)
except Exception as ex:
LOG.debug('Exception cancelling task: %s', six.text_type(ex))
LOG.debug('Exception cancelling task: %s', str(ex))
def _cancel_recursively(self, key, runner):
try:
runner.cancel()
except Exception as ex:
LOG.debug('Exception cancelling task: %s', six.text_type(ex))
LOG.debug('Exception cancelling task: %s', str(ex))
node = self._graph[key]
for dependent_node in node.required_by():
node_runner = self._runners[dependent_node]
@ -508,4 +501,4 @@ class DependencyTaskGroup(object):
def running(k_r):
return k_r[0] in self._graph and k_r[1].started()
return six.moves.filter(running, six.iteritems(self._runners))
return filter(running, self._runners.items())

View File

@ -32,7 +32,6 @@ from oslo_service import threadgroup
from oslo_utils import timeutils
from oslo_utils import uuidutils
from osprofiler import profiler
import six
import webob
from heat.common import context
@ -251,7 +250,7 @@ class ThreadGroupManager(object):
for th in threads:
th.link(mark_done, th)
while not all(six.itervalues(links_done)):
while not all(links_done.values()):
eventlet.sleep()
def send(self, stack_id, message):
@ -695,7 +694,7 @@ class EngineService(service.ServiceBase):
except AssertionError:
raise
except Exception as ex:
raise exception.StackValidationFailed(message=six.text_type(ex))
raise exception.StackValidationFailed(message=str(ex))
max_resources = cfg.CONF.max_resources_per_stack
if max_resources == -1:
@ -834,7 +833,7 @@ class EngineService(service.ServiceBase):
stack.create_stack_user_project_id()
except exception.AuthorizationFailure as ex:
stack.state_set(stack.action, stack.FAILED,
six.text_type(ex))
str(ex))
def _stack_create(stack, msg_queue=None):
# Create/Adopt a stack, and create the periodic task if successful
@ -1288,7 +1287,7 @@ class EngineService(service.ServiceBase):
try:
self._validate_template(cnxt, tmpl)
except Exception as ex:
return {'Error': six.text_type(ex)}
return {'Error': str(ex)}
stack_name = 'dummy'
stack = parser.Stack(cnxt, stack_name, tmpl,
@ -1297,7 +1296,7 @@ class EngineService(service.ServiceBase):
stack.validate(ignorable_errors=ignorable_errors,
validate_res_tmpl_only=True)
except exception.StackValidationFailed as ex:
return {'Error': six.text_type(ex)}
return {'Error': str(ex)}
def filter_parameter(p):
return p.name not in stack.parameters.PSEUDO_PARAMETERS
@ -1642,7 +1641,7 @@ class EngineService(service.ServiceBase):
supported_funcs.update(tmpl_class.plugin.condition_functions)
functions = []
for func_name, func in six.iteritems(supported_funcs):
for func_name, func in supported_funcs.items():
if func is not hot_functions.Removed:
desc = pydoc.splitdoc(pydoc.getdoc(func))[0]
functions.append(
@ -1679,7 +1678,7 @@ class EngineService(service.ServiceBase):
raise exception.ResourceTypeUnavailable(
service_name=resource_class.default_client_name,
resource_type=type_name,
reason=six.text_type(exc))
reason=str(exc))
else:
if not svc_available:
raise exception.ResourceTypeUnavailable(
@ -2021,7 +2020,7 @@ class EngineService(service.ServiceBase):
stack = parser.Stack.load(cnxt, stack=s)
return [api.format_stack_resource(resource)
for name, resource in six.iteritems(stack)
for name, resource in stack.items()
if resource_name is None or name == resource_name]
@context.request_context
@ -2103,7 +2102,7 @@ class EngineService(service.ServiceBase):
if stack.status == stack.IN_PROGRESS:
LOG.info('%(stack)s is in state %(action)s_IN_PROGRESS, '
'snapshot is not permitted.', {
'stack': six.text_type(stack),
'stack': str(stack),
'action': stack.action})
raise exception.ActionInProgress(stack_name=stack.name,
action=stack.action)

View File

@ -11,14 +11,14 @@
# License for the specific language governing permissions and limitations
# under the License.
import itertools
import uuid
from oslo_log import log as logging
from oslo_serialization import jsonutils
from oslo_utils import timeutils
import requests
import six
from six.moves.urllib import parse as urlparse
from urllib import parse
from heat.common import crypt
from heat.common import exception
@ -88,8 +88,7 @@ class SoftwareConfigService(object):
cnxt, server_id)
# filter out the sds with None config
flt_sd = six.moves.filterfalse(lambda sd: sd.config is None,
all_sd)
flt_sd = itertools.filterfalse(lambda sd: sd.config is None, all_sd)
# sort the configs by config name, to give the list of metadata a
# deterministic and controllable order.
flt_sd_s = sorted(flt_sd, key=lambda sd: sd.config.name)
@ -153,7 +152,7 @@ class SoftwareConfigService(object):
raise exception.ConcurrentTransaction(action=action)
def _refresh_swift_software_deployment(self, cnxt, sd, deploy_signal_id):
container, object_name = urlparse.urlparse(
container, object_name = parse.urlparse(
deploy_signal_id).path.split('/')[-2:]
swift_plugin = cnxt.clients.client_plugin('swift')
swift = swift_plugin.client()
@ -281,7 +280,7 @@ class SoftwareConfigService(object):
'stack_user_project_id': stack_user_project_id,
'action': action,
'status': status,
'status_reason': six.text_type(status_reason)})
'status_reason': str(status_reason)})
self._push_metadata_software_deployments(
cnxt, server_id, stack_user_project_id)
return api.format_software_deployment(sd)
@ -332,7 +331,7 @@ class SoftwareConfigService(object):
if status == rpc_api.SOFTWARE_DEPLOYMENT_FAILED:
# build a status reason out of all of the values of outputs
# flagged as error_output
status_reasons = [' : '.join((k, six.text_type(status_reasons[k])))
status_reasons = [' : '.join((k, str(status_reasons[k])))
for k in status_reasons]
status_reason = ', '.join(status_reasons)
else:
@ -362,7 +361,7 @@ class SoftwareConfigService(object):
if status:
update_data['status'] = status
if status_reason:
update_data['status_reason'] = six.text_type(status_reason)
update_data['status_reason'] = str(status_reason)
if updated_at:
update_data['updated_at'] = timeutils.normalize_time(
timeutils.parse_isotime(updated_at))

View File

@ -17,7 +17,6 @@ APIs for dealing with input and output definitions for Software Configurations.
import collections
import copy
import six
from heat.common.i18n import _
@ -104,7 +103,7 @@ class IOConfig(object):
try:
self._props.validate()
except exception.StackValidationFailed as exc:
raise ValueError(six.text_type(exc))
raise ValueError(str(exc))
def name(self):
"""Return the name of the input or output."""
@ -181,7 +180,7 @@ def check_io_schema_list(io_configs):
"""
if (not isinstance(io_configs, collections.Sequence) or
isinstance(io_configs, collections.Mapping) or
isinstance(io_configs, six.string_types)):
isinstance(io_configs, str)):
raise TypeError('Software Config I/O Schema must be in a list')
if not all(isinstance(conf, collections.Mapping) for conf in io_configs):

View File

@ -25,7 +25,6 @@ from oslo_utils import excutils
from oslo_utils import timeutils as oslo_timeutils
from oslo_utils import uuidutils
from osprofiler import profiler
import six
from heat.common import context as common_context
from heat.common import environment_format as env_fmt
@ -75,20 +74,20 @@ class ForcedCancel(Exception):
def reset_state_on_error(func):
@six.wraps(func)
@functools.wraps(func)
def handle_exceptions(stack, *args, **kwargs):
errmsg = None
try:
return func(stack, *args, **kwargs)
except Exception as exc:
with excutils.save_and_reraise_exception():
errmsg = six.text_type(exc)
errmsg = str(exc)
LOG.error('Unexpected exception in %(func)s: %(msg)s',
{'func': func.__name__, 'msg': errmsg})
except BaseException as exc:
with excutils.save_and_reraise_exception():
exc_type = type(exc).__name__
errmsg = '%s(%s)' % (exc_type, six.text_type(exc))
errmsg = '%s(%s)' % (exc_type, str(exc))
LOG.info('Stopped due to %(msg)s in %(func)s',
{'func': func.__name__, 'msg': errmsg})
finally:
@ -101,7 +100,6 @@ def reset_state_on_error(func):
return handle_exceptions
@six.python_2_unicode_compatible
class Stack(collections.Mapping):
ACTIONS = (
@ -337,7 +335,7 @@ class Stack(collections.Mapping):
resources = self._db_resources_get()
stk_def_cache = {}
for rsc in six.itervalues(resources):
for rsc in resources.values():
loaded_res = self._resource_from_db_resource(rsc, stk_def_cache)
if loaded_res is not None:
yield loaded_res
@ -520,14 +518,14 @@ class Stack(collections.Mapping):
"""
if self._dependencies is None:
deps = dependencies.Dependencies()
for res in six.itervalues(self.resources):
for res in self.resources.values():
res.add_explicit_dependencies(deps)
self._dependencies = deps
return self._dependencies
def _add_implicit_dependencies(self, deps, ignore_errors=True):
"""Augment the given dependencies with implicit ones from plugins."""
for res in six.itervalues(self.resources):
for res in self.resources.values():
try:
res.add_dependencies(deps)
except Exception as exc:
@ -540,8 +538,8 @@ class Stack(collections.Mapping):
else:
LOG.warning('Ignoring error adding implicit '
'dependencies for %(res)s: %(err)s',
{'res': six.text_type(res),
'err': six.text_type(exc)})
{'res': str(res),
'err': str(exc)})
@classmethod
def load(cls, context, stack_id=None, stack=None, show_deleted=True,
@ -655,7 +653,7 @@ class Stack(collections.Mapping):
stack.update({
'action': self.action,
'status': self.status,
'status_reason': six.text_type(self.status_reason)})
'status_reason': str(self.status_reason)})
if only_db:
stack['parent_resource_name'] = self.parent_resource_name
@ -801,7 +799,7 @@ class Stack(collections.Mapping):
def __str__(self):
"""Return a human-readable string representation of the stack."""
text = 'Stack "%s" [%s]' % (self.name, self.id)
return six.text_type(text)
return str(text)
def resource_by_refid(self, refid):
"""Return the resource in this stack with the specified refid.
@ -809,7 +807,7 @@ class Stack(collections.Mapping):
:returns: resource in this stack with the specified refid, or None if
not found.
"""
for r in six.itervalues(self):
for r in self.values():
if r.state not in ((r.INIT, r.COMPLETE),
(r.CREATE, r.IN_PROGRESS),
(r.CREATE, r.COMPLETE),
@ -906,7 +904,7 @@ class Stack(collections.Mapping):
else:
iter_rsc = self._explicit_dependencies()
unique_defns = set(res.t for res in six.itervalues(resources))
unique_defns = set(res.t for res in resources.values())
unique_defn_names = set(defn.name for defn in unique_defns)
for res in iter_rsc:
@ -939,7 +937,7 @@ class Stack(collections.Mapping):
raise exception.StackValidationFailed(message=result)
eventlet.sleep(0)
for op_name, output in six.iteritems(self.outputs):
for op_name, output in self.outputs.items():
try:
output.validate()
except exception.StackValidationFailed as ex:
@ -958,7 +956,7 @@ class Stack(collections.Mapping):
during its lifecycle using the configured deferred authentication
method.
"""
return any(res.requires_deferred_auth for res in six.itervalues(self))
return any(res.requires_deferred_auth for res in self.values())
def _add_event(self, action, status, reason):
"""Add a state change event to the database."""
@ -1045,7 +1043,7 @@ class Stack(collections.Mapping):
if stack is not None:
values = {'action': self.action,
'status': self.status,
'status_reason': six.text_type(self.status_reason)}
'status_reason': str(self.status_reason)}
self._send_notification_and_add_event()
if self.convergence:
# do things differently for convergence
@ -1075,7 +1073,7 @@ class Stack(collections.Mapping):
if stack is not None:
values = {'action': self.action,
'status': self.status,
'status_reason': six.text_type(self.status_reason)}
'status_reason': str(self.status_reason)}
self._send_notification_and_add_event()
stack.persist_state_and_release_lock(self.context, self.id,
engine_id, values)
@ -1095,7 +1093,7 @@ class Stack(collections.Mapping):
def preview_resources(self):
"""Preview the stack with all of the resources."""
return [resource.preview()
for resource in six.itervalues(self.resources)]
for resource in self.resources.values()]
def get_nested_parameters(self, filter_func):
"""Return nested parameters schema, if any.
@ -1105,7 +1103,7 @@ class Stack(collections.Mapping):
stack.
"""
result = {}
for name, rsrc in six.iteritems(self.resources):
for name, rsrc in self.resources.items():
nested = rsrc.get_nested_parameters_stack()
if nested is None:
continue
@ -1182,7 +1180,7 @@ class Stack(collections.Mapping):
None, action)
except Exception as e:
self.state_set(action, self.FAILED, e.args[0] if e.args else
'Failed stack pre-ops: %s' % six.text_type(e))
'Failed stack pre-ops: %s' % str(e))
if callable(post_func):
post_func()
if notify is not None:
@ -1238,7 +1236,7 @@ class Stack(collections.Mapping):
# ExceptionGroup, but the raw exception.
# see scheduler.py line 395-399
stack_status = self.FAILED
reason = 'Resource %s failed: %s' % (action, six.text_type(ex))
reason = 'Resource %s failed: %s' % (action, str(ex))
if pre_completion_func:
pre_completion_func(self, action, stack_status, reason)
@ -1272,7 +1270,7 @@ class Stack(collections.Mapping):
return hasattr(res, 'handle_%s' % res.CHECK.lower())
all_supported = all(is_supported(res)
for res in six.itervalues(self.resources))
for res in self.resources.values())
if not all_supported:
msg = ". '%s' not fully supported (see resources)" % self.CHECK
@ -1316,7 +1314,7 @@ class Stack(collections.Mapping):
if not self.disable_rollback and self.state == (self.ADOPT,
self.FAILED):
# enter the same flow as abandon and just delete the stack
for res in six.itervalues(self.resources):
for res in self.resources.values():
res.abandon_in_progress = True
self.delete(action=self.ROLLBACK, abandon=True)
@ -1426,7 +1424,7 @@ class Stack(collections.Mapping):
try:
self.delete_all_snapshots()
except Exception as exc:
self.state_set(self.action, self.FAILED, six.text_type(exc))
self.state_set(self.action, self.FAILED, str(exc))
self.purge_db()
return
@ -1576,11 +1574,11 @@ class Stack(collections.Mapping):
return set(n.rsrc_id for n in dep_nodes if not n.is_update)
def reset_stack_and_resources_in_progress(self, reason):
for name, rsrc in six.iteritems(self.resources):
for name, rsrc in self.resources.items():
if rsrc.status == rsrc.IN_PROGRESS:
rsrc.state_set(rsrc.action,
rsrc.FAILED,
six.text_type(reason))
str(reason))
if self.action == self.UPDATE and not self.convergence:
backup_stack = self._backup_stack(False)
existing_params = environment.Environment({env_fmt.PARAMETERS:
@ -1591,7 +1589,7 @@ class Stack(collections.Mapping):
self._merge_user_param_template(existing_params, template,
bkp_stack_template)
self.state_set(self.action, self.FAILED, six.text_type(reason))
self.state_set(self.action, self.FAILED, str(reason))
@scheduler.wrappertask
def update_task(self, newstack, action=UPDATE,
@ -1609,7 +1607,7 @@ class Stack(collections.Mapping):
newstack, action)
except Exception as e:
self.state_set(action, self.FAILED, e.args[0] if e.args else
'Failed stack pre-ops: %s' % six.text_type(e))
'Failed stack pre-ops: %s' % str(e))
if notify is not None:
notify.signal()
return
@ -1756,7 +1754,7 @@ class Stack(collections.Mapping):
:returns: a boolean for require rollback flag.
"""
self.status_reason = six.text_type(exc)
self.status_reason = str(exc)
self.status = self.FAILED
if action != self.UPDATE:
return False
@ -1800,7 +1798,7 @@ class Stack(collections.Mapping):
def copy_data(source_res, destination_res):
if source_res.data():
for key, val in six.iteritems(source_res.data()):
for key, val in source_res.data().items():
destination_res.data_set(key, val)
for key, backup_res in stack.resources.items():
@ -1905,7 +1903,7 @@ class Stack(collections.Mapping):
except Exception as ex:
LOG.exception("Error deleting project")
stack_status = self.FAILED
reason = "Error deleting project: %s" % six.text_type(ex)
reason = "Error deleting project: %s" % str(ex)
return stack_status, reason
@ -1957,7 +1955,7 @@ class Stack(collections.Mapping):
except Exception as e:
self.state_set(action, self.FAILED,
e.args[0] if e.args else
'Failed stack pre-ops: %s' % six.text_type(e))
'Failed stack pre-ops: %s' % str(e))
return
action_task = scheduler.DependencyTaskGroup(self.dependencies,
@ -1967,7 +1965,7 @@ class Stack(collections.Mapping):
scheduler.TaskRunner(action_task)(timeout=self.timeout_secs())
except exception.ResourceFailure as ex:
stack_status = self.FAILED
reason = 'Resource %s failed: %s' % (action, six.text_type(ex))
reason = 'Resource %s failed: %s' % (action, str(ex))
except scheduler.Timeout:
stack_status = self.FAILED
reason = '%s timed out' % action.title()
@ -2092,7 +2090,7 @@ class Stack(collections.Mapping):
ss_defn = self.defn.clone_with_new_template(template,
self.identifier())
resources = self._resources_for_defn(ss_defn)
for name, rsrc in six.iteritems(resources):
for name, rsrc in resources.items():
data = snapshot.data['resources'].get(name)
if data:
scheduler.TaskRunner(rsrc.delete_snapshot, data)()
@ -2159,7 +2157,7 @@ class Stack(collections.Mapping):
'status': self.status,
'template': self.t.t,
'resources': dict((res.name, res.prepare_abandon())
for res in six.itervalues(self.resources)),
for res in self.resources.values()),
'project_id': self.tenant_id,
'stack_user_project_id': self.stack_user_project_id,
'tags': self.tags,

View File

@ -12,7 +12,6 @@
# under the License.
import itertools
import six
from heat.common import exception
from heat.engine import attributes
@ -232,7 +231,7 @@ class ResourceProxy(status.ResourceStatus):
the "show" attribute.
"""
all_attrs = self._res_data().attributes()
return dict((k, v) for k, v in six.iteritems(all_attrs)
return dict((k, v) for k, v in all_attrs.items()
if k != attributes.SHOW_ATTR)
@ -253,8 +252,8 @@ def update_resource_data(stack_definition, resource_name, resource_data):
res_defns = stack_definition._resource_defns or {}
op_defns = stack_definition._output_defns or {}
all_defns = itertools.chain(six.itervalues(res_defns),
six.itervalues(op_defns))
all_defns = itertools.chain(res_defns.values(),
op_defns.values())
for defn in all_defns:
if resource_name in defn.required_resource_names():
defn._all_dep_attrs = None

View File

@ -13,7 +13,6 @@
# limitations under the License.
import ast
import six
import tenacity
from oslo_log import log as logging
@ -84,7 +83,7 @@ def _str_unpack_tuple(s):
def _deserialize(d):
d2 = {}
for k, v in d.items():
if isinstance(k, six.string_types) and k.startswith(u'tuple:('):
if isinstance(k, str) and k.startswith(u'tuple:('):
k = _str_unpack_tuple(k)
if isinstance(v, dict):
v = _deserialize(v)

View File

@ -17,7 +17,6 @@ import copy
import functools
import hashlib
import six
from stevedore import extension
from heat.common import exception
@ -37,8 +36,8 @@ _template_classes = None
def get_version(template_data, available_versions):
version_keys = set(key for key, version in available_versions)
candidate_keys = set(k for k, v in six.iteritems(template_data) if
isinstance(v, six.string_types))
candidate_keys = set(k for k, v in template_data.items() if
isinstance(v, str))
keys_present = version_keys & candidate_keys
@ -61,7 +60,7 @@ def _get_template_extension_manager():
def raise_extension_exception(extmanager, ep, err):
raise TemplatePluginNotRegistered(name=ep.name, error=six.text_type(err))
raise TemplatePluginNotRegistered(name=ep.name, error=str(err))
class TemplatePluginNotRegistered(exception.HeatException):
@ -296,7 +295,7 @@ class Template(collections.Mapping):
sections (e.g. parameters are check by parameters schema class).
"""
t_digest = hashlib.sha256(
six.text_type(self.t).encode('utf-8')).hexdigest()
str(self.t).encode('utf-8')).hexdigest()
# TODO(kanagaraj-manickam) currently t_digest is stored in self. which
# is used to check whether already template is validated or not.
@ -315,7 +314,7 @@ class Template(collections.Mapping):
raise exception.InvalidTemplateSection(section=k)
# check resources
for res in six.itervalues(self[self.RESOURCES]):
for res in self[self.RESOURCES].values():
try:
if not res or not res.get('Type'):
message = _('Each Resource must contain '
@ -358,10 +357,10 @@ def parse(functions, stack, snippet, path='', template=None):
if isinstance(snippet, collections.Mapping):
def mkpath(key):
return '.'.join([path, six.text_type(key)])
return '.'.join([path, str(key)])
if len(snippet) == 1:
fn_name, args = next(six.iteritems(snippet))
fn_name, args = next(iter(snippet.items()))
Func = functions.get(fn_name)
if Func is not None:
try:
@ -376,11 +375,11 @@ def parse(functions, stack, snippet, path='', template=None):
except (ValueError, TypeError, KeyError) as e:
raise exception.StackValidationFailed(
path=path,
message=six.text_type(e))
message=str(e))
return dict((k, recurse(v, mkpath(k)))
for k, v in six.iteritems(snippet))
elif (not isinstance(snippet, six.string_types) and
for k, v in snippet.items())
elif (not isinstance(snippet, str) and
isinstance(snippet, collections.Iterable)):
def mkpath(idx):

View File

@ -15,8 +15,6 @@ import collections
import functools
import weakref
import six
from heat.common import exception
from heat.common.i18n import _
from heat.engine import conditions
@ -77,7 +75,7 @@ class CommonTemplate(template.Template):
yield ('resource_type',
self._parse_resource_field(self.RES_TYPE,
six.string_types, 'string',
str, 'string',
name, data, parse))
yield ('properties',
@ -96,11 +94,11 @@ class CommonTemplate(template.Template):
collections.Sequence,
'list or string',
name, data, no_parse)
if isinstance(depends, six.string_types):
if isinstance(depends, str):
depends = [depends]
elif depends:
for dep in depends:
if not isinstance(dep, six.string_types):
if not isinstance(dep, str):
msg = _('Resource %(name)s %(key)s '
'must be a list of strings') % {
'name': name, 'key': self.RES_DEPENDS_ON}
@ -109,7 +107,7 @@ class CommonTemplate(template.Template):
yield 'depends', depends
del_policy = self._parse_resource_field(self.RES_DELETION_POLICY,
(six.string_types,
(str,
function.Function),
'string',
name, data, parse)
@ -130,7 +128,7 @@ class CommonTemplate(template.Template):
yield ('description',
self._parse_resource_field(self.RES_DESCRIPTION,
six.string_types, 'string',
str, 'string',
name, data, no_parse))
def _get_condition_definitions(self):
@ -195,7 +193,7 @@ class CommonTemplate(template.Template):
enabled = conds.is_enabled(function.resolve(cond))
except ValueError as exc:
path = [self.OUTPUTS, key, self.OUTPUT_CONDITION]
message = six.text_type(exc)
message = str(exc)
raise exception.StackValidationFailed(path=path,
message=message)