Remove six[7]
Since our code will only support py3. So remove six is necessary. Change-Id: I3738118b1898421ee41e9e2902c255ead73f3915
This commit is contained in:
2
tox.ini
2
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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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):
|
||||
'</error_message>' % 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:
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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))
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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__()
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
@@ -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'
|
||||
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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'
|
||||
|
||||
|
||||
@@ -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'
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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__()
|
||||
|
||||
@@ -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']
|
||||
]
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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'
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user