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
This commit is contained in:
Mehdi Abaakouk 2013-10-23 13:51:35 +02:00
parent 6031964de2
commit 30ecd2f766
2 changed files with 14 additions and 5 deletions

View File

@ -118,7 +118,7 @@ class RPCPublisher(publisher.PublisherBase):
self.target = options.get('target', ['record_metering_data'])[0] 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( self.max_queue_length = int(options.get(
'max_queue_length', [1024])[-1]) 'max_queue_length', [1024])[-1])

View File

@ -19,9 +19,11 @@
"""Tests for ceilometer/publish.py """Tests for ceilometer/publish.py
""" """
import eventlet
import datetime import datetime
import eventlet
import mock
from ceilometer import sample from ceilometer import sample
from ceilometer.openstack.common import jsonutils from ceilometer.openstack.common import jsonutils
from ceilometer.openstack.common import network_utils from ceilometer.openstack.common import network_utils
@ -296,10 +298,13 @@ class TestPublish(test.BaseTestCase):
self.assertEqual(len(self.published), 2) self.assertEqual(len(self.published), 2)
self.assertEqual(len(publisher.local_queue), 0) 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 self.rpc_unreachable = True
publisher = rpc.RPCPublisher( publisher = rpc.RPCPublisher(
network_utils.urlsplit('rpc://')) network_utils.urlsplit('rpc://'))
self.assertTrue(mylog.info.called)
self.assertRaises( self.assertRaises(
SystemExit, SystemExit,
publisher.publish_samples, publisher.publish_samples,
@ -308,10 +313,12 @@ class TestPublish(test.BaseTestCase):
self.assertEqual(len(self.published), 0) self.assertEqual(len(self.published), 0)
self.assertEqual(len(publisher.local_queue), 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 self.rpc_unreachable = True
publisher = rpc.RPCPublisher( publisher = rpc.RPCPublisher(
network_utils.urlsplit('rpc://?policy=default')) network_utils.urlsplit('rpc://?policy=default'))
self.assertTrue(mylog.info.called)
self.assertRaises( self.assertRaises(
SystemExit, SystemExit,
publisher.publish_samples, publisher.publish_samples,
@ -319,7 +326,8 @@ class TestPublish(test.BaseTestCase):
self.assertEqual(len(self.published), 0) self.assertEqual(len(self.published), 0)
self.assertEqual(len(publisher.local_queue), 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 self.rpc_unreachable = True
publisher = rpc.RPCPublisher( publisher = rpc.RPCPublisher(
network_utils.urlsplit('rpc://?policy=notexist')) network_utils.urlsplit('rpc://?policy=notexist'))
@ -327,6 +335,7 @@ class TestPublish(test.BaseTestCase):
SystemExit, SystemExit,
publisher.publish_samples, publisher.publish_samples,
None, self.test_data) None, self.test_data)
self.assertTrue(mylog.warn.called)
self.assertEqual(publisher.policy, 'default') self.assertEqual(publisher.policy, 'default')
self.assertEqual(len(self.published), 0) self.assertEqual(len(self.published), 0)
self.assertEqual(len(publisher.local_queue), 0) self.assertEqual(len(publisher.local_queue), 0)