Merge "Remove unnecessary wrapping of transformer ExtentionManager"

This commit is contained in:
Jenkins 2015-06-24 02:15:11 +00:00 committed by Gerrit Code Review
commit bd1996de17
7 changed files with 13 additions and 39 deletions

View File

@ -23,11 +23,11 @@ import sys
from oslo_config import cfg from oslo_config import cfg
from oslo_context import context from oslo_context import context
from oslo_utils import timeutils from oslo_utils import timeutils
from stevedore import extension
from ceilometer import pipeline from ceilometer import pipeline
from ceilometer import sample from ceilometer import sample
from ceilometer import service from ceilometer import service
from ceilometer import transformer
def send_sample(): def send_sample():
@ -79,10 +79,7 @@ def send_sample():
root_logger.setLevel(logging.DEBUG) root_logger.setLevel(logging.DEBUG)
pipeline_manager = pipeline.setup_pipeline( pipeline_manager = pipeline.setup_pipeline(
transformer.TransformerExtensionManager( extension.ExtensionManager('ceilometer.transformer'))
'ceilometer.transformer',
),
)
with pipeline_manager.publisher(context.get_admin_context()) as p: with pipeline_manager.publisher(context.get_admin_context()) as p:
p([sample.Sample( p([sample.Sample(

View File

@ -19,7 +19,6 @@ from stevedore import extension
from ceilometer.i18n import _ from ceilometer.i18n import _
from ceilometer import pipeline from ceilometer import pipeline
from ceilometer import transformer
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
@ -51,7 +50,7 @@ def _load_pipeline_manager():
global _pipeline_manager global _pipeline_manager
_pipeline_manager = pipeline.setup_pipeline( _pipeline_manager = pipeline.setup_pipeline(
transformer.TransformerExtensionManager( extension.ExtensionManager(
'ceilometer.transformer', 'ceilometer.transformer',
), ),
) )

View File

@ -25,14 +25,15 @@ from oslo_config import cfg
from oslo_log import log from oslo_log import log
from oslo_utils import timeutils from oslo_utils import timeutils
import six import six
from stevedore import extension
import yaml import yaml
from ceilometer.event.storage import models from ceilometer.event.storage import models
from ceilometer.i18n import _ from ceilometer.i18n import _
from ceilometer import publisher from ceilometer import publisher
from ceilometer.publisher import utils as publisher_utils from ceilometer.publisher import utils as publisher_utils
from ceilometer import sample as sample_util from ceilometer import sample as sample_util
from ceilometer import transformer as xformer
OPTS = [ OPTS = [
@ -376,7 +377,7 @@ class Sink(object):
for transformer in self.transformer_cfg: for transformer in self.transformer_cfg:
parameter = transformer['parameters'] or {} parameter = transformer['parameters'] or {}
try: try:
ext = transformer_manager.get_ext(transformer['name']) ext = transformer_manager[transformer['name']]
except KeyError: except KeyError:
raise PipelineException( raise PipelineException(
"No transformer named %s loaded" % transformer['name'], "No transformer named %s loaded" % transformer['name'],
@ -732,7 +733,7 @@ def _setup_pipeline_manager(cfg_file, transformer_manager, p_type=SAMPLE_TYPE):
return PipelineManager(pipeline_cfg, return PipelineManager(pipeline_cfg,
transformer_manager or transformer_manager or
xformer.TransformerExtensionManager( extension.ExtensionManager(
'ceilometer.transformer', 'ceilometer.transformer',
), p_type) ), p_type)

View File

@ -37,7 +37,6 @@ from ceilometer import publisher
from ceilometer.publisher import test as test_publisher from ceilometer.publisher import test as test_publisher
from ceilometer import sample from ceilometer import sample
from ceilometer.tests import base from ceilometer.tests import base
from ceilometer import transformer
from ceilometer import utils from ceilometer import utils
@ -173,7 +172,7 @@ class BaseAgentManagerTestCase(base.BaseTestCase):
params = [] params = []
def setup_pipeline(self): def setup_pipeline(self):
self.transformer_manager = transformer.TransformerExtensionManager( self.transformer_manager = extension.ExtensionManager(
'ceilometer.transformer', 'ceilometer.transformer',
) )
self.mgr.pipeline_manager = pipeline.PipelineManager( self.mgr.pipeline_manager = pipeline.PipelineManager(

View File

@ -138,18 +138,12 @@ class BasePipelineTestCase(base.BaseTestCase):
resource_metadata={} resource_metadata={}
) )
self.useFixture(mockpatch.PatchObject(
transformer.TransformerExtensionManager, "__init__",
side_effect=self.fake_tem_init))
self.useFixture(mockpatch.PatchObject(
transformer.TransformerExtensionManager, "get_ext",
side_effect=self.fake_tem_get_ext))
self.useFixture(mockpatch.PatchObject( self.useFixture(mockpatch.PatchObject(
publisher, 'get_publisher', side_effect=self.get_publisher)) publisher, 'get_publisher', side_effect=self.get_publisher))
self.transformer_manager = transformer.TransformerExtensionManager() self.transformer_manager = mock.MagicMock()
self.transformer_manager.__getitem__.side_effect = \
self.fake_tem_get_ext
self._setup_pipeline_cfg() self._setup_pipeline_cfg()

View File

@ -15,10 +15,10 @@
"""Tests for ceilometer/notifier.py """Tests for ceilometer/notifier.py
""" """
from oslotest import base from oslotest import base
from stevedore import extension
from ceilometer import notifier from ceilometer import notifier
from ceilometer import pipeline from ceilometer import pipeline
from ceilometer import transformer
MESSAGE = { MESSAGE = {
@ -64,7 +64,7 @@ MESSAGE = {
class TestNotifier(base.BaseTestCase): class TestNotifier(base.BaseTestCase):
def test_process_notification(self): def test_process_notification(self):
transformer_manager = transformer.TransformerExtensionManager( transformer_manager = extension.ExtensionManager(
'ceilometer.transformer', 'ceilometer.transformer',
) )
notifier._pipeline_manager = pipeline.PipelineManager( notifier._pipeline_manager = pipeline.PipelineManager(

View File

@ -17,22 +17,6 @@ import abc
import collections import collections
import six import six
from stevedore import extension
class TransformerExtensionManager(extension.ExtensionManager):
def __init__(self, namespace):
super(TransformerExtensionManager, self).__init__(
namespace=namespace,
invoke_on_load=False,
invoke_args=(),
invoke_kwds={}
)
self.by_name = dict((e.name, e) for e in self.extensions)
def get_ext(self, name):
return self.by_name[name]
@six.add_metaclass(abc.ABCMeta) @six.add_metaclass(abc.ABCMeta)