From 3e28c8e76b348a97b66d90ddb04cfda1521fb2ea 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 9 of a serie of 28 patches Change-Id: I89ec972a566ce211b5de4b02ca4d9b1b6e178525 --- .../resources/openstack/designate/zone.py | 3 +-- .../openstack/heat/autoscaling_group.py | 6 ++---- .../openstack/heat/instance_group.py | 3 +-- .../resources/openstack/heat/none_resource.py | 3 +-- .../resources/openstack/heat/random_string.py | 4 +--- .../resources/openstack/heat/remote_stack.py | 7 +++---- .../openstack/heat/resource_chain.py | 7 +++---- .../openstack/heat/resource_group.py | 21 +++++++++---------- .../openstack/heat/scaling_policy.py | 5 ++--- .../openstack/heat/software_deployment.py | 5 ++--- 10 files changed, 26 insertions(+), 38 deletions(-) diff --git a/heat/engine/resources/openstack/designate/zone.py b/heat/engine/resources/openstack/designate/zone.py index 0268b69a2c..57b65548d7 100644 --- a/heat/engine/resources/openstack/designate/zone.py +++ b/heat/engine/resources/openstack/designate/zone.py @@ -10,7 +10,6 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. -import six from heat.common import exception from heat.common.i18n import _ @@ -122,7 +121,7 @@ class DesignateZone(resource.Resource): raise_invalid_exception(self.SECONDARY, self.MASTERS) def handle_create(self): - args = dict((k, v) for k, v in six.iteritems(self.properties) if v) + args = dict((k, v) for k, v in self.properties.items() if v) args['type_'] = args.pop(self.TYPE) zone = self.client().zones.create(**args) diff --git a/heat/engine/resources/openstack/heat/autoscaling_group.py b/heat/engine/resources/openstack/heat/autoscaling_group.py index be579a2520..a232ee88da 100644 --- a/heat/engine/resources/openstack/heat/autoscaling_group.py +++ b/heat/engine/resources/openstack/heat/autoscaling_group.py @@ -11,8 +11,6 @@ # License for the specific language governing permissions and limitations # under the License. -import six - from oslo_log import log as logging from heat.common import exception @@ -212,7 +210,7 @@ class AutoScalingResourceGroup(aws_asg.AutoScalingGroup): return resource.Resource.get_reference_id(self) def _attribute_output_name(self, *attr_path): - return ', '.join(six.text_type(a) for a in attr_path) + return ', '.join(str(a) for a in attr_path) def get_attribute(self, key, *path): # noqa: C901 if key == self.CURRENT_SIZE: @@ -284,7 +282,7 @@ class AutoScalingResourceGroup(aws_asg.AutoScalingGroup): def _nested_output_defns(self, resource_names, get_attr_fn, get_res_fn): for attr in self.referenced_attrs(): - if isinstance(attr, six.string_types): + if isinstance(attr, str): key, path = attr, [] else: key, path = attr[0], list(attr[1:]) diff --git a/heat/engine/resources/openstack/heat/instance_group.py b/heat/engine/resources/openstack/heat/instance_group.py index 103737d440..0b5fdeaeaa 100644 --- a/heat/engine/resources/openstack/heat/instance_group.py +++ b/heat/engine/resources/openstack/heat/instance_group.py @@ -12,7 +12,6 @@ # under the License. import functools -import six from oslo_log import log as logging @@ -460,7 +459,7 @@ class InstanceGroup(stack_resource.StackResource): def _nested_output_defns(self, resource_names, get_attr_fn, get_res_fn): for attr in self.referenced_attrs(): - if isinstance(attr, six.string_types): + if isinstance(attr, str): key = attr else: key = attr[0] diff --git a/heat/engine/resources/openstack/heat/none_resource.py b/heat/engine/resources/openstack/heat/none_resource.py index 8932344eb7..e0e871a371 100644 --- a/heat/engine/resources/openstack/heat/none_resource.py +++ b/heat/engine/resources/openstack/heat/none_resource.py @@ -11,7 +11,6 @@ # License for the specific language governing permissions and limitations # under the License. -import six import uuid from heat.engine import properties @@ -47,7 +46,7 @@ class NoneResource(resource.Resource): self.translate_properties(self.properties, client_resolve) def handle_create(self): - self.resource_id_set(six.text_type(uuid.uuid4())) + self.resource_id_set(str(uuid.uuid4())) # set is_placeholder flag when resource trying to replace original # resource with a placeholder resource. self.data_set(self.IS_PLACEHOLDER, 'True') diff --git a/heat/engine/resources/openstack/heat/random_string.py b/heat/engine/resources/openstack/heat/random_string.py index 9c457a936d..4b03d98547 100644 --- a/heat/engine/resources/openstack/heat/random_string.py +++ b/heat/engine/resources/openstack/heat/random_string.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.common import password_gen @@ -235,7 +233,7 @@ class RandomString(resource.Resource): if self.resource_id is not None: return self.data().get('value') else: - return six.text_type(self.name) + return str(self.name) def resource_mapping(): diff --git a/heat/engine/resources/openstack/heat/remote_stack.py b/heat/engine/resources/openstack/heat/remote_stack.py index 189133a433..4574de8341 100644 --- a/heat/engine/resources/openstack/heat/remote_stack.py +++ b/heat/engine/resources/openstack/heat/remote_stack.py @@ -13,7 +13,6 @@ from oslo_log import log as logging from oslo_serialization import jsonutils -import six import tempfile from heat.common import auth_plugin @@ -49,7 +48,7 @@ class TempCACertFile(object): try: self._cacert_temp_file = tempfile.NamedTemporaryFile() self._cacert_temp_file.write( - six.text_type(self._cacert).encode('utf-8')) + str(self._cacert).encode('utf-8')) # Add seek func to make sure the writen context will flush to # tempfile with python 2.7. we can use flush() for python 2.7 # but not 3.5. @@ -266,7 +265,7 @@ class RemoteStack(resource.Resource): location = "remote cloud" else: location = 'region "%s"' % self._region_name - exc_info = dict(location=location, exc=six.text_type(ex)) + exc_info = dict(location=location, exc=str(ex)) msg = _('Cannot establish connection to Heat endpoint at ' '%(location)s due to "%(exc)s"') % exc_info raise exception.StackValidationFailed(message=msg) @@ -287,7 +286,7 @@ class RemoteStack(resource.Resource): location = "remote cloud" else: location = 'region "%s"' % self._region_name - exc_info = dict(location=location, exc=six.text_type(ex)) + exc_info = dict(location=location, exc=str(ex)) msg = _('Failed validating stack template using Heat endpoint at ' '%(location)s due to "%(exc)s"') % exc_info raise exception.StackValidationFailed(message=msg) diff --git a/heat/engine/resources/openstack/heat/resource_chain.py b/heat/engine/resources/openstack/heat/resource_chain.py index 9cadc78ce6..ff58711f1d 100644 --- a/heat/engine/resources/openstack/heat/resource_chain.py +++ b/heat/engine/resources/openstack/heat/resource_chain.py @@ -12,7 +12,6 @@ # under the License. import functools -import six from oslo_log import log as logging @@ -155,7 +154,7 @@ class ResourceChain(stack_resource.StackResource): return {} def _attribute_output_name(self, *attr_path): - return ', '.join(six.text_type(a) for a in attr_path) + return ', '.join(str(a) for a in attr_path) def get_attribute(self, key, *path): if key == self.ATTR_ATTRIBUTES and not path: @@ -198,7 +197,7 @@ class ResourceChain(stack_resource.StackResource): def _nested_output_defns(self, resource_names, get_attr_fn, get_res_fn): for attr in self.referenced_attrs(): - if isinstance(attr, six.string_types): + if isinstance(attr, str): key, path = attr, [] else: key, path = attr[0], list(attr[1:]) @@ -227,7 +226,7 @@ class ResourceChain(stack_resource.StackResource): @staticmethod def _resource_names(resource_types): """Returns a list of unique resource names to create.""" - return [six.text_type(i) for i, t in enumerate(resource_types)] + return [str(i) for i, t in enumerate(resource_types)] def _build_resource_definition(self, resource_name, resource_type, depends_on=None): diff --git a/heat/engine/resources/openstack/heat/resource_group.py b/heat/engine/resources/openstack/heat/resource_group.py index c43746d2c9..dbed1d4e2e 100644 --- a/heat/engine/resources/openstack/heat/resource_group.py +++ b/heat/engine/resources/openstack/heat/resource_group.py @@ -15,7 +15,6 @@ import collections import copy import functools import itertools -import six from oslo_log import log as logging @@ -306,7 +305,7 @@ class ResourceGroup(stack_resource.StackResource): first_name = next(self._resource_names()) test_tmpl = self._assemble_nested([first_name], include_all=True) - res_def = next(six.itervalues(test_tmpl.resource_definitions(None))) + res_def = next(iter(test_tmpl.resource_definitions(None).values())) # make sure we can resolve the nested resource type self.stack.env.get_class_to_instantiate(res_def.resource_type) @@ -339,12 +338,12 @@ class ResourceGroup(stack_resource.StackResource): if self.REMOVAL_RSRC_LIST in r: # Tolerate string or int list values for n in r[self.REMOVAL_RSRC_LIST]: - str_n = six.text_type(n) + str_n = str(n) if (str_n in current_blacklist or self.resource_id is None or str_n in insp.member_names(include_failed=True)): yield str_n - elif isinstance(n, six.string_types): + elif isinstance(n, str): try: refids = self.get_output(self.REFS_MAP) except (exception.NotFound, @@ -399,9 +398,9 @@ class ResourceGroup(stack_resource.StackResource): def is_blacklisted(name): return name in name_blacklist - candidates = six.moves.map(six.text_type, itertools.count()) + candidates = map(str, itertools.count()) - return itertools.islice(six.moves.filterfalse(is_blacklisted, + return itertools.islice(itertools.filterfalse(is_blacklisted, candidates), size) @@ -488,7 +487,7 @@ class ResourceGroup(stack_resource.StackResource): def _attribute_output_name(self, *attr_path): if attr_path[0] == self.REFS: return self.REFS - return ', '.join(six.text_type(a) for a in attr_path) + return ', '.join(str(a) for a in attr_path) def get_attribute(self, key, *path): if key == self.REMOVED_RSRC_LIST: @@ -546,7 +545,7 @@ class ResourceGroup(stack_resource.StackResource): def _nested_output_defns(self, resource_names, get_attr_fn, get_res_fn): for attr in self.referenced_attrs(): - if isinstance(attr, six.string_types): + if isinstance(attr, str): key, path = attr, [] else: key, path = attr[0], list(attr[1:]) @@ -611,7 +610,7 @@ class ResourceGroup(stack_resource.StackResource): if isinstance(snippet, collections.Mapping): return dict((k, ignore_param_resolve(v)) for k, v in snippet.items()) - elif (not isinstance(snippet, six.string_types) and + elif (not isinstance(snippet, str) and isinstance(snippet, collections.Iterable)): return [ignore_param_resolve(v) for v in snippet] @@ -639,7 +638,7 @@ class ResourceGroup(stack_resource.StackResource): def recurse(x): return self._handle_repl_val(res_name, x) - if isinstance(val, six.string_types): + if isinstance(val, str): return val.replace(repl_var, res_name) elif isinstance(val, collections.Mapping): return {k: recurse(v) for k, v in val.items()} @@ -706,7 +705,7 @@ class ResourceGroup(stack_resource.StackResource): old_resources = sorted(valid_resources, key=replace_priority) existing_names = set(n for n, d in valid_resources) - new_names = six.moves.filterfalse(lambda n: n in existing_names, + new_names = itertools.filterfalse(lambda n: n in existing_names, names) res_def = self.get_resource_def(include_all) definitions = scl_template.member_definitions( diff --git a/heat/engine/resources/openstack/heat/scaling_policy.py b/heat/engine/resources/openstack/heat/scaling_policy.py index c0afc212e4..cc06227104 100644 --- a/heat/engine/resources/openstack/heat/scaling_policy.py +++ b/heat/engine/resources/openstack/heat/scaling_policy.py @@ -12,7 +12,6 @@ # under the License. from oslo_log import log as logging -import six from heat.common import exception from heat.common.i18n import _ @@ -186,9 +185,9 @@ class AutoScalingPolicy(signal_responder.SignalResponder): if self.resource_id is None: return if name == self.ALARM_URL: - return six.text_type(self._get_ec2_signed_url()) + return str(self._get_ec2_signed_url()) elif name == self.SIGNAL_URL: - return six.text_type(self._get_heat_signal_url()) + return str(self._get_heat_signal_url()) def resource_mapping(): diff --git a/heat/engine/resources/openstack/heat/software_deployment.py b/heat/engine/resources/openstack/heat/software_deployment.py index 09c6627129..39a6d0675e 100644 --- a/heat/engine/resources/openstack/heat/software_deployment.py +++ b/heat/engine/resources/openstack/heat/software_deployment.py @@ -12,8 +12,7 @@ # under the License. import copy -import six -from six import itertools +import itertools import uuid from oslo_config import cfg @@ -749,7 +748,7 @@ class SoftwareDeploymentGroup(resource_group.ResourceGroup): def _nested_output_defns(self, resource_names, get_attr_fn, get_res_fn): for attr in self.referenced_attrs(): - key = attr if isinstance(attr, six.string_types) else attr[0] + key = attr if isinstance(attr, str) else attr[0] n_attr = self._member_attribute_name(key) output_name = self._attribute_output_name(self.ATTR_ATTRIBUTES, n_attr)