Remove six

This library no longer supports Python 2, thus usage of six can be
removed. This also removes workarounds for Python 2.

Change-Id: Ia3f56a2a984cc1d82b717041583a727d9cb5642c
This commit is contained in:
Takashi Kajinami 2022-05-05 12:47:04 +09:00 committed by Brian Rosmaita
parent c722aefb67
commit 94bd3fffc0
10 changed files with 11 additions and 70 deletions

View File

@ -26,7 +26,6 @@ from cinderlib import _fake_packages # noqa F401
from cinderlib import cinderlib
from cinderlib import objects
from cinderlib import serialization
from cinderlib import workarounds # noqa
try:
__version__ = importlib_metadata.version('cinderlib')

View File

@ -33,13 +33,11 @@ input file, it will default to /etc/cinder/cinder.conf.
import sys
import six
from cinderlib.cmd import cinder_to_yaml
def _to_str(value):
if isinstance(value, six.string_types):
if isinstance(value, str):
return '"' + value + '"'
return value

View File

@ -16,7 +16,7 @@
from os import path
import yaml
from six.moves import configparser
import configparser
from cinder.cmd import volume
volume.objects.register_all() # noqa

View File

@ -26,7 +26,6 @@ from os_brick import initiator as brick_initiator
from oslo_config import cfg
from oslo_log import log as logging
from oslo_utils import timeutils
import six
from cinderlib import exception
from cinderlib import utils
@ -65,7 +64,7 @@ class Object(object):
overwrite=False)
def _get_backend(self, backend_name_or_obj):
if isinstance(backend_name_or_obj, six.string_types):
if isinstance(backend_name_or_obj, str):
try:
return self.backend_class.backends[backend_name_or_obj]
except KeyError:
@ -219,7 +218,9 @@ class Object(object):
def _raise_with_resource(self):
exc_info = sys.exc_info()
exc_info[1].resource = self
six.reraise(*exc_info)
if exc_info[1].__traceback__ is not exc_info[2]:
raise exc_info[1].with_traceback(exc_info[2])
raise exc_info[1]
class NamedObject(Object):
@ -296,7 +297,7 @@ class Volume(NamedObject):
def __init__(self, backend_or_vol, pool_name=None, **kwargs):
# Accept backend name for convenience
if isinstance(backend_or_vol, six.string_types):
if isinstance(backend_or_vol, str):
backend_name = backend_or_vol
backend_or_vol = self._get_backend(backend_or_vol)
elif isinstance(backend_or_vol, self.backend_class):
@ -678,8 +679,7 @@ class Connection(Object, LazyVolumeAttr):
# If multipathed not defined autodetect based on connection info
conn_info = conn_info['conn'].get('data', {})
iscsi_mp = 'target_iqns' in conn_info and 'target_portals' in conn_info
fc_mp = not isinstance(conn_info.get('target_wwn', ''),
six.string_types)
fc_mp = not isinstance(conn_info.get('target_wwn', ''), str)
return iscsi_mp or fc_mp
def __init__(self, *args, **kwargs):

View File

@ -14,7 +14,6 @@
# under the License.
import inspect
import six
from stevedore import driver
from cinderlib import exception
@ -54,7 +53,7 @@ def setup(config):
base.PersistenceDriverBase):
return storage(**config)
if not isinstance(storage, six.string_types):
if not isinstance(storage, str):
raise exception.InvalidPersistence(storage)
persistence_driver = driver.DriverManager(

View File

@ -19,7 +19,6 @@ from cinder import objects
from cinder.objects import base as cinder_base_ovo
from oslo_utils import timeutils
from oslo_versionedobjects import fields
import six
import cinderlib
from cinderlib import serialization
@ -90,7 +89,7 @@ class PersistenceDriverBase(object):
resource._ovo.status = 'deleted'
def reset_change_tracker(self, resource, fields=None):
if isinstance(fields, six.string_types):
if isinstance(fields, str):
fields = (fields,)
resource._ovo.obj_reset_changes(fields)

View File

@ -24,7 +24,6 @@ on the OVO's serialization mechanism to add/get additional data we want.
import functools
import json as json_lib
import six
from cinder.objects import base as cinder_base_ovo
from oslo_versionedobjects import base as base_ovo
@ -175,7 +174,7 @@ def datetime_to_primitive(obj, attr, value, visited=None):
def load(json_src, save=False):
"""Load any json serialized cinderlib object."""
if isinstance(json_src, six.string_types):
if isinstance(json_src, str):
json_src = json_lib.loads(json_src)
if isinstance(json_src, list):

View File

@ -19,9 +19,7 @@ import subprocess
import tempfile
import unittest
from oslo_config import cfg
from oslo_utils import strutils
import six
import yaml
import cinderlib
@ -89,19 +87,8 @@ class BaseFunctTestCase(unittest.TestCase):
return cls.tests_config
@staticmethod
def _replace_oslo_cli_parse():
original_cli_parser = cfg.ConfigOpts._parse_cli_opts
def _parse_cli_opts(self, args):
return original_cli_parser(self, [])
cfg.ConfigOpts._parse_cli_opts = six.create_unbound_method(
_parse_cli_opts, cfg.ConfigOpts)
@classmethod
def setUpClass(cls):
cls._replace_oslo_cli_parse()
config = cls.ensure_config_loaded()
# Use memory_db persistence instead of memory to ensure migrations work
cinderlib.setup(root_helper=cls.ROOT_HELPER,

View File

@ -17,24 +17,10 @@
import unittest
from unittest import mock
from oslo_config import cfg
import six
import cinderlib
from cinderlib.tests.unit import utils
def _replace_oslo_cli_parse():
original_cli_parser = cfg.ConfigOpts._parse_cli_opts
def _parse_cli_opts(self, args):
return original_cli_parser(self, [])
cfg.ConfigOpts._parse_cli_opts = six.create_unbound_method(_parse_cli_opts,
cfg.ConfigOpts)
_replace_oslo_cli_parse()
cinderlib.setup(persistence_config={'storage': utils.get_mock_persistence()})

View File

@ -1,26 +0,0 @@
# Copyright (c) 2018, Red Hat, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# 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
if six.PY2:
# Python 2 workaround for getaddrinfo (fails if port is valid unicode)
def my_getaddrinfo(original, host, port, *args, **kwargs):
if isinstance(port, six.text_type):
port = str(port)
return original(host, port, *args, **kwargs)
import functools
import socket
socket.getaddrinfo = functools.partial(my_getaddrinfo, socket.getaddrinfo)