From 30ecd2f76633b8854401c6254210aaa5a7920be0 Mon Sep 17 00:00:00 2001 From: Mehdi Abaakouk Date: Wed, 23 Oct 2013 13:51:35 +0200 Subject: [PATCH] Fix the default rpc policy value Before, each time a service that use ceilometer.publisher.rpc start this annoying message appear because the default value is not the correct. WARNING ceilometer.publisher.rpc [-] Publishing policy is unknown (wait) force to default WARNING ceilometer.publisher.rpc [-] Publishing policy is unknown (wait) force to default This patch set the correct default (to default inteads of wait), and check in tests that the expected logger method is called. Fixes bug #1245965 Change-Id: I41b9461359c7b0b17eb8e9dad1772bafdc3554fc --- ceilometer/publisher/rpc.py | 2 +- tests/publisher/test_rpc_publisher.py | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/ceilometer/publisher/rpc.py b/ceilometer/publisher/rpc.py index 99f22a859..892eca46a 100644 --- a/ceilometer/publisher/rpc.py +++ b/ceilometer/publisher/rpc.py @@ -118,7 +118,7 @@ class RPCPublisher(publisher.PublisherBase): self.target = options.get('target', ['record_metering_data'])[0] - self.policy = options.get('policy', ['wait'])[-1] + self.policy = options.get('policy', ['default'])[-1] self.max_queue_length = int(options.get( 'max_queue_length', [1024])[-1]) diff --git a/tests/publisher/test_rpc_publisher.py b/tests/publisher/test_rpc_publisher.py index 853eb525c..0e622d691 100644 --- a/tests/publisher/test_rpc_publisher.py +++ b/tests/publisher/test_rpc_publisher.py @@ -19,9 +19,11 @@ """Tests for ceilometer/publish.py """ -import eventlet import datetime +import eventlet +import mock + from ceilometer import sample from ceilometer.openstack.common import jsonutils from ceilometer.openstack.common import network_utils @@ -296,10 +298,13 @@ class TestPublish(test.BaseTestCase): self.assertEqual(len(self.published), 2) self.assertEqual(len(publisher.local_queue), 0) - def test_published_with_no_policy(self): + @mock.patch('ceilometer.publisher.rpc.LOG') + def test_published_with_no_policy(self, mylog): self.rpc_unreachable = True publisher = rpc.RPCPublisher( network_utils.urlsplit('rpc://')) + self.assertTrue(mylog.info.called) + self.assertRaises( SystemExit, publisher.publish_samples, @@ -308,10 +313,12 @@ class TestPublish(test.BaseTestCase): self.assertEqual(len(self.published), 0) self.assertEqual(len(publisher.local_queue), 0) - def test_published_with_policy_block(self): + @mock.patch('ceilometer.publisher.rpc.LOG') + def test_published_with_policy_block(self, mylog): self.rpc_unreachable = True publisher = rpc.RPCPublisher( network_utils.urlsplit('rpc://?policy=default')) + self.assertTrue(mylog.info.called) self.assertRaises( SystemExit, publisher.publish_samples, @@ -319,7 +326,8 @@ class TestPublish(test.BaseTestCase): self.assertEqual(len(self.published), 0) self.assertEqual(len(publisher.local_queue), 0) - def test_published_with_policy_incorrect(self): + @mock.patch('ceilometer.publisher.rpc.LOG') + def test_published_with_policy_incorrect(self, mylog): self.rpc_unreachable = True publisher = rpc.RPCPublisher( network_utils.urlsplit('rpc://?policy=notexist')) @@ -327,6 +335,7 @@ class TestPublish(test.BaseTestCase): SystemExit, publisher.publish_samples, None, self.test_data) + self.assertTrue(mylog.warn.called) self.assertEqual(publisher.policy, 'default') self.assertEqual(len(self.published), 0) self.assertEqual(len(publisher.local_queue), 0)