commit b49bef7dd9f9725c8505aa21b01adaeeb8907da1 Author: xuanyandong Date: Wed Oct 7 22:39:31 2020 +0800 Remove six of dir cinder/scheduler/* Replace the following items with Python 3 style code. - six.add_metaclass - six.string_types - six.text_type - six.wraps Change-Id: I1a1d9bf7e26e436bc93fe0091ecaae8ca5593c42 Implements: blueprint six-removal diff --git a/cinder/scheduler/base_weight.py b/cinder/scheduler/base_weight.py index bbd0bba..6472ff9 100644 --- a/cinder/scheduler/base_weight.py +++ b/cinder/scheduler/base_weight.py @@ -20,7 +20,6 @@ Pluggable Weighing support import abc from oslo_log import log as logging -import six from cinder.scheduler import base_handler @@ -67,8 +66,7 @@ class WeighedObject(object): return "" % (self.obj, self.weight) -@six.add_metaclass(abc.ABCMeta) -class BaseWeigher(object): +class BaseWeigher(object, metaclass=abc.ABCMeta): """Base class for pluggable weighers. The attributes maxval and minval can be specified to set up the maximum diff --git a/cinder/scheduler/evaluator/evaluator.py b/cinder/scheduler/evaluator/evaluator.py index 0d05beb..435c5b1 100644 --- a/cinder/scheduler/evaluator/evaluator.py +++ b/cinder/scheduler/evaluator/evaluator.py @@ -17,7 +17,6 @@ import operator import re import pyparsing -import six from cinder import exception from cinder.i18n import _ @@ -40,7 +39,7 @@ class EvalConstant(object): def eval(self): result = self.value - if (isinstance(result, six.string_types) and + if (isinstance(result, str) and re.match(r"^[a-zA-Z_]+\.[a-zA-Z_]+$", result)): (which_dict, entry) = result.split('.') try: diff --git a/cinder/scheduler/filters/driver_filter.py b/cinder/scheduler/filters/driver_filter.py index 33ed9fd..397215d 100644 --- a/cinder/scheduler/filters/driver_filter.py +++ b/cinder/scheduler/filters/driver_filter.py @@ -14,7 +14,6 @@ # under the License. from oslo_log import log as logging -import six from cinder.scheduler.evaluator import evaluator from cinder.scheduler import filters @@ -120,7 +119,7 @@ class DriverFilter(filters.BaseBackendFilter): if ('filter_function' in backend_caps and backend_caps['filter_function'] is not None): - filter_function = six.text_type(backend_caps['filter_function']) + filter_function = str(backend_caps['filter_function']) qos_specs = filter_properties.get('qos_specs', {}) diff --git a/cinder/scheduler/filters/json_filter.py b/cinder/scheduler/filters/json_filter.py index 6377537..851e873 100644 --- a/cinder/scheduler/filters/json_filter.py +++ b/cinder/scheduler/filters/json_filter.py @@ -16,7 +16,6 @@ import operator from oslo_serialization import jsonutils -import six from cinder.scheduler import filters @@ -127,7 +126,7 @@ class JsonFilter(filters.BaseBackendFilter): for arg in query[1:]: if isinstance(arg, list): arg = self._process_filter(arg, backend_state) - elif isinstance(arg, six.string_types): + elif isinstance(arg, str): arg = self._parse_string(arg, backend_state) if arg is not None: cooked_args.append(arg) diff --git a/cinder/scheduler/manager.py b/cinder/scheduler/manager.py index 0832f38..d163856 100644 --- a/cinder/scheduler/manager.py +++ b/cinder/scheduler/manager.py @@ -21,6 +21,7 @@ Scheduler Service import collections from datetime import datetime +import functools import eventlet from oslo_config import cfg @@ -31,7 +32,6 @@ from oslo_utils import excutils from oslo_utils import importutils from oslo_utils import timeutils from oslo_utils import versionutils -import six from cinder.backup import rpcapi as backup_rpcapi from cinder import context @@ -74,7 +74,7 @@ LOG = logging.getLogger(__name__) def append_operation_type(name=None): def _decorator(schedule_function): - @six.wraps(schedule_function) + @functools.wraps(schedule_function) def inject_operation_decorator(*args, **kwargs): request_spec = kwargs.get('request_spec', None) @@ -485,7 +485,7 @@ class SchedulerManager(manager.CleanableManager, manager.Manager): # TODO(harlowja): move into a task that just does this later. if not msg: msg = ("Failed to schedule_%(method)s: %(ex)s" % - {'method': method, 'ex': six.text_type(ex)}) + {'method': method, 'ex': ex}) LOG.error(msg) volume_state = updates['volume_state'] @@ -515,7 +515,7 @@ class SchedulerManager(manager.CleanableManager, manager.Manager): msg=None): if not msg: msg = ("Failed to schedule_%(method)s: %(ex)s" % - {'method': method, 'ex': six.text_type(ex)}) + {'method': method, 'ex': ex}) LOG.error(msg) model_update = dict(status=state) diff --git a/cinder/scheduler/weights/goodness.py b/cinder/scheduler/weights/goodness.py index feb0e07..31d7ee6 100644 --- a/cinder/scheduler/weights/goodness.py +++ b/cinder/scheduler/weights/goodness.py @@ -13,7 +13,6 @@ # under the License. from oslo_log import log as logging -import six from cinder.scheduler.evaluator import evaluator from cinder.scheduler import weights @@ -124,7 +123,7 @@ class GoodnessWeigher(weights.BaseHostWeigher): if ('goodness_function' in host_caps and host_caps['goodness_function'] is not None): - goodness_function = six.text_type(host_caps['goodness_function']) + goodness_function = str(host_caps['goodness_function']) qos_specs = weight_properties.get('qos_specs', {}) or {}