From e6a6468eefd891839df2fd0c885182c275cdc1a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Beraud?= Date: Wed, 20 Nov 2019 19:37:26 +0100 Subject: [PATCH] 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 10 of a serie of 28 patches Change-Id: Ic745ceced9989497c489f3df3ee9ff84fe507b88 --- .../resources/openstack/heat/structured_config.py | 10 ++++------ heat/engine/resources/openstack/heat/swiftsignal.py | 5 ++--- heat/engine/resources/openstack/heat/test_resource.py | 5 ++--- heat/engine/resources/openstack/heat/wait_condition.py | 3 +-- heat/engine/resources/openstack/keystone/region.py | 2 +- heat/engine/resources/openstack/magnum/bay.py | 4 +--- heat/engine/resources/openstack/magnum/cluster.py | 4 +--- .../resources/openstack/magnum/cluster_template.py | 4 +--- heat/engine/resources/openstack/manila/share.py | 5 ++--- .../resources/openstack/mistral/external_resource.py | 3 +-- 10 files changed, 16 insertions(+), 29 deletions(-) diff --git a/heat/engine/resources/openstack/heat/structured_config.py b/heat/engine/resources/openstack/heat/structured_config.py index 836e2ef92a..a23bfcedad 100644 --- a/heat/engine/resources/openstack/heat/structured_config.py +++ b/heat/engine/resources/openstack/heat/structured_config.py @@ -15,8 +15,6 @@ import collections import copy import functools -import six - from heat.common import exception from heat.common.i18n import _ from heat.engine import constraints @@ -150,8 +148,8 @@ class StructuredDeployment(sd.SoftwareDeployment): def get_input_key_arg(snippet, input_key): if len(snippet) != 1: return None - fn_name, fn_arg = next(six.iteritems(snippet)) - if (fn_name == input_key and isinstance(fn_arg, six.string_types)): + fn_name, fn_arg = next(iter(snippet.items())) + if (fn_name == input_key and isinstance(fn_arg, str)): return fn_arg @staticmethod @@ -175,8 +173,8 @@ class StructuredDeployment(sd.SoftwareDeployment): check_input_val ) - return dict((k, parse(v)) for k, v in six.iteritems(snippet)) - elif (not isinstance(snippet, six.string_types) and + return dict((k, parse(v)) for k, v in snippet.items()) + elif (not isinstance(snippet, str) and isinstance(snippet, collections.Iterable)): return [parse(v) for v in snippet] else: diff --git a/heat/engine/resources/openstack/heat/swiftsignal.py b/heat/engine/resources/openstack/heat/swiftsignal.py index d8c33296b1..dc78b93102 100644 --- a/heat/engine/resources/openstack/heat/swiftsignal.py +++ b/heat/engine/resources/openstack/heat/swiftsignal.py @@ -14,8 +14,7 @@ from oslo_log import log as logging from oslo_serialization import jsonutils from oslo_utils import timeutils -import six -from six.moves.urllib import parse +from urllib import parse from heat.common import exception from heat.common.i18n import _ @@ -344,7 +343,7 @@ class SwiftSignal(resource.Resource): def _resolve_attribute(self, key): if key == self.DATA: - return six.text_type(jsonutils.dumps(self.get_data())) + return str(jsonutils.dumps(self.get_data())) def resource_mapping(): diff --git a/heat/engine/resources/openstack/heat/test_resource.py b/heat/engine/resources/openstack/heat/test_resource.py index 3af8b46b07..dc8b6234b8 100644 --- a/heat/engine/resources/openstack/heat/test_resource.py +++ b/heat/engine/resources/openstack/heat/test_resource.py @@ -14,7 +14,6 @@ import datetime import eventlet from oslo_utils import timeutils -import six from heat.common.i18n import _ from heat.engine import attributes @@ -218,12 +217,12 @@ class TestResource(resource.Resource): obj.get(entity_id) except Exception as exc: LOG.debug('%s.%s(%s) %s' % (client_name, self.entity, - entity_id, six.text_type(exc))) + entity_id, str(exc))) else: # just sleep some more eventlet.sleep(1) - if isinstance(started_at, six.string_types): + if isinstance(started_at, str): started_at = timeutils.parse_isotime(started_at) started_at = timeutils.normalize_time(started_at) diff --git a/heat/engine/resources/openstack/heat/wait_condition.py b/heat/engine/resources/openstack/heat/wait_condition.py index bea9c38d88..db8ff844e1 100644 --- a/heat/engine/resources/openstack/heat/wait_condition.py +++ b/heat/engine/resources/openstack/heat/wait_condition.py @@ -14,7 +14,6 @@ from oslo_log import log as logging from oslo_serialization import jsonutils from oslo_utils import timeutils -import six from heat.common.i18n import _ from heat.engine import attributes @@ -158,7 +157,7 @@ class HeatWaitCondition(resource.Resource): 'key': key, 'res': res}) - return six.text_type(jsonutils.dumps(res)) + return str(jsonutils.dumps(res)) def resource_mapping(): diff --git a/heat/engine/resources/openstack/keystone/region.py b/heat/engine/resources/openstack/keystone/region.py index b52cf009dc..63ed6b3e66 100644 --- a/heat/engine/resources/openstack/keystone/region.py +++ b/heat/engine/resources/openstack/keystone/region.py @@ -11,7 +11,7 @@ # License for the specific language governing permissions and limitations # under the License. -from six.moves.urllib import parse +from urllib import parse from heat.common.i18n import _ from heat.engine import constraints diff --git a/heat/engine/resources/openstack/magnum/bay.py b/heat/engine/resources/openstack/magnum/bay.py index fd2ed643c0..1837dd5525 100644 --- a/heat/engine/resources/openstack/magnum/bay.py +++ b/heat/engine/resources/openstack/magnum/bay.py @@ -11,8 +11,6 @@ # License for the specific language governing permissions and limitations # under the License. -import six - from heat.common import exception from heat.common.i18n import _ from heat.engine import constraints @@ -129,7 +127,7 @@ class Bay(resource.Resource): def handle_update(self, json_snippet, tmpl_diff, prop_diff): if prop_diff: patch = [{'op': 'replace', 'path': '/' + k, 'value': v} - for k, v in six.iteritems(prop_diff)] + for k, v in prop_diff.items()] self.client().bays.update(self.resource_id, patch) return self.resource_id diff --git a/heat/engine/resources/openstack/magnum/cluster.py b/heat/engine/resources/openstack/magnum/cluster.py index 58e465d3e9..ac2ae5dc94 100644 --- a/heat/engine/resources/openstack/magnum/cluster.py +++ b/heat/engine/resources/openstack/magnum/cluster.py @@ -11,8 +11,6 @@ # License for the specific language governing permissions and limitations # under the License. -import six - from heat.common import exception from heat.common.i18n import _ from heat.engine import attributes @@ -218,7 +216,7 @@ class Cluster(resource.Resource): def handle_update(self, json_snippet, tmpl_diff, prop_diff): if prop_diff: patch = [{'op': 'replace', 'path': '/' + k, 'value': v} - for k, v in six.iteritems(prop_diff)] + for k, v in prop_diff.items()] self.client().clusters.update(self.resource_id, patch) return self.resource_id diff --git a/heat/engine/resources/openstack/magnum/cluster_template.py b/heat/engine/resources/openstack/magnum/cluster_template.py index d394492b3b..d51162e546 100644 --- a/heat/engine/resources/openstack/magnum/cluster_template.py +++ b/heat/engine/resources/openstack/magnum/cluster_template.py @@ -11,8 +11,6 @@ # License for the specific language governing permissions and limitations # under the License. -import six - from heat.common import exception from heat.common.i18n import _ from heat.engine import constraints @@ -290,7 +288,7 @@ class ClusterTemplate(resource.Resource): def handle_update(self, json_snippet, tmpl_diff, prop_diff): if prop_diff: patch = [{'op': 'replace', 'path': '/' + k, 'value': v} - for k, v in six.iteritems(prop_diff)] + for k, v in prop_diff.items()] self.client().cluster_templates.update(self.resource_id, patch) return self.resource_id diff --git a/heat/engine/resources/openstack/manila/share.py b/heat/engine/resources/openstack/manila/share.py index ce89f78632..17b164a7c4 100644 --- a/heat/engine/resources/openstack/manila/share.py +++ b/heat/engine/resources/openstack/manila/share.py @@ -13,7 +13,6 @@ from oslo_log import log as logging from oslo_utils import encodeutils -import six from heat.common import exception from heat.common.i18n import _ @@ -197,7 +196,7 @@ class ManilaShare(resource.Resource): if self.resource_id is None: return share = self._request_share() - return six.text_type(getattr(share, name)) + return str(getattr(share, name)) def handle_create(self): # Request IDs of entities from manila @@ -345,7 +344,7 @@ class ManilaShare(resource.Resource): result[self.ACCESS_RULES] = [] for rule in rules: result[self.ACCESS_RULES].append( - {(k, v) for (k, v) in six.iteritems(rule) + {(k, v) for (k, v) in rule.items() if k in self._ACCESS_RULE_PROPERTIES}) return result diff --git a/heat/engine/resources/openstack/mistral/external_resource.py b/heat/engine/resources/openstack/mistral/external_resource.py index 9e8f1b70e3..a38e35b4ed 100644 --- a/heat/engine/resources/openstack/mistral/external_resource.py +++ b/heat/engine/resources/openstack/mistral/external_resource.py @@ -13,7 +13,6 @@ from oslo_log import log as logging from oslo_serialization import jsonutils -import six from heat.common import exception from heat.common.i18n import _ @@ -212,7 +211,7 @@ class MistralExternalResource(resource.Resource): LOG.debug('ExternalResource id set to %(rid)s from Mistral ' 'execution %(eid)s output' % {'eid': execution_id, 'rid': rsrc_id}) - self.resource_id_set(six.text_type(rsrc_id)[:255]) + self.resource_id_set(str(rsrc_id)[:255]) return success def _resolve_attribute(self, name):