Change pipeline_manager to instance attribute in hooks

We should not assume the type of object which pecan.make_app() return
because it varies based on different configuration settings during the
test.

In order to achieve this, we have to change the PipelineHook's class
attribute pipeline_manager to be instance attribute, otherwise,
different api server created for different DB back-end would end up
sharing the same pipeline_manager which would break test tests.

(Failing unit tests in gate, manually booting it out. Please *DONT*
run recheck no bug on unit test failures).

Change-Id: Ic4370b1b8bec5723a0d719c74bdcdad8a6552912
Closes-Bug: #1327032
This commit is contained in:
Lianhao Lu 2014-06-05 10:57:15 +08:00 committed by Sean Dague
parent 2b562814cc
commit 524200dc4b
2 changed files with 11 additions and 20 deletions

View File

@ -48,13 +48,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

View File

@ -36,25 +36,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',