From 0ef0f165cbb2359182edfde8f9e0462687af1c40 Mon Sep 17 00:00:00 2001 From: chenke Date: Tue, 21 Apr 2020 21:22:31 +0800 Subject: [PATCH] Remove six[7] Since our code will only support py3. So remove six is necessary. Change-Id: I3738118b1898421ee41e9e2902c255ead73f3915 --- tox.ini | 2 +- watcher/api/hooks.py | 2 +- watcher/api/middleware/parsable_error.py | 7 ++--- watcher/api/scheduling.py | 3 +- watcher/applier/action_plan/base.py | 4 +-- watcher/applier/actions/base.py | 4 +-- watcher/applier/base.py | 4 +-- watcher/applier/workflow_engine/base.py | 4 +-- watcher/common/context.py | 3 +- watcher/common/loader/base.py | 4 +-- watcher/common/loader/loadable.py | 8 ++--- watcher/common/service_manager.py | 4 +-- watcher/common/utils.py | 5 ++- watcher/db/api.py | 4 +-- watcher/db/purge.py | 1 - watcher/decision_engine/audit/base.py | 12 +++---- .../decision_engine/datasources/grafana.py | 3 +- watcher/decision_engine/goal/base.py | 4 +-- watcher/decision_engine/goal/efficacy/base.py | 5 +-- .../goal/efficacy/indicators.py | 4 +-- watcher/decision_engine/model/base.py | 4 +-- .../decision_engine/model/collector/base.py | 5 ++- .../decision_engine/model/collector/cinder.py | 4 +-- .../model/element/baremetal_resource.py | 4 +-- watcher/decision_engine/model/element/base.py | 4 +-- .../model/element/compute_resource.py | 4 +-- .../model/element/storage_resource.py | 4 +-- watcher/decision_engine/model/model_root.py | 25 +++++++-------- .../model/notification/base.py | 4 +-- .../model/notification/cinder.py | 4 +-- .../model/notification/filtering.py | 3 +- watcher/decision_engine/planner/base.py | 4 +-- watcher/decision_engine/scope/base.py | 4 +-- watcher/decision_engine/scoring/base.py | 7 ++--- watcher/decision_engine/solution/base.py | 4 +-- .../solution/solution_comparator.py | 4 +-- .../solution/solution_evaluator.py | 4 +-- .../decision_engine/strategy/context/base.py | 4 +-- .../strategy/selection/base.py | 4 +-- .../strategy/strategies/base.py | 31 ++++++------------- .../strategies/vm_workload_consolidation.py | 5 ++- .../strategy/strategies/zone_migration.py | 7 ++--- watcher/decision_engine/threading.py | 4 +-- watcher/objects/fields.py | 7 ++--- watcher/tests/api/base.py | 2 +- watcher/tests/api/v1/test_audit_templates.py | 2 +- watcher/tests/api/v1/test_audits.py | 2 +- watcher/tests/api/v1/test_goals.py | 2 +- watcher/tests/api/v1/test_services.py | 2 +- watcher/tests/api/v1/test_strategies.py | 2 +- .../test_default_workflow_engine.py | 5 +-- 51 files changed, 86 insertions(+), 172 deletions(-) diff --git a/tox.ini b/tox.ini index 253301622..b6cb4bc54 100644 --- a/tox.ini +++ b/tox.ini @@ -26,7 +26,7 @@ passenv = http_proxy HTTP_PROXY https_proxy HTTPS_PROXY no_proxy NO_PROXY commands = doc8 doc/source/ CONTRIBUTING.rst HACKING.rst README.rst flake8 - bandit -r watcher -x watcher/tests/* -n5 -ll -s B320 + bandit -r watcher -x watcher/tests/* -n5 -ll -s B320,B322 [testenv:venv] setenv = PYTHONHASHSEED=0 diff --git a/watcher/api/hooks.py b/watcher/api/hooks.py index 5bfd514e7..996678eaf 100644 --- a/watcher/api/hooks.py +++ b/watcher/api/hooks.py @@ -15,9 +15,9 @@ # under the License. +from http import client as http_client from oslo_config import cfg from pecan import hooks -from six.moves import http_client from watcher.common import context diff --git a/watcher/api/middleware/parsable_error.py b/watcher/api/middleware/parsable_error.py index 9d905ab4a..e6ab542f8 100644 --- a/watcher/api/middleware/parsable_error.py +++ b/watcher/api/middleware/parsable_error.py @@ -24,7 +24,6 @@ from xml import etree as et from oslo_log import log from oslo_serialization import jsonutils -import six import webob from watcher._i18n import _ @@ -84,12 +83,10 @@ class ParsableErrorMiddleware(object): '' % state['status_code']] state['headers'].append(('Content-Type', 'application/xml')) else: - if six.PY3: - app_iter = [i.decode('utf-8') for i in app_iter] + app_iter = [i.decode('utf-8') for i in app_iter] body = [jsonutils.dumps( {'error_message': '\n'.join(app_iter)})] - if six.PY3: - body = [item.encode('utf-8') for item in body] + body = [item.encode('utf-8') for item in body] state['headers'].append(('Content-Type', 'application/json')) state['headers'].append(('Content-Length', str(len(body[0])))) else: diff --git a/watcher/api/scheduling.py b/watcher/api/scheduling.py index d44be7d7a..d981e7380 100644 --- a/watcher/api/scheduling.py +++ b/watcher/api/scheduling.py @@ -20,7 +20,6 @@ import itertools from oslo_config import cfg from oslo_log import log from oslo_utils import timeutils -import six from watcher.common import context as watcher_context from watcher.common import scheduling @@ -83,7 +82,7 @@ class APISchedulingService(scheduling.BackgroundSchedulerService): service = objects.Service.get(context, service_id) last_heartbeat = (service.last_seen_up or service.updated_at or service.created_at) - if isinstance(last_heartbeat, six.string_types): + if isinstance(last_heartbeat, str): # NOTE(russellb) If this service came in over rpc via # conductor, then the timestamp will be a string and needs to be # converted back to a datetime. diff --git a/watcher/applier/action_plan/base.py b/watcher/applier/action_plan/base.py index dbd40a6c0..a47388ad0 100644 --- a/watcher/applier/action_plan/base.py +++ b/watcher/applier/action_plan/base.py @@ -18,11 +18,9 @@ # import abc -import six -@six.add_metaclass(abc.ABCMeta) -class BaseActionPlanHandler(object): +class BaseActionPlanHandler(object, metaclass=abc.ABCMeta): @abc.abstractmethod def execute(self): raise NotImplementedError() diff --git a/watcher/applier/actions/base.py b/watcher/applier/actions/base.py index 6518f17c9..114f3a2e4 100644 --- a/watcher/applier/actions/base.py +++ b/watcher/applier/actions/base.py @@ -19,14 +19,12 @@ import abc import jsonschema -import six from watcher.common import clients from watcher.common.loader import loadable -@six.add_metaclass(abc.ABCMeta) -class BaseAction(loadable.Loadable): +class BaseAction(loadable.Loadable, metaclass=abc.ABCMeta): # NOTE(jed): by convention we decided # that the attribute "resource_id" is the unique id of # the resource to which the Action applies to allow us to use it in the diff --git a/watcher/applier/base.py b/watcher/applier/base.py index daa409714..3aedba613 100644 --- a/watcher/applier/base.py +++ b/watcher/applier/base.py @@ -26,11 +26,9 @@ See: :doc:`../architecture` for more details on this component. """ import abc -import six -@six.add_metaclass(abc.ABCMeta) -class BaseApplier(object): +class BaseApplier(object, metaclass=abc.ABCMeta): @abc.abstractmethod def execute(self, action_plan_uuid): raise NotImplementedError() diff --git a/watcher/applier/workflow_engine/base.py b/watcher/applier/workflow_engine/base.py index 5fa7fcdb5..bcf09260a 100644 --- a/watcher/applier/workflow_engine/base.py +++ b/watcher/applier/workflow_engine/base.py @@ -17,7 +17,6 @@ # import abc -import six import time import eventlet @@ -40,8 +39,7 @@ CANCEL_STATE = [objects.action_plan.State.CANCELLING, objects.action_plan.State.CANCELLED] -@six.add_metaclass(abc.ABCMeta) -class BaseWorkFlowEngine(loadable.Loadable): +class BaseWorkFlowEngine(loadable.Loadable, metaclass=abc.ABCMeta): def __init__(self, config, context=None, applier_manager=None): """Constructor diff --git a/watcher/common/context.py b/watcher/common/context.py index c5400f035..7a82cad8c 100644 --- a/watcher/common/context.py +++ b/watcher/common/context.py @@ -13,7 +13,6 @@ from oslo_context import context from oslo_log import log from oslo_utils import timeutils -import six LOG = log.getLogger(__name__) @@ -69,7 +68,7 @@ class RequestContext(context.RequestContext): self.project_id = project_id if not timestamp: timestamp = timeutils.utcnow() - if isinstance(timestamp, six.string_types): + if isinstance(timestamp, str): timestamp = timeutils.parse_isotime(timestamp) self.timestamp = timestamp self.user_name = user_name diff --git a/watcher/common/loader/base.py b/watcher/common/loader/base.py index 322cb4335..d959b2452 100644 --- a/watcher/common/loader/base.py +++ b/watcher/common/loader/base.py @@ -17,11 +17,9 @@ from __future__ import unicode_literals import abc -import six -@six.add_metaclass(abc.ABCMeta) -class BaseLoader(object): +class BaseLoader(object, metaclass=abc.ABCMeta): @abc.abstractmethod def list_available(self): diff --git a/watcher/common/loader/loadable.py b/watcher/common/loader/loadable.py index c234274eb..02fe212b4 100644 --- a/watcher/common/loader/loadable.py +++ b/watcher/common/loader/loadable.py @@ -16,13 +16,10 @@ import abc -import six - from watcher.common import service -@six.add_metaclass(abc.ABCMeta) -class Loadable(object): +class Loadable(object, metaclass=abc.ABCMeta): """Generic interface for dynamically loading a driver/entry point. This defines the contract in order to let the loader manager inject @@ -48,8 +45,7 @@ LoadableSingletonMeta = type( "LoadableSingletonMeta", (abc.ABCMeta, service.Singleton), {}) -@six.add_metaclass(LoadableSingletonMeta) -class LoadableSingleton(object): +class LoadableSingleton(object, metaclass=LoadableSingletonMeta): """Generic interface for dynamically loading a driver as a singleton. This defines the contract in order to let the loader manager inject diff --git a/watcher/common/service_manager.py b/watcher/common/service_manager.py index b87240cfe..db126d8e0 100644 --- a/watcher/common/service_manager.py +++ b/watcher/common/service_manager.py @@ -15,11 +15,9 @@ # under the License. import abc -import six -@six.add_metaclass(abc.ABCMeta) -class ServiceManager(object): +class ServiceManager(object, metaclass=abc.ABCMeta): @abc.abstractproperty def service_name(self): diff --git a/watcher/common/utils.py b/watcher/common/utils.py index 8c1b5d0d5..645b73965 100644 --- a/watcher/common/utils.py +++ b/watcher/common/utils.py @@ -28,7 +28,6 @@ from oslo_config import cfg from oslo_log import log from oslo_utils import strutils from oslo_utils import uuidutils -import six from watcher.common import exception @@ -82,7 +81,7 @@ def safe_rstrip(value, chars=None): :return: Stripped value. """ - if not isinstance(value, six.string_types): + if not isinstance(value, str): LOG.warning( "Failed to remove trailing character. Returning original object." "Supplied object is not a string: %s,", value) @@ -104,7 +103,7 @@ def is_hostname_safe(hostname): """ m = r'^[a-z0-9]([a-z0-9\-]{0,61}[a-z0-9])?$' - return (isinstance(hostname, six.string_types) and + return (isinstance(hostname, str) and (re.match(m, hostname) is not None)) diff --git a/watcher/db/api.py b/watcher/db/api.py index a823f6450..295ae48cf 100644 --- a/watcher/db/api.py +++ b/watcher/db/api.py @@ -18,7 +18,6 @@ Base classes for storage engines import abc from oslo_config import cfg from oslo_db import api as db_api -import six _BACKEND_MAPPING = {'sqlalchemy': 'watcher.db.sqlalchemy.api'} IMPL = db_api.DBAPI.from_config(cfg.CONF, backend_mapping=_BACKEND_MAPPING, @@ -30,8 +29,7 @@ def get_instance(): return IMPL -@six.add_metaclass(abc.ABCMeta) -class BaseConnection(object): +class BaseConnection(object, metaclass=abc.ABCMeta): """Base class for storage system connections.""" @abc.abstractmethod diff --git a/watcher/db/purge.py b/watcher/db/purge.py index 4fb6e5efe..d1b58fefa 100644 --- a/watcher/db/purge.py +++ b/watcher/db/purge.py @@ -25,7 +25,6 @@ import sys from oslo_log import log from oslo_utils import strutils import prettytable as ptable -from six.moves import input from watcher._i18n import _ from watcher._i18n import lazy_translation_enabled diff --git a/watcher/decision_engine/audit/base.py b/watcher/decision_engine/audit/base.py index 07d4bf0e1..37cf72182 100644 --- a/watcher/decision_engine/audit/base.py +++ b/watcher/decision_engine/audit/base.py @@ -18,7 +18,6 @@ # limitations under the License. # import abc -import six from oslo_config import cfg from oslo_log import log @@ -36,9 +35,11 @@ CONF = cfg.CONF LOG = log.getLogger(__name__) -@six.add_metaclass(abc.ABCMeta) -@six.add_metaclass(service.Singleton) -class BaseAuditHandler(object): +class BaseMetaClass(service.Singleton, abc.ABCMeta): + pass + + +class BaseAuditHandler(object, metaclass=BaseMetaClass): @abc.abstractmethod def execute(self, audit, request_context): @@ -57,8 +58,7 @@ class BaseAuditHandler(object): raise NotImplementedError() -@six.add_metaclass(abc.ABCMeta) -class AuditHandler(BaseAuditHandler): +class AuditHandler(BaseAuditHandler, metaclass=abc.ABCMeta): def __init__(self): super(AuditHandler, self).__init__() diff --git a/watcher/decision_engine/datasources/grafana.py b/watcher/decision_engine/datasources/grafana.py index b194d59d4..2cbff9e0f 100644 --- a/watcher/decision_engine/datasources/grafana.py +++ b/watcher/decision_engine/datasources/grafana.py @@ -16,9 +16,10 @@ # See the License for the specific language governing permissions and # limitations under the License. +from urllib import parse as urlparse + from oslo_config import cfg from oslo_log import log -import six.moves.urllib.parse as urlparse from watcher.common import clients from watcher.common import exception diff --git a/watcher/decision_engine/goal/base.py b/watcher/decision_engine/goal/base.py index b272cfcbd..9d0969070 100644 --- a/watcher/decision_engine/goal/base.py +++ b/watcher/decision_engine/goal/base.py @@ -15,13 +15,11 @@ # limitations under the License. import abc -import six from watcher.common.loader import loadable -@six.add_metaclass(abc.ABCMeta) -class Goal(loadable.Loadable): +class Goal(loadable.Loadable, metaclass=abc.ABCMeta): def __init__(self, config): super(Goal, self).__init__(config) diff --git a/watcher/decision_engine/goal/efficacy/base.py b/watcher/decision_engine/goal/efficacy/base.py index 19463c1a8..fa8693b24 100644 --- a/watcher/decision_engine/goal/efficacy/base.py +++ b/watcher/decision_engine/goal/efficacy/base.py @@ -27,11 +27,8 @@ import abc import jsonschema from oslo_serialization import jsonutils -import six - -@six.add_metaclass(abc.ABCMeta) -class EfficacySpecification(object): +class EfficacySpecification(object, metaclass=abc.ABCMeta): def __init__(self): self._indicators_specs = self.get_indicators_specifications() diff --git a/watcher/decision_engine/goal/efficacy/indicators.py b/watcher/decision_engine/goal/efficacy/indicators.py index a5870a825..3f6631dae 100644 --- a/watcher/decision_engine/goal/efficacy/indicators.py +++ b/watcher/decision_engine/goal/efficacy/indicators.py @@ -18,7 +18,6 @@ import abc import jsonschema from jsonschema import SchemaError from jsonschema import ValidationError -import six from oslo_log import log from oslo_serialization import jsonutils @@ -29,8 +28,7 @@ from watcher.common import exception LOG = log.getLogger(__name__) -@six.add_metaclass(abc.ABCMeta) -class IndicatorSpecification(object): +class IndicatorSpecification(object, metaclass=abc.ABCMeta): def __init__(self, name=None, description=None, unit=None, required=True): self.name = name diff --git a/watcher/decision_engine/model/base.py b/watcher/decision_engine/model/base.py index 8629d0530..97cde4cb0 100644 --- a/watcher/decision_engine/model/base.py +++ b/watcher/decision_engine/model/base.py @@ -25,11 +25,9 @@ See: :doc:`../architecture` for more details on this component. """ import abc -import six -@six.add_metaclass(abc.ABCMeta) -class Model(object): +class Model(object, metaclass=abc.ABCMeta): @abc.abstractmethod def to_string(self): diff --git a/watcher/decision_engine/model/collector/base.py b/watcher/decision_engine/model/collector/base.py index 76e9307e3..00b5e6857 100644 --- a/watcher/decision_engine/model/collector/base.py +++ b/watcher/decision_engine/model/collector/base.py @@ -110,7 +110,6 @@ import time from oslo_config import cfg from oslo_log import log -import six from watcher.common import clients from watcher.common.loader import loadable @@ -120,8 +119,8 @@ LOG = log.getLogger(__name__) CONF = cfg.CONF -@six.add_metaclass(abc.ABCMeta) -class BaseClusterDataModelCollector(loadable.LoadableSingleton): +class BaseClusterDataModelCollector(loadable.LoadableSingleton, + metaclass=abc.ABCMeta): STALE_MODEL = model_root.ModelRoot(stale=True) diff --git a/watcher/decision_engine/model/collector/cinder.py b/watcher/decision_engine/model/collector/cinder.py index 5a24389de..cdb9bdd47 100644 --- a/watcher/decision_engine/model/collector/cinder.py +++ b/watcher/decision_engine/model/collector/cinder.py @@ -13,8 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import six - from oslo_log import log from watcher.common import cinder_helper @@ -286,7 +284,7 @@ class CinderModelBuilder(base.BaseModelBuilder): :param instance: Cinder Volume object. :return: A volume node for the graph. """ - attachments = [{k: v for k, v in six.iteritems(d) if k in ( + attachments = [{k: v for k, v in iter(d.items()) if k in ( 'server_id', 'attachment_id')} for d in volume.attachments] volume_attributes = { diff --git a/watcher/decision_engine/model/element/baremetal_resource.py b/watcher/decision_engine/model/element/baremetal_resource.py index d53640fe5..359c7c1dc 100644 --- a/watcher/decision_engine/model/element/baremetal_resource.py +++ b/watcher/decision_engine/model/element/baremetal_resource.py @@ -16,14 +16,12 @@ import abc -import six from watcher.decision_engine.model.element import base from watcher.objects import fields as wfields -@six.add_metaclass(abc.ABCMeta) -class BaremetalResource(base.Element): +class BaremetalResource(base.Element, metaclass=abc.ABCMeta): VERSION = '1.0' diff --git a/watcher/decision_engine/model/element/base.py b/watcher/decision_engine/model/element/base.py index 6ff04da25..3dea73130 100644 --- a/watcher/decision_engine/model/element/base.py +++ b/watcher/decision_engine/model/element/base.py @@ -21,7 +21,6 @@ import collections from lxml import etree from oslo_log import log -import six from watcher.objects import base from watcher.objects import fields as wfields @@ -29,9 +28,8 @@ from watcher.objects import fields as wfields LOG = log.getLogger(__name__) -@six.add_metaclass(abc.ABCMeta) class Element(base.WatcherObject, base.WatcherObjectDictCompat, - base.WatcherComparableObject): + base.WatcherComparableObject, metaclass=abc.ABCMeta): # Initial version VERSION = '1.0' diff --git a/watcher/decision_engine/model/element/compute_resource.py b/watcher/decision_engine/model/element/compute_resource.py index 4b9037506..76ba93277 100644 --- a/watcher/decision_engine/model/element/compute_resource.py +++ b/watcher/decision_engine/model/element/compute_resource.py @@ -16,14 +16,12 @@ import abc -import six from watcher.decision_engine.model.element import base from watcher.objects import fields as wfields -@six.add_metaclass(abc.ABCMeta) -class ComputeResource(base.Element): +class ComputeResource(base.Element, metaclass=abc.ABCMeta): VERSION = '1.0' diff --git a/watcher/decision_engine/model/element/storage_resource.py b/watcher/decision_engine/model/element/storage_resource.py index 834c6621c..6ea67cb70 100644 --- a/watcher/decision_engine/model/element/storage_resource.py +++ b/watcher/decision_engine/model/element/storage_resource.py @@ -16,14 +16,12 @@ import abc -import six from watcher.decision_engine.model.element import base from watcher.objects import fields as wfields -@six.add_metaclass(abc.ABCMeta) -class StorageResource(base.Element): +class StorageResource(base.Element, metaclass=abc.ABCMeta): VERSION = '1.0' diff --git a/watcher/decision_engine/model/model_root.py b/watcher/decision_engine/model/model_root.py index d200196da..242a12477 100644 --- a/watcher/decision_engine/model/model_root.py +++ b/watcher/decision_engine/model/model_root.py @@ -21,7 +21,6 @@ from lxml import etree import networkx as nx from oslo_concurrency import lockutils from oslo_log import log -import six from watcher._i18n import _ from watcher.common import exception @@ -93,9 +92,9 @@ class ModelRoot(nx.DiGraph, base.Model): :param node: :py:class:`~.node.ComputeNode` object or node UUID :type node: str or :py:class:`~.instance.Instance` """ - if isinstance(instance, six.string_types): + if isinstance(instance, str): instance = self.get_instance_by_uuid(instance) - if isinstance(node, six.string_types): + if isinstance(node, str): node = self.get_node_by_uuid(node) self.assert_node(node) self.assert_instance(instance) @@ -104,9 +103,9 @@ class ModelRoot(nx.DiGraph, base.Model): @lockutils.synchronized("model_root") def unmap_instance(self, instance, node): - if isinstance(instance, six.string_types): + if isinstance(instance, str): instance = self.get_instance_by_uuid(instance) - if isinstance(node, six.string_types): + if isinstance(node, str): node = self.get_node_by_uuid(node) self.remove_edge(instance.uuid, node.uuid) @@ -367,9 +366,9 @@ class StorageModelRoot(nx.DiGraph, base.Model): :param pool: :py:class:`~.node.Pool` object or pool name :param node: :py:class:`~.node.StorageNode` object or node host """ - if isinstance(pool, six.string_types): + if isinstance(pool, str): pool = self.get_pool_by_pool_name(pool) - if isinstance(node, six.string_types): + if isinstance(node, str): node = self.get_node_by_name(node) self.assert_node(node) self.assert_pool(pool) @@ -383,9 +382,9 @@ class StorageModelRoot(nx.DiGraph, base.Model): :param pool: :py:class:`~.node.Pool` object or pool name :param node: :py:class:`~.node.StorageNode` object or node name """ - if isinstance(pool, six.string_types): + if isinstance(pool, str): pool = self.get_pool_by_pool_name(pool) - if isinstance(node, six.string_types): + if isinstance(node, str): node = self.get_node_by_name(node) self.remove_edge(pool.name, node.host) @@ -411,9 +410,9 @@ class StorageModelRoot(nx.DiGraph, base.Model): :param volume: :py:class:`~.volume.Volume` object or volume UUID :param pool: :py:class:`~.node.Pool` object or pool name """ - if isinstance(volume, six.string_types): + if isinstance(volume, str): volume = self.get_volume_by_uuid(volume) - if isinstance(pool, six.string_types): + if isinstance(pool, str): pool = self.get_pool_by_pool_name(pool) self.assert_pool(pool) self.assert_volume(volume) @@ -427,9 +426,9 @@ class StorageModelRoot(nx.DiGraph, base.Model): :param volume: :py:class:`~.volume.Volume` object or volume UUID :param pool: :py:class:`~.node.Pool` object or pool name """ - if isinstance(volume, six.string_types): + if isinstance(volume, str): volume = self.get_volume_by_uuid(volume) - if isinstance(pool, six.string_types): + if isinstance(pool, str): pool = self.get_pool_by_pool_name(pool) self.remove_edge(volume.uuid, pool.name) diff --git a/watcher/decision_engine/model/notification/base.py b/watcher/decision_engine/model/notification/base.py index 9090ab312..26a01ac87 100644 --- a/watcher/decision_engine/model/notification/base.py +++ b/watcher/decision_engine/model/notification/base.py @@ -17,11 +17,9 @@ # limitations under the License. import abc -import six -@six.add_metaclass(abc.ABCMeta) -class NotificationEndpoint(object): +class NotificationEndpoint(object, metaclass=abc.ABCMeta): def __init__(self, collector): super(NotificationEndpoint, self).__init__() diff --git a/watcher/decision_engine/model/notification/cinder.py b/watcher/decision_engine/model/notification/cinder.py index 5c7066b9a..4a248506c 100644 --- a/watcher/decision_engine/model/notification/cinder.py +++ b/watcher/decision_engine/model/notification/cinder.py @@ -14,8 +14,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import six - from oslo_log import log from watcher.common import cinder_helper from watcher.common import exception @@ -161,7 +159,7 @@ class CinderNotification(base.NotificationEndpoint): return 'attachment_id' attachments = [ - {_keyReplace(k): v for k, v in six.iteritems(d) + {_keyReplace(k): v for k, v in iter(d.items()) if k in ('instance_uuid', 'id')} for d in data['volume_attachment'] ] diff --git a/watcher/decision_engine/model/notification/filtering.py b/watcher/decision_engine/model/notification/filtering.py index 737e317ff..181fbb144 100644 --- a/watcher/decision_engine/model/notification/filtering.py +++ b/watcher/decision_engine/model/notification/filtering.py @@ -19,7 +19,6 @@ import re import oslo_messaging as om -import six class NotificationFilter(om.NotificationFilter): @@ -81,7 +80,7 @@ class NotificationFilter(om.NotificationFilter): elif regex is not None and data is None: return True elif (regex is not None and - isinstance(data, six.string_types) and + isinstance(data, str) and not regex.match(data)): return True diff --git a/watcher/decision_engine/planner/base.py b/watcher/decision_engine/planner/base.py index 9c255b4c2..7e8a132d1 100644 --- a/watcher/decision_engine/planner/base.py +++ b/watcher/decision_engine/planner/base.py @@ -45,13 +45,11 @@ See :doc:`../architecture` for more details on this component. """ import abc -import six from watcher.common.loader import loadable -@six.add_metaclass(abc.ABCMeta) -class BasePlanner(loadable.Loadable): +class BasePlanner(loadable.Loadable, metaclass=abc.ABCMeta): @classmethod def get_config_opts(cls): diff --git a/watcher/decision_engine/scope/base.py b/watcher/decision_engine/scope/base.py index 76f17467f..34aaff824 100644 --- a/watcher/decision_engine/scope/base.py +++ b/watcher/decision_engine/scope/base.py @@ -16,13 +16,11 @@ # import abc -import six from watcher.common import context -@six.add_metaclass(abc.ABCMeta) -class BaseScope(object): +class BaseScope(object, metaclass=abc.ABCMeta): """A base class for Scope mechanism Child of this class is called when audit launches strategy. This strategy diff --git a/watcher/decision_engine/scoring/base.py b/watcher/decision_engine/scoring/base.py index 3fcc68b6a..0c1e27745 100644 --- a/watcher/decision_engine/scoring/base.py +++ b/watcher/decision_engine/scoring/base.py @@ -17,13 +17,11 @@ # limitations under the License. import abc -import six from watcher.common.loader import loadable -@six.add_metaclass(abc.ABCMeta) -class ScoringEngine(loadable.Loadable): +class ScoringEngine(loadable.Loadable, metaclass=abc.ABCMeta): """A base class for all the Scoring Engines. A Scoring Engine is an instance of a data model, to which the learning @@ -97,8 +95,7 @@ class ScoringEngine(loadable.Loadable): return [] -@six.add_metaclass(abc.ABCMeta) -class ScoringEngineContainer(loadable.Loadable): +class ScoringEngineContainer(loadable.Loadable, metaclass=abc.ABCMeta): """A base class for all the Scoring Engines Containers. A Scoring Engine Container is an abstraction which allows to plugin diff --git a/watcher/decision_engine/solution/base.py b/watcher/decision_engine/solution/base.py index ba56a0716..f150b0076 100644 --- a/watcher/decision_engine/solution/base.py +++ b/watcher/decision_engine/solution/base.py @@ -56,13 +56,11 @@ Two approaches to dealing with this can be envisaged: """ import abc -import six from watcher.decision_engine.solution import efficacy -@six.add_metaclass(abc.ABCMeta) -class BaseSolution(object): +class BaseSolution(object, metaclass=abc.ABCMeta): def __init__(self, goal, strategy): """Base Solution constructor diff --git a/watcher/decision_engine/solution/solution_comparator.py b/watcher/decision_engine/solution/solution_comparator.py index 254cd6c03..768ea80b9 100644 --- a/watcher/decision_engine/solution/solution_comparator.py +++ b/watcher/decision_engine/solution/solution_comparator.py @@ -17,11 +17,9 @@ # limitations under the License. # import abc -import six -@six.add_metaclass(abc.ABCMeta) -class BaseSolutionComparator(object): +class BaseSolutionComparator(object, metaclass=abc.ABCMeta): @abc.abstractmethod def compare(self, sol1, sol2): raise NotImplementedError() diff --git a/watcher/decision_engine/solution/solution_evaluator.py b/watcher/decision_engine/solution/solution_evaluator.py index b36b70f4f..aad340e88 100644 --- a/watcher/decision_engine/solution/solution_evaluator.py +++ b/watcher/decision_engine/solution/solution_evaluator.py @@ -17,11 +17,9 @@ # limitations under the License. # import abc -import six -@six.add_metaclass(abc.ABCMeta) -class BaseSolutionEvaluator(object): +class BaseSolutionEvaluator(object, metaclass=abc.ABCMeta): @abc.abstractmethod def evaluate(self, solution): raise NotImplementedError() diff --git a/watcher/decision_engine/strategy/context/base.py b/watcher/decision_engine/strategy/context/base.py index 37286b2b1..1e59871c8 100644 --- a/watcher/decision_engine/strategy/context/base.py +++ b/watcher/decision_engine/strategy/context/base.py @@ -18,14 +18,12 @@ # limitations under the License. import abc -import six from watcher import notifications from watcher.objects import fields -@six.add_metaclass(abc.ABCMeta) -class StrategyContext(object): +class StrategyContext(object, metaclass=abc.ABCMeta): def execute_strategy(self, audit, request_context): """Execute the strategy for the given an audit diff --git a/watcher/decision_engine/strategy/selection/base.py b/watcher/decision_engine/strategy/selection/base.py index 7bf949029..d21e36d63 100644 --- a/watcher/decision_engine/strategy/selection/base.py +++ b/watcher/decision_engine/strategy/selection/base.py @@ -17,11 +17,9 @@ # limitations under the License. # import abc -import six -@six.add_metaclass(abc.ABCMeta) -class BaseSelector(object): +class BaseSelector(object, metaclass=abc.ABCMeta): @abc.abstractmethod def select(self): diff --git a/watcher/decision_engine/strategy/strategies/base.py b/watcher/decision_engine/strategy/strategies/base.py index a74ff5a02..734b03619 100755 --- a/watcher/decision_engine/strategy/strategies/base.py +++ b/watcher/decision_engine/strategy/strategies/base.py @@ -37,7 +37,6 @@ which are dynamically loaded by Watcher at launch time. """ import abc -import six from oslo_config import cfg from oslo_log import log @@ -121,8 +120,7 @@ class StrategyEndpoint(object): return [available_datasource, available_metrics, available_cdm] -@six.add_metaclass(abc.ABCMeta) -class BaseStrategy(loadable.Loadable): +class BaseStrategy(loadable.Loadable, metaclass=abc.ABCMeta): """A base class for all the strategies A Strategy is an algorithm implementation which is able to find a @@ -471,8 +469,7 @@ class BaseStrategy(loadable.Loadable): input_parameters=parameters) -@six.add_metaclass(abc.ABCMeta) -class DummyBaseStrategy(BaseStrategy): +class DummyBaseStrategy(BaseStrategy, metaclass=abc.ABCMeta): @classmethod def get_goal_name(cls): @@ -485,8 +482,7 @@ class DummyBaseStrategy(BaseStrategy): return [] -@six.add_metaclass(abc.ABCMeta) -class UnclassifiedStrategy(BaseStrategy): +class UnclassifiedStrategy(BaseStrategy, metaclass=abc.ABCMeta): """This base class is used to ease the development of new strategies The goal defined within this strategy can be used to simplify the @@ -500,8 +496,7 @@ class UnclassifiedStrategy(BaseStrategy): return "unclassified" -@six.add_metaclass(abc.ABCMeta) -class ServerConsolidationBaseStrategy(BaseStrategy): +class ServerConsolidationBaseStrategy(BaseStrategy, metaclass=abc.ABCMeta): REASON_FOR_DISABLE = 'watcher_disabled' @@ -510,16 +505,14 @@ class ServerConsolidationBaseStrategy(BaseStrategy): return "server_consolidation" -@six.add_metaclass(abc.ABCMeta) -class ThermalOptimizationBaseStrategy(BaseStrategy): +class ThermalOptimizationBaseStrategy(BaseStrategy, metaclass=abc.ABCMeta): @classmethod def get_goal_name(cls): return "thermal_optimization" -@six.add_metaclass(abc.ABCMeta) -class WorkloadStabilizationBaseStrategy(BaseStrategy): +class WorkloadStabilizationBaseStrategy(BaseStrategy, metaclass=abc.ABCMeta): def __init__(self, *args, **kwargs): super(WorkloadStabilizationBaseStrategy, self @@ -531,16 +524,14 @@ class WorkloadStabilizationBaseStrategy(BaseStrategy): return "workload_balancing" -@six.add_metaclass(abc.ABCMeta) -class NoisyNeighborBaseStrategy(BaseStrategy): +class NoisyNeighborBaseStrategy(BaseStrategy, metaclass=abc.ABCMeta): @classmethod def get_goal_name(cls): return "noisy_neighbor" -@six.add_metaclass(abc.ABCMeta) -class SavingEnergyBaseStrategy(BaseStrategy): +class SavingEnergyBaseStrategy(BaseStrategy, metaclass=abc.ABCMeta): @classmethod def get_goal_name(cls): @@ -553,8 +544,7 @@ class SavingEnergyBaseStrategy(BaseStrategy): return [] -@six.add_metaclass(abc.ABCMeta) -class ZoneMigrationBaseStrategy(BaseStrategy): +class ZoneMigrationBaseStrategy(BaseStrategy, metaclass=abc.ABCMeta): @classmethod def get_goal_name(cls): @@ -567,8 +557,7 @@ class ZoneMigrationBaseStrategy(BaseStrategy): return [] -@six.add_metaclass(abc.ABCMeta) -class HostMaintenanceBaseStrategy(BaseStrategy): +class HostMaintenanceBaseStrategy(BaseStrategy, metaclass=abc.ABCMeta): REASON_FOR_MAINTAINING = 'watcher_maintaining' diff --git a/watcher/decision_engine/strategy/strategies/vm_workload_consolidation.py b/watcher/decision_engine/strategy/strategies/vm_workload_consolidation.py index b9a09e387..2c5f55489 100644 --- a/watcher/decision_engine/strategy/strategies/vm_workload_consolidation.py +++ b/watcher/decision_engine/strategy/strategies/vm_workload_consolidation.py @@ -19,7 +19,6 @@ # from oslo_log import log -import six from watcher._i18n import _ from watcher.common import exception @@ -132,7 +131,7 @@ class VMWorkloadConsolidation(base.ServerConsolidationBaseStrategy): :param instance: """ - if isinstance(instance.state, six.string_types): + if isinstance(instance.state, str): return instance.state elif isinstance(instance.state, element.InstanceState): return instance.state.value @@ -148,7 +147,7 @@ class VMWorkloadConsolidation(base.ServerConsolidationBaseStrategy): :param node: """ - if isinstance(node.status, six.string_types): + if isinstance(node.status, str): return node.status elif isinstance(node.status, element.ServiceState): return node.status.value diff --git a/watcher/decision_engine/strategy/strategies/zone_migration.py b/watcher/decision_engine/strategy/strategies/zone_migration.py index dc51fd225..edecd8354 100644 --- a/watcher/decision_engine/strategy/strategies/zone_migration.py +++ b/watcher/decision_engine/strategy/strategies/zone_migration.py @@ -13,7 +13,6 @@ # from dateutil.parser import parse -import six from oslo_log import log @@ -282,7 +281,7 @@ class ZoneMigration(base.ZoneMigrationBaseStrategy): action_counter = ActionCounter(total_limit, per_pool_limit, per_node_limit) - for k, targets in six.iteritems(filtered_targets): + for k, targets in iter(filtered_targets.items()): if k == VOLUME: self.volumes_migration(targets, action_counter) elif k == INSTANCE: @@ -580,7 +579,7 @@ class ZoneMigration(base.ZoneMigrationBaseStrategy): filter_list = [] priority_filter_map = self.get_priority_filter_map() - for k, v in six.iteritems(self.priority): + for k, v in iter(self.priority.items()): if k in priority_filter_map: filter_list.append(priority_filter_map[k](v)) @@ -710,7 +709,7 @@ class BaseFilter(object): return {} for cond in list(reversed(self.condition)): - for k, v in six.iteritems(targets): + for k, v in iter(targets.items()): if not self.is_allowed(k): continue LOG.debug("filter:%s with the key: %s", cond, k) diff --git a/watcher/decision_engine/threading.py b/watcher/decision_engine/threading.py index 8a8a154c4..68d1baf38 100644 --- a/watcher/decision_engine/threading.py +++ b/watcher/decision_engine/threading.py @@ -19,7 +19,6 @@ import copy import futurist from futurist import waiters -import six from oslo_config import cfg from oslo_log import log @@ -29,8 +28,7 @@ CONF = cfg.CONF LOG = log.getLogger(__name__) -@six.add_metaclass(service.Singleton) -class DecisionEngineThreadPool(object): +class DecisionEngineThreadPool(object, metaclass=service.Singleton): """Singleton threadpool to submit general tasks to""" def __init__(self): diff --git a/watcher/objects/fields.py b/watcher/objects/fields.py index 94eeb5346..abe7f1f0a 100644 --- a/watcher/objects/fields.py +++ b/watcher/objects/fields.py @@ -15,7 +15,6 @@ """Utility methods for objects""" import ast -import six from oslo_serialization import jsonutils from oslo_versionedobjects import fields @@ -67,7 +66,7 @@ class ListOfUUIDsField(fields.AutoTypedField): class FlexibleDict(fields.FieldType): @staticmethod def coerce(obj, attr, value): - if isinstance(value, six.string_types): + if isinstance(value, str): value = ast.literal_eval(value) return dict(value) @@ -87,7 +86,7 @@ class FlexibleDictField(fields.AutoTypedField): class FlexibleListOfDict(fields.FieldType): @staticmethod def coerce(obj, attr, value): - if isinstance(value, six.string_types): + if isinstance(value, str): value = ast.literal_eval(value) return list(value) @@ -106,7 +105,7 @@ class FlexibleListOfDictField(fields.AutoTypedField): class Json(fields.FieldType): def coerce(self, obj, attr, value): - if isinstance(value, six.string_types): + if isinstance(value, str): loaded = jsonutils.loads(value) return loaded return value diff --git a/watcher/tests/api/base.py b/watcher/tests/api/base.py index 82696512b..9d05824cb 100644 --- a/watcher/tests/api/base.py +++ b/watcher/tests/api/base.py @@ -24,11 +24,11 @@ import copy import mock +from urllib import parse as urlparse from oslo_config import cfg import pecan import pecan.testing -from six.moves.urllib import parse as urlparse from watcher.api import hooks from watcher.common import context as watcher_context diff --git a/watcher/tests/api/v1/test_audit_templates.py b/watcher/tests/api/v1/test_audit_templates.py index dc990e4d2..55002bc04 100644 --- a/watcher/tests/api/v1/test_audit_templates.py +++ b/watcher/tests/api/v1/test_audit_templates.py @@ -13,12 +13,12 @@ import datetime import itertools import mock +from urllib import parse as urlparse from webtest.app import AppError from oslo_config import cfg from oslo_serialization import jsonutils from oslo_utils import timeutils -from six.moves.urllib import parse as urlparse from wsme import types as wtypes from watcher.api.controllers.v1 import audit_template as api_audit_template diff --git a/watcher/tests/api/v1/test_audits.py b/watcher/tests/api/v1/test_audits.py index 14137f62a..34603e655 100644 --- a/watcher/tests/api/v1/test_audits.py +++ b/watcher/tests/api/v1/test_audits.py @@ -14,13 +14,13 @@ import datetime from dateutil import tz import itertools import mock +from urllib import parse as urlparse from oslo_config import cfg from oslo_serialization import jsonutils from oslo_utils import timeutils from wsme import types as wtypes -from six.moves.urllib import parse as urlparse from watcher.api.controllers.v1 import audit as api_audit from watcher.common import utils from watcher.db import api as db_api diff --git a/watcher/tests/api/v1/test_goals.py b/watcher/tests/api/v1/test_goals.py index f75e120d0..94baf4291 100644 --- a/watcher/tests/api/v1/test_goals.py +++ b/watcher/tests/api/v1/test_goals.py @@ -12,7 +12,7 @@ from oslo_config import cfg from oslo_serialization import jsonutils -from six.moves.urllib import parse as urlparse +from urllib import parse as urlparse from watcher.common import utils from watcher.tests.api import base as api_base diff --git a/watcher/tests/api/v1/test_services.py b/watcher/tests/api/v1/test_services.py index 8bc7f3581..114534ad6 100644 --- a/watcher/tests/api/v1/test_services.py +++ b/watcher/tests/api/v1/test_services.py @@ -12,7 +12,7 @@ from oslo_config import cfg from oslo_serialization import jsonutils -from six.moves.urllib import parse as urlparse +from urllib import parse as urlparse from watcher.tests.api import base as api_base from watcher.tests.objects import utils as obj_utils diff --git a/watcher/tests/api/v1/test_strategies.py b/watcher/tests/api/v1/test_strategies.py index abba7becd..33442b0f2 100644 --- a/watcher/tests/api/v1/test_strategies.py +++ b/watcher/tests/api/v1/test_strategies.py @@ -11,10 +11,10 @@ # limitations under the License. import mock +from urllib import parse as urlparse from oslo_config import cfg from oslo_serialization import jsonutils -from six.moves.urllib import parse as urlparse from watcher.common import utils from watcher.decision_engine import rpcapi as deapi diff --git a/watcher/tests/applier/workflow_engine/test_default_workflow_engine.py b/watcher/tests/applier/workflow_engine/test_default_workflow_engine.py index 08053904a..100d21a69 100644 --- a/watcher/tests/applier/workflow_engine/test_default_workflow_engine.py +++ b/watcher/tests/applier/workflow_engine/test_default_workflow_engine.py @@ -19,8 +19,6 @@ import abc import mock -import six - from watcher.applier.actions import base as abase from watcher.applier.actions import factory from watcher.applier.workflow_engine import default as tflow @@ -36,8 +34,7 @@ class ExpectedException(Exception): pass -@six.add_metaclass(abc.ABCMeta) -class FakeAction(abase.BaseAction): +class FakeAction(abase.BaseAction, metaclass=abc.ABCMeta): def schema(self): pass