diff --git a/ceilometer/api/hooks.py b/ceilometer/api/hooks.py index 8974427da..76df07700 100644 --- a/ceilometer/api/hooks.py +++ b/ceilometer/api/hooks.py @@ -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 diff --git a/ceilometer/tests/api/v2/test_post_samples_scenarios.py b/ceilometer/tests/api/v2/test_post_samples_scenarios.py index 3140cdc3e..cc623a59a 100644 --- a/ceilometer/tests/api/v2/test_post_samples_scenarios.py +++ b/ceilometer/tests/api/v2/test_post_samples_scenarios.py @@ -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',