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

Change-Id: If54d634abfd345c1e672d31cb11de14260b34cc0
This commit is contained in:
Hervé Beraud 2019-11-20 19:37:26 +01:00
parent 0de03fcdd3
commit 1c318a167c
10 changed files with 21 additions and 37 deletions

View File

@ -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 properties
@ -102,7 +100,7 @@ class VPCGatewayAttachment(resource.Resource):
default_client_name = 'neutron'
def _vpc_route_tables(self, ignore_errors=False):
for res in six.itervalues(self.stack):
for res in self.stack.values():
if res.has_interface('AWS::EC2::RouteTable'):
try:
vpc_id = self.properties[self.VPC_ID]

View File

@ -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 properties
@ -169,12 +167,12 @@ class NeutronSecurityGroup(object):
rule['direction'] = 'egress'
for rule in updated[self.sg.SECURITY_GROUP_INGRESS]:
rule['direction'] = 'ingress'
updated_rules = list(six.itervalues(updated))
updated_rules = list(updated.values())
updated_all = updated_rules[0] + updated_rules[1]
ids_to_delete = [id for id, rule in existing.items()
if rule not in updated_all]
rules_to_create = [rule for rule in updated_all
if rule not in six.itervalues(existing)]
if rule not in existing.values()]
return ids_to_delete, rules_to_create

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.common.i18n import _
@ -80,7 +79,7 @@ class User(stack_user.StackUser):
# If a non-string (e.g embedded IAM dict policy) is passed, we
# ignore the policy (don't reject it because we previously ignored
# and we don't want to break templates which previously worked
if not isinstance(policy, six.string_types):
if not isinstance(policy, str):
LOG.debug("Ignoring policy %s, must be string "
"resource name", policy)
continue
@ -118,7 +117,7 @@ class User(stack_user.StackUser):
def access_allowed(self, resource_name):
policies = (self.properties[self.POLICIES] or [])
for policy in policies:
if not isinstance(policy, six.string_types):
if not isinstance(policy, str):
LOG.debug("Ignoring policy %s, must be string "
"resource name", policy)
continue

View File

@ -14,7 +14,6 @@ import os
from oslo_config import cfg
from oslo_log import log as logging
import six
from heat.common import exception
from heat.common.i18n import _
@ -623,7 +622,7 @@ backend servers
'Interval must be larger than Timeout'}
def get_reference_id(self):
return six.text_type(self.name)
return str(self.name)
def _resolve_attribute(self, name):
"""We don't really support any of these yet."""

View File

@ -10,8 +10,7 @@
# 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 six.moves.urllib import parse as urlparse
from urllib import parse
from heat.common import exception
from heat.common.i18n import _
@ -165,11 +164,11 @@ class S3Bucket(resource.Resource):
self.client_plugin().ignore_not_found(ex)
def get_reference_id(self):
return six.text_type(self.resource_id)
return str(self.resource_id)
def _resolve_attribute(self, name):
url = self.client().get_auth()[0]
parsed = list(urlparse.urlparse(url))
parsed = list(parse.urlparse(url))
if name == self.DOMAIN_NAME:
return parsed[1].split(':')[0]
elif name == self.WEBSITE_URL:

View File

@ -11,8 +11,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import six
from heat.common.i18n import _
from heat.engine import constraints
from heat.engine import properties
@ -157,7 +155,7 @@ class AodhAlarm(alarm_base.BaseAlarm):
# make sure the matching_metadata appears in the query like this:
# {field: metadata.$prefix.x, ...}
for m_k, m_v in six.iteritems(mmd):
for m_k, m_v in mmd.items():
key = 'metadata.%s' % prefix
if m_k.startswith('metadata.'):
m_k = m_k[len('metadata.'):]
@ -168,7 +166,7 @@ class AodhAlarm(alarm_base.BaseAlarm):
# NOTE(prazumovsky): type of query value must be a string, but
# matching_metadata value type can not be a string, so we
# must convert value to a string type.
query.append(dict(field=key, op='eq', value=six.text_type(m_v)))
query.append(dict(field=key, op='eq', value=str(m_v)))
if self.MATCHING_METADATA in kwargs:
del kwargs[self.MATCHING_METADATA]
if self.QUERY in kwargs:

View File

@ -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
@ -192,12 +190,12 @@ class CertificateContainer(GenericContainer):
}
def create_container(self):
info = dict((k, v) for k, v in six.iteritems(self.properties)
info = dict((k, v) for k, v in self.properties.items()
if v is not None)
return self.client_plugin().create_certificate(**info)
def get_refs(self):
return [v for k, v in six.iteritems(self.properties)
return [v for k, v in self.properties.items()
if (k != self.NAME and v is not None)]
@ -239,12 +237,12 @@ class RSAContainer(GenericContainer):
}
def create_container(self):
info = dict((k, v) for k, v in six.iteritems(self.properties)
info = dict((k, v) for k, v in self.properties.items()
if v is not None)
return self.client_plugin().create_rsa(**info)
def get_refs(self):
return [v for k, v in six.iteritems(self.properties)
return [v for k, v in self.properties.items()
if (k != self.NAME and v is not None)]

View File

@ -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
@ -228,8 +226,8 @@ class Order(resource.Resource):
raise exception.ResourcePropertyDependency(
prop1=self.PROFILE, prop2=self.CA_ID
)
declared_props = sorted([k for k, v in six.iteritems(
self.properties) if k != self.TYPE and v is not None])
declared_props = sorted([k for k, v in self.properties.items()
if k != self.TYPE and v is not None])
allowed_props = sorted(self.ALLOWED_PROPERTIES_FOR_TYPE[
self.properties[self.TYPE]])
diff = sorted(set(declared_props) - set(allowed_props))

View File

@ -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 _
@ -310,7 +309,7 @@ class CinderVolume(vb.BaseVolume, sh.SchedulerHintsMixin):
cinder = self.client()
vol = cinder.volumes.get(self.resource_id)
if name == self.METADATA_ATTR:
return six.text_type(jsonutils.dumps(vol.metadata))
return str(jsonutils.dumps(vol.metadata))
elif name == self.METADATA_VALUES_ATTR:
return vol.metadata
if name == self.DISPLAY_NAME_ATTR:
@ -319,7 +318,7 @@ class CinderVolume(vb.BaseVolume, sh.SchedulerHintsMixin):
return vol.description
elif name == self.ATTACHMENTS_LIST:
return vol.attachments
return six.text_type(getattr(vol, name))
return str(getattr(vol, name))
def check_create_complete(self, vol_id):
complete = super(CinderVolume, self).check_create_complete(vol_id)
@ -355,7 +354,7 @@ class CinderVolume(vb.BaseVolume, sh.SchedulerHintsMixin):
if self.client_plugin().is_client_exception(ex):
raise exception.Error(_(
"Failed to extend volume %(vol)s - %(err)s") % {
'vol': self.resource_id, 'err': six.text_type(ex)})
'vol': self.resource_id, 'err': str(ex)})
else:
raise
return True

View File

@ -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
@ -99,7 +97,7 @@ class DesignateRecordSet(resource.Resource):
entity = 'recordsets'
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)
if not args.get(self.NAME):
args[self.NAME] = self.physical_resource_name()