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 14 of a serie of 28 patches

Change-Id: Iccb743056c631f2e0728013942d764cd8b1ecfe0
This commit is contained in:
Hervé Beraud 2019-11-20 19:37:26 +01:00
parent 5fa48d67a2
commit 9bc5c23885
10 changed files with 19 additions and 29 deletions

View File

@ -12,7 +12,6 @@
# under the License.
import collections
import six
import weakref
from heat.common import context
@ -40,7 +39,7 @@ class TemplateFiles(collections.Mapping):
self.files_id = files.files_id
self.files = files.files
return
if isinstance(files, six.integer_types):
if isinstance(files, int):
self.files_id = files
if self.files_id in _d:
self.files = _d[self.files_id]

View File

@ -14,7 +14,6 @@
import functools
from oslo_log import log as logging
import six
from heat.common import exception
from heat.common.i18n import _
@ -354,6 +353,6 @@ def resolve_and_find(value, cplugin, finder, entity=None,
except Exception as ex:
if ignore_resolve_error:
LOG.info("Ignoring error in RESOLVE translation: %s",
six.text_type(ex))
str(ex))
return value
raise

View File

@ -12,7 +12,6 @@
# under the License.
from oslo_log import log as logging
import six
from heat.common import exception
from heat.engine import dependencies
@ -145,7 +144,7 @@ class StackUpdate(object):
failure = exception.ResourceFailure(ex, existing_res,
existing_res.UPDATE)
existing_res._add_event(existing_res.UPDATE, existing_res.FAILED,
six.text_type(ex))
str(ex))
raise failure
def _update_resource_data(self, resource):
@ -255,7 +254,7 @@ class StackUpdate(object):
for e in existing_deps.graph(reverse=True).edges():
yield e
# Don't cleanup old resources until after they have been replaced
for name, res in six.iteritems(self.existing_stack):
for name, res in self.existing_stack.items():
if name in self.new_stack:
yield (res, self.new_stack[name])

View File

@ -15,12 +15,11 @@
from oslo_serialization import jsonutils as json
from oslo_versionedobjects import fields
import six
class Json(fields.FieldType):
def coerce(self, obj, attr, value):
if isinstance(value, six.string_types):
if isinstance(value, str):
loaded = json.loads(value)
return loaded
return value

View File

@ -21,7 +21,6 @@ from oslo_config import cfg
from oslo_log import log as logging
from oslo_versionedobjects import base
from oslo_versionedobjects import fields
import six
import tenacity
from heat.common import crypt
@ -57,7 +56,7 @@ class ResourceCache(object):
self.by_stack_id_name = collections.defaultdict(dict)
def set_by_stack_id(self, resources):
for res in six.itervalues(resources):
for res in resources.values():
self.by_stack_id_name[res.stack_id][res.name] = res
@ -190,7 +189,7 @@ class Resource(
resource_name,
cls._from_db_object(cls(context), context, resource_db)
)
for resource_name, resource_db in six.iteritems(resources_db)
for resource_name, resource_db in resources_db.items()
]
return dict(resources)
@ -246,7 +245,7 @@ class Resource(
resource_name,
cls._from_db_object(cls(context), context, resource_db)
)
for resource_name, resource_db in six.iteritems(resources_db)
for resource_name, resource_db in resources_db.items()
]
return dict(resources)
@ -259,7 +258,7 @@ class Resource(
resource_id,
cls._from_db_object(cls(context), context, resource_db)
)
for resource_id, resource_db in six.iteritems(resources_db)
for resource_id, resource_db in resources_db.items()
]
return dict(resources)
@ -280,7 +279,7 @@ class Resource(
context,
stack_id,
stack_id_only=True)
return {db_res.stack_id for db_res in six.itervalues(resources_db)}
return {db_res.stack_id for db_res in resources_db.values()}
@classmethod
def purge_deleted(cls, context, stack_id):

View File

@ -18,7 +18,6 @@
from oslo_log import log as logging
from oslo_versionedobjects import base
from oslo_versionedobjects import fields
import six
from heat.common import exception
from heat.common.i18n import _
@ -117,7 +116,7 @@ class Stack(
def get_by_name_and_owner_id(cls, context, stack_name, owner_id):
db_stack = db_api.stack_get_by_name_and_owner_id(
context,
six.text_type(stack_name),
str(stack_name),
owner_id
)
if not db_stack:
@ -127,7 +126,7 @@ class Stack(
@classmethod
def get_by_name(cls, context, stack_name):
db_stack = db_api.stack_get_by_name(context, six.text_type(stack_name))
db_stack = db_api.stack_get_by_name(context, str(stack_name))
if not db_stack:
return None
stack = cls._from_db_object(context, cls(context), db_stack)

View File

@ -18,7 +18,6 @@ from heat.common.i18n import _
from heat.engine import resource
from oslo_log import log as logging
from oslo_utils import timeutils
import six
LOG = logging.getLogger(__name__)
@ -48,19 +47,19 @@ class CooldownMixin(object):
# Note: this is for supporting old version cooldown checking
metadata.pop('scaling_in_progress', None)
if metadata and cooldown != 0:
last_adjust = next(six.iterkeys(metadata))
last_adjust = next(iter(metadata.keys()))
if not timeutils.is_older_than(last_adjust, cooldown):
self._log_and_raise_no_action(cooldown)
elif 'cooldown_end' in metadata:
cooldown_end = next(six.iterkeys(metadata['cooldown_end']))
cooldown_end = next(iter(metadata['cooldown_end'].keys()))
now = timeutils.utcnow().isoformat()
if now < cooldown_end:
self._log_and_raise_no_action(cooldown)
elif cooldown != 0:
# Note: this is also for supporting old version cooldown checking
last_adjust = next(six.iterkeys(metadata['cooldown']))
last_adjust = next(iter(metadata['cooldown'].keys()))
if not timeutils.is_older_than(last_adjust, cooldown):
self._log_and_raise_no_action(cooldown)
@ -91,7 +90,7 @@ class CooldownMixin(object):
seconds=cooldown)).isoformat()
if 'cooldown_end' in metadata:
cooldown_end = max(
next(six.iterkeys(metadata['cooldown_end'])),
next(iter(metadata['cooldown_end'].keys())),
cooldown_end)
metadata['cooldown_end'] = {cooldown_end: cooldown_reason}
metadata['scaling_in_progress'] = False

View File

@ -18,7 +18,6 @@ import mock
from oslo_config import cfg
from oslo_utils import importutils
import requests
import six
from heat.api.aws import ec2token
from heat.api.aws import exception
@ -520,7 +519,7 @@ class Ec2TokenTest(common.HeatTestCase):
ex = self.assertRaises(exception.HeatInternalFailureError,
ec2.__call__, dummy_req)
self.assertEqual('Service misconfigured', six.text_type(ex))
self.assertEqual('Service misconfigured', str(ex))
def test_call_ok_auth_uri_ec2authtoken(self):
dummy_url = 'http://123:5000/v2.0'

View File

@ -16,7 +16,6 @@ import os
import mock
from oslo_config import fixture as config_fixture
import six
from heat.api.aws import exception
import heat.api.cfn.v1.stacks as stacks
@ -1210,7 +1209,7 @@ class CfnStackControllerTest(common.HeatTestCase):
expected = {'DescribeStackEventsResponse':
{'DescribeStackEventsResult':
{'StackEvents':
[{'EventId': six.text_type(event_id),
[{'EventId': str(event_id),
'StackId': u'arn:openstack:heat::t:stacks/wordpress/6',
'ResourceStatus': u'TEST_IN_PROGRESS',
'ResourceType': u'AWS::EC2::Instance',

View File

@ -14,7 +14,6 @@
import json
import mock
import six
import webob.exc
import heat.api.middleware.fault as fault
@ -221,7 +220,7 @@ class ActionControllerTest(tools.ControllerTest, common.HeatTestCase):
stack_id=stack_identity.stack_id,
body=body)
self.assertEqual(403, resp.status_int)
self.assertIn('403 Forbidden', six.text_type(resp))
self.assertIn('403 Forbidden', str(resp))
def test_action_badaction_ise(self, mock_enforce):
stack_identity = identifier.HeatIdentifier(self.tenant,