Remove usage of six.text_type and six.string_type

With python 3.x, six.text_type and six.string_type
are just str.

Also removed a six.integer_type since it was the only
one left in a file.

Another step in removing all of six usage from neutron.

Change-Id: I5208dc41bff1983ecd323286f427296b722da62a
This commit is contained in:
Brian Haley 2020-05-22 13:04:07 -04:00
parent a2a2301675
commit 4f10c3bd3f
19 changed files with 24 additions and 42 deletions

View File

@ -19,7 +19,6 @@ import netaddr
from neutron_lib import constants as lib_constants
from oslo_log import log as logging
from oslo_utils import excutils
import six
from neutron.agent.l3 import dvr_fip_ns
from neutron.agent.l3 import dvr_router_base
@ -317,7 +316,7 @@ class DvrLocalRouter(dvr_router_base.DvrRouterBase):
"""
net = netaddr.IPNetwork(ip_cidr)
if net.version == 6:
if isinstance(ip_cidr, six.text_type):
if isinstance(ip_cidr, str):
ip_cidr = ip_cidr.encode() # Needed for Python 3.x
# the crc32 & 0xffffffff is for Python 2.6 and 3.0 compatibility
snat_idx = binascii.crc32(ip_cidr) & 0xffffffff

View File

@ -25,7 +25,6 @@ import oslo_messaging
from oslo_service import loopingcall
from oslo_utils import encodeutils
import requests
import six
from six.moves import urllib
import webob
@ -103,7 +102,7 @@ class MetadataProxyHandler(object):
LOG.exception("Unexpected error.")
msg = _('An unknown error has occurred. '
'Please try your request again.')
explanation = six.text_type(msg)
explanation = str(msg)
return webob.exc.HTTPInternalServerError(explanation=explanation)
def _get_ports_from_server(self, router_id=None, ip_address=None,
@ -252,7 +251,7 @@ class MetadataProxyHandler(object):
'Remote metadata server experienced an internal server error.'
)
LOG.warning(msg)
explanation = six.text_type(msg)
explanation = str(msg)
return webob.exc.HTTPInternalServerError(explanation=explanation)
else:
raise Exception(_('Unexpected response code: %s') %

View File

@ -28,7 +28,6 @@ from oslo_config import cfg
from oslo_log import log as logging
from oslo_utils import encodeutils
import requests
import six
from six.moves import urllib
import webob
@ -74,7 +73,7 @@ class MetadataProxyHandler(object):
LOG.exception("Unexpected error.")
msg = _('An unknown error has occurred. '
'Please try your request again.')
explanation = six.text_type(msg)
explanation = str(msg)
return webob.exc.HTTPInternalServerError(explanation=explanation)
def _get_instance_and_project_id(self, req):
@ -159,7 +158,7 @@ class MetadataProxyHandler(object):
'Remote metadata server experienced an internal server error.'
)
LOG.warning(msg)
explanation = six.text_type(msg)
explanation = str(msg)
return webob.exc.HTTPInternalServerError(explanation=explanation)
else:
raise Exception(_('Unexpected response code: %s') %

View File

@ -14,7 +14,6 @@ import re
from neutron_lib.api.definitions import portbindings
from neutron_lib import constants as const
import six
# TODO(lucasagomes): Remove OVN_SG_NAME_EXT_ID_KEY in the Rocky release
OVN_SG_NAME_EXT_ID_KEY = 'neutron:security_group_name'
@ -46,10 +45,10 @@ OVN_DEVICE_OWNER_EXT_ID_KEY = 'neutron:device_owner'
OVN_LIVENESS_CHECK_EXT_ID_KEY = 'neutron:liveness_check_at'
METADATA_LIVENESS_CHECK_EXT_ID_KEY = 'neutron:metadata_liveness_check_at'
OVN_PORT_BINDING_PROFILE = portbindings.PROFILE
OVN_PORT_BINDING_PROFILE_PARAMS = [{'parent_name': six.string_types,
'tag': six.integer_types},
{'vtep-physical-switch': six.string_types,
'vtep-logical-switch': six.string_types}]
OVN_PORT_BINDING_PROFILE_PARAMS = [{'parent_name': str,
'tag': int},
{'vtep-physical-switch': str,
'vtep-logical-switch': str}]
MIGRATING_ATTR = 'migrating_to'
OVN_ROUTER_PORT_OPTION_KEYS = ['router-port', 'nat-addresses']
OVN_GATEWAY_CHASSIS_KEY = 'redirect-chassis'

View File

@ -17,7 +17,6 @@ import datetime
from oslo_log import log
from oslo_utils import timeutils
import six
from tooz import hashring
from neutron.common.ovn import constants
@ -89,7 +88,7 @@ class HashRingManager(object):
self._load_hash_ring()
# tooz expects a byte string for the hash
if isinstance(key, six.string_types):
if isinstance(key, str):
key = key.encode('utf-8')
try:

View File

@ -35,7 +35,6 @@ from oslo_config import cfg
from oslo_log import helpers as log_helper
from oslo_log import log as logging
from oslo_utils import excutils
import six
from neutron._i18n import _
from neutron.api import extensions
@ -1123,7 +1122,7 @@ class L3_NAT_with_dvr_db_mixin(_DVRAgentInterfaceMixin,
def _get_device_owner(self, context, router=None):
"""Get device_owner for the specified router."""
router_is_uuid = isinstance(router, six.string_types)
router_is_uuid = isinstance(router, str)
if router_is_uuid:
router = self._get_router(context, router)
if is_distributed_router(router):

View File

@ -40,7 +40,6 @@ from oslo_db import exception as db_exc
from oslo_log import helpers as log_helpers
from oslo_log import log as logging
from oslo_utils import excutils
import six
import sqlalchemy as sa
from sqlalchemy import exc as sql_exc
from sqlalchemy import orm
@ -341,7 +340,7 @@ class L3_HA_NAT_db_mixin(l3_dvr_db.L3_NAT_with_dvr_db_mixin,
def _get_device_owner(self, context, router=None):
"""Get device_owner for the specified router."""
router_is_uuid = isinstance(router, six.string_types)
router_is_uuid = isinstance(router, str)
if router_is_uuid:
router = self._get_router(context, router)
if (is_ha_router(router) and not

View File

@ -25,7 +25,6 @@ from alembic import util as alembic_util
from oslo_config import cfg
from oslo_utils import fileutils
from oslo_utils import importutils
import six
from neutron._i18n import _
from neutron.conf.db import migration_cli
@ -83,7 +82,7 @@ def do_alembic_command(config, cmd, revision=None, desc=None, **kwargs):
try:
getattr(alembic_command, cmd)(config, *args, **kwargs)
except alembic_util.CommandError as e:
log_error(six.text_type(e))
log_error(str(e))
log_info(_('OK'))

View File

@ -30,7 +30,6 @@ from neutron_lib.utils import helpers
from neutron_lib.utils import net
from oslo_log import log as logging
from oslo_utils import uuidutils
import six
from sqlalchemy.orm import scoped_session
from neutron._i18n import _
@ -414,7 +413,7 @@ class SecurityGroupDbMixin(ext_sg.SecurityGroupPluginBase,
protocol = rule_dict.get('protocol')
if protocol:
# object expects strings only
protocol = six.text_type(protocol)
protocol = str(protocol)
args = {
'id': (rule_dict.get('id') or uuidutils.generate_uuid()),

View File

@ -24,7 +24,6 @@ from neutron_lib.db import constants as db_const
from neutron_lib import exceptions
from neutron_lib.plugins import directory
from oslo_utils import netutils
import six
from neutron._i18n import _
from neutron.api import extensions
@ -171,7 +170,7 @@ def convert_protocol(value):
def convert_ethertype_to_case_insensitive(value):
if isinstance(value, six.string_types):
if isinstance(value, str):
for ethertype in sg_supported_ethertypes:
if ethertype.lower() == value.lower():
return ethertype

View File

@ -29,7 +29,6 @@ from oslo_config import cfg
from oslo_log import log as logging
from oslo_utils import excutils
from oslo_utils import timeutils
import six
from neutron._i18n import _
from neutron.agent.common import ovs_lib
@ -219,7 +218,7 @@ class OpenFlowSwitchMixin(object):
match=None, active_bundle=None, **match_kwargs):
(dp, ofp, ofpp) = self._get_dp()
match = self._match(ofp, ofpp, match, **match_kwargs)
if isinstance(instructions, six.string_types):
if isinstance(instructions, str):
debtcollector.deprecate("Use of string instruction is "
"deprecated", removal_version='U')
jsonlist = ofctl_string.ofp_instruction_from_str(

View File

@ -30,7 +30,6 @@ from oslo_db import exception as db_exc
from oslo_log import log as logging
from oslo_policy import policy
from oslo_utils import excutils
import six
import stevedore
from neutron._i18n import _
@ -334,7 +333,7 @@ class OwnerCheck(policy.Check):
match = self.match % target
if self.kind in creds:
return match == six.text_type(creds[self.kind])
return match == str(creds[self.kind])
return False

View File

@ -21,7 +21,6 @@ from oslo_config import cfg
from oslo_log import log as logging
from oslo_log import versionutils
from oslo_utils import importutils
import six
import webob
from neutron._i18n import _
@ -174,7 +173,7 @@ class QuotaEngine(object):
_driver_class = QUOTA_CONF_DRIVER
LOG.info("ConfDriver is used as quota_driver because the "
"loaded plugin does not support 'quotas' table.")
if isinstance(_driver_class, six.string_types):
if isinstance(_driver_class, str):
_driver_class = importutils.import_object(_driver_class)
if isinstance(_driver_class, ConfDriver):
versionutils.report_deprecated_feature(

View File

@ -13,7 +13,6 @@
# under the License.
import eventlet
import six
from neutron._i18n import _
from neutron.agent.common import async_process
@ -27,7 +26,7 @@ class AsyncProcessTestFramework(base.BaseLoggingTestCase):
def setUp(self):
super(AsyncProcessTestFramework, self).setUp()
self.test_file_path = self.get_temp_file_path('test_async_process.tmp')
self.data = [six.text_type(x) for x in range(4)]
self.data = [str(x) for x in range(4)]
with open(self.test_file_path, 'w') as f:
f.writelines('%s\n' % item for item in self.data)

View File

@ -23,7 +23,6 @@ from oslo_config import fixture as config_fixture
from oslo_db.sqlalchemy import test_migrations
from oslo_log import log as logging
from oslotest import base as oslotest_base
import six
import sqlalchemy
from sqlalchemy import event # noqa
from sqlalchemy.sql import ddl as sqla_ddl
@ -576,7 +575,7 @@ class _TestWalkMigrations(object):
self.script_dir = alembic_script.ScriptDirectory.from_config(db_config)
db_config.neutron_config = cfg.CONF
db_config.neutron_config.set_override('connection',
six.text_type(uri),
str(uri),
group='database')
return db_config

View File

@ -31,7 +31,6 @@ from oslo_config import cfg
from oslo_db import exception as db_exc
from oslo_policy import policy as oslo_policy
from oslo_utils import uuidutils
import six
from six.moves import urllib
import webob
from webob import exc
@ -930,7 +929,7 @@ class JSONV2TestCase(APIv2TestBase, testlib_api.WebTestCase):
instance = self.plugin.return_value
instance.get_network.return_value = {
'tenant_id': six.text_type(tenant_id)
'tenant_id': str(tenant_id)
}
instance.get_ports_count.return_value = 1
instance.create_port.return_value = return_value

View File

@ -392,7 +392,7 @@ class TestExcDetails(base.BaseTestCase):
def test_extract_exc_details_no_details_attached(self):
self.assertIsInstance(
utils.extract_exc_details(Exception()), six.text_type)
utils.extract_exc_details(Exception()), str)
@ddt.ddt

View File

@ -13,7 +13,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import six
import testresources
import testscenarios
import testtools
@ -56,7 +55,7 @@ def create_request(path, body, content_type, method='GET',
req.headers = {}
req.headers['Accept'] = content_type
req.headers.update(headers)
if isinstance(body, six.text_type):
if isinstance(body, str):
req.body = body.encode()
else:
req.body = body

View File

@ -35,7 +35,6 @@ from oslo_service import systemd
from oslo_service import wsgi
from oslo_utils import encodeutils
from oslo_utils import excutils
import six
import webob.dec
import webob.exc
@ -322,7 +321,7 @@ class JSONDictSerializer(DictSerializer):
def default(self, data):
def sanitizer(obj):
return six.text_type(obj)
return str(obj)
return encode_body(jsonutils.dumps(data, default=sanitizer))