From 524200dc4bc39487b4cd4c9298b004238e248244 Mon Sep 17 00:00:00 2001 From: Lianhao Lu Date: Thu, 5 Jun 2014 10:57:15 +0800 Subject: [PATCH] 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 --- ceilometer/api/hooks.py | 9 +++----- .../api/v2/test_post_samples_scenarios.py | 22 +++++++------------ 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/ceilometer/api/hooks.py b/ceilometer/api/hooks.py index 757482df4..de83e572d 100644 --- a/ceilometer/api/hooks.py +++ b/ceilometer/api/hooks.py @@ -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 diff --git a/ceilometer/tests/api/v2/test_post_samples_scenarios.py b/ceilometer/tests/api/v2/test_post_samples_scenarios.py index 925fdfcd9..8526e2222 100644 --- a/ceilometer/tests/api/v2/test_post_samples_scenarios.py +++ b/ceilometer/tests/api/v2/test_post_samples_scenarios.py @@ -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',