Merge "Change pipeline_manager to instance attribute in hooks"
This commit is contained in:
commit
715f1e2e0d
@ -47,13 +47,10 @@ class PipelineHook(hooks.PecanHook):
|
||||
new samples can be posted via the /v2/meters/ API.
|
||||
'''
|
||||
|
||||
pipeline_manager = None
|
||||
|
||||
def __init__(self):
|
||||
if self.__class__.pipeline_manager is None:
|
||||
# this is done here as the cfg options are not available
|
||||
# when the file is imported.
|
||||
self.__class__.pipeline_manager = pipeline.setup_pipeline()
|
||||
# this is done here as the cfg options are not available
|
||||
# when the file is imported.
|
||||
self.pipeline_manager = pipeline.setup_pipeline()
|
||||
|
||||
def before(self, state):
|
||||
state.request.pipeline_manager = self.pipeline_manager
|
||||
|
@ -35,25 +35,19 @@ class TestPostSamples(FunctionalTest,
|
||||
del m['message_signature']
|
||||
self.published.append(data)
|
||||
|
||||
def patch_publishers(self):
|
||||
def fake_get_rpc_client(self, **kwargs):
|
||||
cast_ctxt = mock.Mock()
|
||||
cast_ctxt.cast.side_effect = self.fake_cast
|
||||
found = False
|
||||
pipeline_hook = self.app.app.application.app.hooks[2]
|
||||
for pipeline in pipeline_hook.pipeline_manager.pipelines:
|
||||
for publisher in pipeline.publishers:
|
||||
if hasattr(publisher, 'rpc_client'):
|
||||
self.useFixture(mockpatch.PatchObject(
|
||||
publisher.rpc_client, 'prepare',
|
||||
return_value=cast_ctxt))
|
||||
found = True
|
||||
if not found:
|
||||
raise Exception('fail to patch the rpc publisher')
|
||||
client = mock.Mock()
|
||||
client.prepare.return_value = cast_ctxt
|
||||
return client
|
||||
|
||||
def setUp(self):
|
||||
super(TestPostSamples, self).setUp()
|
||||
self.published = []
|
||||
self.patch_publishers()
|
||||
self.useFixture(mockpatch.Patch(
|
||||
'ceilometer.messaging.get_rpc_client',
|
||||
new=self.fake_get_rpc_client))
|
||||
super(TestPostSamples, self).setUp()
|
||||
|
||||
def test_one(self):
|
||||
s1 = [{'counter_name': 'apples',
|
||||
|
Loading…
x
Reference in New Issue
Block a user