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

View File

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

View File

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

View File

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

View File

@ -35,7 +35,6 @@ from oslo_config import cfg
from oslo_log import helpers as log_helper from oslo_log import helpers as log_helper
from oslo_log import log as logging from oslo_log import log as logging
from oslo_utils import excutils from oslo_utils import excutils
import six
from neutron._i18n import _ from neutron._i18n import _
from neutron.api import extensions 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): def _get_device_owner(self, context, router=None):
"""Get device_owner for the specified router.""" """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: if router_is_uuid:
router = self._get_router(context, router) router = self._get_router(context, router)
if is_distributed_router(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 helpers as log_helpers
from oslo_log import log as logging from oslo_log import log as logging
from oslo_utils import excutils from oslo_utils import excutils
import six
import sqlalchemy as sa import sqlalchemy as sa
from sqlalchemy import exc as sql_exc from sqlalchemy import exc as sql_exc
from sqlalchemy import orm 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): def _get_device_owner(self, context, router=None):
"""Get device_owner for the specified router.""" """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: if router_is_uuid:
router = self._get_router(context, router) router = self._get_router(context, router)
if (is_ha_router(router) and not 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_config import cfg
from oslo_utils import fileutils from oslo_utils import fileutils
from oslo_utils import importutils from oslo_utils import importutils
import six
from neutron._i18n import _ from neutron._i18n import _
from neutron.conf.db import migration_cli from neutron.conf.db import migration_cli
@ -83,7 +82,7 @@ def do_alembic_command(config, cmd, revision=None, desc=None, **kwargs):
try: try:
getattr(alembic_command, cmd)(config, *args, **kwargs) getattr(alembic_command, cmd)(config, *args, **kwargs)
except alembic_util.CommandError as e: except alembic_util.CommandError as e:
log_error(six.text_type(e)) log_error(str(e))
log_info(_('OK')) log_info(_('OK'))

View File

@ -30,7 +30,6 @@ from neutron_lib.utils import helpers
from neutron_lib.utils import net from neutron_lib.utils import net
from oslo_log import log as logging from oslo_log import log as logging
from oslo_utils import uuidutils from oslo_utils import uuidutils
import six
from sqlalchemy.orm import scoped_session from sqlalchemy.orm import scoped_session
from neutron._i18n import _ from neutron._i18n import _
@ -414,7 +413,7 @@ class SecurityGroupDbMixin(ext_sg.SecurityGroupPluginBase,
protocol = rule_dict.get('protocol') protocol = rule_dict.get('protocol')
if protocol: if protocol:
# object expects strings only # object expects strings only
protocol = six.text_type(protocol) protocol = str(protocol)
args = { args = {
'id': (rule_dict.get('id') or uuidutils.generate_uuid()), '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 import exceptions
from neutron_lib.plugins import directory from neutron_lib.plugins import directory
from oslo_utils import netutils from oslo_utils import netutils
import six
from neutron._i18n import _ from neutron._i18n import _
from neutron.api import extensions from neutron.api import extensions
@ -171,7 +170,7 @@ def convert_protocol(value):
def convert_ethertype_to_case_insensitive(value): def convert_ethertype_to_case_insensitive(value):
if isinstance(value, six.string_types): if isinstance(value, str):
for ethertype in sg_supported_ethertypes: for ethertype in sg_supported_ethertypes:
if ethertype.lower() == value.lower(): if ethertype.lower() == value.lower():
return ethertype return ethertype

View File

@ -29,7 +29,6 @@ from oslo_config import cfg
from oslo_log import log as logging from oslo_log import log as logging
from oslo_utils import excutils from oslo_utils import excutils
from oslo_utils import timeutils from oslo_utils import timeutils
import six
from neutron._i18n import _ from neutron._i18n import _
from neutron.agent.common import ovs_lib from neutron.agent.common import ovs_lib
@ -219,7 +218,7 @@ class OpenFlowSwitchMixin(object):
match=None, active_bundle=None, **match_kwargs): match=None, active_bundle=None, **match_kwargs):
(dp, ofp, ofpp) = self._get_dp() (dp, ofp, ofpp) = self._get_dp()
match = self._match(ofp, ofpp, match, **match_kwargs) 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 " debtcollector.deprecate("Use of string instruction is "
"deprecated", removal_version='U') "deprecated", removal_version='U')
jsonlist = ofctl_string.ofp_instruction_from_str( 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_log import log as logging
from oslo_policy import policy from oslo_policy import policy
from oslo_utils import excutils from oslo_utils import excutils
import six
import stevedore import stevedore
from neutron._i18n import _ from neutron._i18n import _
@ -334,7 +333,7 @@ class OwnerCheck(policy.Check):
match = self.match % target match = self.match % target
if self.kind in creds: if self.kind in creds:
return match == six.text_type(creds[self.kind]) return match == str(creds[self.kind])
return False return False

View File

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

View File

@ -13,7 +13,6 @@
# under the License. # under the License.
import eventlet import eventlet
import six
from neutron._i18n import _ from neutron._i18n import _
from neutron.agent.common import async_process from neutron.agent.common import async_process
@ -27,7 +26,7 @@ class AsyncProcessTestFramework(base.BaseLoggingTestCase):
def setUp(self): def setUp(self):
super(AsyncProcessTestFramework, self).setUp() super(AsyncProcessTestFramework, self).setUp()
self.test_file_path = self.get_temp_file_path('test_async_process.tmp') 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: with open(self.test_file_path, 'w') as f:
f.writelines('%s\n' % item for item in self.data) 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_db.sqlalchemy import test_migrations
from oslo_log import log as logging from oslo_log import log as logging
from oslotest import base as oslotest_base from oslotest import base as oslotest_base
import six
import sqlalchemy import sqlalchemy
from sqlalchemy import event # noqa from sqlalchemy import event # noqa
from sqlalchemy.sql import ddl as sqla_ddl 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) self.script_dir = alembic_script.ScriptDirectory.from_config(db_config)
db_config.neutron_config = cfg.CONF db_config.neutron_config = cfg.CONF
db_config.neutron_config.set_override('connection', db_config.neutron_config.set_override('connection',
six.text_type(uri), str(uri),
group='database') group='database')
return db_config return db_config

View File

@ -31,7 +31,6 @@ from oslo_config import cfg
from oslo_db import exception as db_exc from oslo_db import exception as db_exc
from oslo_policy import policy as oslo_policy from oslo_policy import policy as oslo_policy
from oslo_utils import uuidutils from oslo_utils import uuidutils
import six
from six.moves import urllib from six.moves import urllib
import webob import webob
from webob import exc from webob import exc
@ -930,7 +929,7 @@ class JSONV2TestCase(APIv2TestBase, testlib_api.WebTestCase):
instance = self.plugin.return_value instance = self.plugin.return_value
instance.get_network.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.get_ports_count.return_value = 1
instance.create_port.return_value = return_value 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): def test_extract_exc_details_no_details_attached(self):
self.assertIsInstance( self.assertIsInstance(
utils.extract_exc_details(Exception()), six.text_type) utils.extract_exc_details(Exception()), str)
@ddt.ddt @ddt.ddt

View File

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

View File

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