Added abc.ABCMeta metaclass for abstract classes

Change-Id: I036148693a38fb1b0d1c298eb22d16e8d24ecacf
This commit is contained in:
Lianhao Lu 2014-01-23 15:18:39 +08:00
parent a00917a935
commit fb488286e0
5 changed files with 20 additions and 10 deletions

View File

@ -20,6 +20,8 @@ import abc
import collections
import itertools
import six
from ceilometer.openstack.common import context
from ceilometer.openstack.common import log
from ceilometer.openstack.common import service as os_service
@ -29,6 +31,7 @@ from ceilometer import transformer
LOG = log.getLogger(__name__)
@six.add_metaclass(abc.ABCMeta)
class PollingTask(object):
"""Polling task for polling samples and inject into pipeline.
A polling task can be invoked periodically or only once.
@ -56,6 +59,7 @@ class PollingTask(object):
"""Polling sample and publish into pipeline."""
@six.add_metaclass(abc.ABCMeta)
class AgentManager(os_service.Service):
def __init__(self, extension_manager):

View File

@ -21,6 +21,8 @@
import abc
import collections
import six
from ceilometer.compute import plugin
from ceilometer.compute.pollsters import util
from ceilometer.compute.virt import inspector as virt_inspector
@ -37,6 +39,7 @@ DiskIOData = collections.namedtuple(
)
@six.add_metaclass(abc.ABCMeta)
class _Base(plugin.ComputePollster):
DISKIO_USAGE_MESSAGE = ' '.join(["DISKIO USAGE:",

View File

@ -23,10 +23,10 @@ import abc
import datetime
import mock
import six
from stevedore import extension
from stevedore.tests import manager as extension_tests
from ceilometer import agent
from ceilometer.openstack.common.fixture import config
from ceilometer import pipeline
from ceilometer import plugin
@ -68,6 +68,7 @@ class TestPollsterException(TestPollster):
raise Exception()
@six.add_metaclass(abc.ABCMeta)
class BaseAgentManagerTestCase(base.BaseTestCase):
class Pollster(TestPollster):
@ -154,13 +155,13 @@ class BaseAgentManagerTestCase(base.BaseTestCase):
)
@abc.abstractmethod
def setup_manager(self):
"""Setup subclass specific managers."""
def create_manager(self):
"""Return subclass specific manager."""
@mock.patch('ceilometer.pipeline.setup_pipeline', mock.MagicMock())
def setUp(self):
super(BaseAgentManagerTestCase, self).setUp()
self.setup_manager()
self.mgr = self.create_manager()
self.mgr.pollster_manager = self.create_extension_manager()
self.pipeline_cfg = [{
'name': "test_pipeline",
@ -276,7 +277,8 @@ class BaseAgentManagerTestCase(base.BaseTestCase):
self.assertEqual(len(pub.samples), 0)
def test_agent_manager_start(self):
mgr = agent.AgentManager(self.mgr.pollster_manager)
mgr = self.create_manager()
mgr.pollster_manager = self.mgr.pollster_manager
mgr.create_polling_task = mock.MagicMock()
mgr.tg = mock.MagicMock()
mgr.start()

View File

@ -35,9 +35,9 @@ class TestManager(test.BaseTestCase):
class TestRunTasks(agentbase.BaseAgentManagerTestCase):
def setup_manager(self):
self.mgr = manager.AgentManager()
@staticmethod
def create_manager():
return manager.AgentManager()
def setUp(self):
super(TestRunTasks, self).setUp()

View File

@ -45,8 +45,9 @@ class TestRunTasks(agentbase.BaseAgentManagerTestCase):
def _raise_exception(self):
raise Exception
def setup_manager(self):
self.mgr = manager.AgentManager()
@staticmethod
def create_manager():
return manager.AgentManager()
@mock.patch('ceilometer.pipeline.setup_pipeline', mock.MagicMock())
def setUp(self):