From 5a657dd9477bdf43a075cdaccb29c6c9d8329bac Mon Sep 17 00:00:00 2001 From: fujioka yuuichi Date: Tue, 8 Oct 2013 10:58:50 +0900 Subject: [PATCH] Apply six for metaclass __metaclass__ cannot be used in python3. six be used in general for python 3 compatibility. Change-Id: I1d9909d70bb614c9d1c336d0c492027f5b6b5088 Closes-Bug: #1236648 --- ceilometer/alarm/evaluator/__init__.py | 4 ++-- ceilometer/alarm/notifier/__init__.py | 4 ++-- ceilometer/alarm/service.py | 4 ++-- ceilometer/collector/dispatcher/__init__.py | 4 ++-- ceilometer/compute/plugin.py | 4 ++-- ceilometer/plugin.py | 7 +++---- ceilometer/publisher/__init__.py | 4 ++-- ceilometer/storage/base.py | 7 +++---- ceilometer/tests/db.py | 3 ++- ceilometer/transformer/__init__.py | 5 +++-- 10 files changed, 23 insertions(+), 23 deletions(-) diff --git a/ceilometer/alarm/evaluator/__init__.py b/ceilometer/alarm/evaluator/__init__.py index 512965fdf..b2030d962 100644 --- a/ceilometer/alarm/evaluator/__init__.py +++ b/ceilometer/alarm/evaluator/__init__.py @@ -18,6 +18,7 @@ import abc +import six from oslo.config import cfg @@ -33,11 +34,10 @@ OK = 'ok' ALARM = 'alarm' +@six.add_metaclass(abc.ABCMeta) class Evaluator(object): """Base class for alarm rule evaluator plugins.""" - __metaclass__ = abc.ABCMeta - def __init__(self, notifier): self.notifier = notifier self.api_client = None diff --git a/ceilometer/alarm/notifier/__init__.py b/ceilometer/alarm/notifier/__init__.py index 5ac58e48a..ce155820e 100644 --- a/ceilometer/alarm/notifier/__init__.py +++ b/ceilometer/alarm/notifier/__init__.py @@ -17,13 +17,13 @@ # under the License. import abc +import six +@six.add_metaclass(abc.ABCMeta) class AlarmNotifier(object): """Base class for alarm notifier plugins.""" - __metaclass__ = abc.ABCMeta - @abc.abstractmethod def notify(self, action, alarm_id, previous, current, reason): """Notify that an alarm has been triggered. diff --git a/ceilometer/alarm/service.py b/ceilometer/alarm/service.py index a8e99a735..099e48376 100644 --- a/ceilometer/alarm/service.py +++ b/ceilometer/alarm/service.py @@ -19,6 +19,7 @@ # under the License. import abc +import six from oslo.config import cfg from stevedore import extension @@ -58,10 +59,9 @@ cfg.CONF.import_opt('partition_rpc_topic', 'ceilometer.alarm.rpc', LOG = log.getLogger(__name__) +@six.add_metaclass(abc.ABCMeta) class AlarmService(object): - __metaclass__ = abc.ABCMeta - EXTENSIONS_NAMESPACE = "ceilometer.alarm.evaluator" def _load_evaluators(self): diff --git a/ceilometer/collector/dispatcher/__init__.py b/ceilometer/collector/dispatcher/__init__.py index f9011053e..fff32b203 100644 --- a/ceilometer/collector/dispatcher/__init__.py +++ b/ceilometer/collector/dispatcher/__init__.py @@ -17,12 +17,12 @@ # under the License. import abc +import six +@six.add_metaclass(abc.ABCMeta) class Base(object): - __metaclass__ = abc.ABCMeta - def __init__(self, conf): self.conf = conf diff --git a/ceilometer/compute/plugin.py b/ceilometer/compute/plugin.py index 9603f1968..048ff2b0a 100644 --- a/ceilometer/compute/plugin.py +++ b/ceilometer/compute/plugin.py @@ -19,16 +19,16 @@ """ import abc +import six from ceilometer import plugin +@six.add_metaclass(abc.ABCMeta) class ComputePollster(plugin.PollsterBase): """Base class for plugins that support the polling API on the compute node. """ - __metaclass__ = abc.ABCMeta - @abc.abstractmethod def get_samples(self, manager, cache, instance): """Return a sequence of Counter instances from polling the resources. diff --git a/ceilometer/plugin.py b/ceilometer/plugin.py index 834027c2c..1cbcb7b84 100644 --- a/ceilometer/plugin.py +++ b/ceilometer/plugin.py @@ -22,6 +22,7 @@ import abc import collections import fnmatch from oslo.config import cfg +import six # Import this option so every Notification plugin can use it freely. cfg.CONF.import_opt('notification_topics', @@ -37,11 +38,10 @@ class PluginBase(object): """ +@six.add_metaclass(abc.ABCMeta) class NotificationBase(PluginBase): """Base class for plugins that support the notification API.""" - __metaclass__ = abc.ABCMeta - @abc.abstractproperty def event_types(self): """Return a sequence of strings defining the event types to be @@ -85,11 +85,10 @@ class NotificationBase(PluginBase): return [] +@six.add_metaclass(abc.ABCMeta) class PollsterBase(PluginBase): """Base class for plugins that support the polling API.""" - __metaclass__ = abc.ABCMeta - @abc.abstractmethod def get_samples(self, manager, cache): """Return a sequence of Counter instances from polling the resources. diff --git a/ceilometer/publisher/__init__.py b/ceilometer/publisher/__init__.py index df2b39e17..bda113835 100644 --- a/ceilometer/publisher/__init__.py +++ b/ceilometer/publisher/__init__.py @@ -21,6 +21,7 @@ import abc from stevedore import driver from ceilometer.openstack.common import network_utils +import six def get_publisher(url, namespace='ceilometer.publisher'): @@ -34,11 +35,10 @@ def get_publisher(url, namespace='ceilometer.publisher'): return loaded_driver.driver(parse_result) +@six.add_metaclass(abc.ABCMeta) class PublisherBase(object): """Base class for plugins that publish the sampler.""" - __metaclass__ = abc.ABCMeta - def __init__(self, parsed_url): pass diff --git a/ceilometer/storage/base.py b/ceilometer/storage/base.py index 7b59da80b..0715ca43e 100644 --- a/ceilometer/storage/base.py +++ b/ceilometer/storage/base.py @@ -21,6 +21,7 @@ import abc import datetime import math +import six from ceilometer.openstack.common import timeutils @@ -102,21 +103,19 @@ class Pagination(object): self.sort_dirs = sort_dirs +@six.add_metaclass(abc.ABCMeta) class StorageEngine(object): """Base class for storage engines.""" - __metaclass__ = abc.ABCMeta - @abc.abstractmethod def get_connection(self, conf): """Return a Connection instance based on the configuration settings.""" +@six.add_metaclass(abc.ABCMeta) class Connection(object): """Base class for storage system connections.""" - __metaclass__ = abc.ABCMeta - @abc.abstractmethod def __init__(self, conf): """Constructor.""" diff --git a/ceilometer/tests/db.py b/ceilometer/tests/db.py index 6a767cfe2..e1d9f9c6f 100644 --- a/ceilometer/tests/db.py +++ b/ceilometer/tests/db.py @@ -20,6 +20,7 @@ """Base classes for API tests.""" import os +import six import uuid import warnings @@ -78,8 +79,8 @@ class DB2FakeConnectionUrl(MongoDBFakeConnectionUrl): self.url = self.url.replace('mongodb:', 'db2:', 1) +@six.add_metaclass(test_base.SkipNotImplementedMeta) class MixinTestsWithBackendScenarios(object): - __metaclass__ = test_base.SkipNotImplementedMeta scenarios = [ ('sqlalchemy', dict(database_connection='sqlite://')), diff --git a/ceilometer/transformer/__init__.py b/ceilometer/transformer/__init__.py index acc4bc66c..0f9b0db76 100644 --- a/ceilometer/transformer/__init__.py +++ b/ceilometer/transformer/__init__.py @@ -17,6 +17,8 @@ # under the License. import abc +import six + from stevedore import extension @@ -35,11 +37,10 @@ class TransformerExtensionManager(extension.ExtensionManager): return self.by_name[name] +@six.add_metaclass(abc.ABCMeta) class TransformerBase(object): """Base class for plugins that transform the sample.""" - __metaclass__ = abc.ABCMeta - def __init__(self, **kwargs): """Setup transformer.