Cast time-to-live values to int
For large integer values, Juju can choose to return the number in scientific notation. This causes the python code loading the config data to return a floating point number instead of an integer. Floating point values in ceilometer's configuration file will prevent ceilometer from starting. This change forces the type to an integer, allowing users to specify large ttl values. Change-Id: I8e29e6868b4c4a4ae20ad87ab585508fd321261c Closes-Bug: #1651645
This commit is contained in:
parent
f36d6e5cb1
commit
09bb38e488
|
@ -91,12 +91,17 @@ class CeilometerContext(OSContextGenerator):
|
|||
# Lazy-import to avoid a circular dependency in the imports
|
||||
from ceilometer_utils import get_shared_secret
|
||||
|
||||
# Make sure to cast the time-to-live events to integer values.
|
||||
# For large enough numbers, Juju returns the value in scientific
|
||||
# notation which causes python to treat the number as a float
|
||||
# value, which in turn causes ceilometer to fail to start.
|
||||
# See LP#1651645 for more details.
|
||||
ctxt = {
|
||||
'port': CEILOMETER_PORT,
|
||||
'metering_secret': get_shared_secret(),
|
||||
'api_workers': config('api-workers'),
|
||||
'metering_time_to_live': config('metering-time-to-live'),
|
||||
'event_time_to_live': config('event-time-to-live'),
|
||||
'metering_time_to_live': int(config('metering-time-to-live')),
|
||||
'event_time_to_live': int(config('event-time-to-live')),
|
||||
}
|
||||
return ctxt
|
||||
|
||||
|
|
|
@ -133,6 +133,22 @@ class CeilometerContextsTest(CharmTestCase):
|
|||
'event_time_to_live': -1,
|
||||
})
|
||||
|
||||
@patch.object(utils, 'get_shared_secret')
|
||||
def test_ceilometer_context_ttl_values(self, secret):
|
||||
secret.return_value = 'mysecret'
|
||||
self.test_config.set('metering-time-to-live', 7.776e+06)
|
||||
self.test_config.set('event-time-to-live', 7.776e+06)
|
||||
context = contexts.CeilometerContext()()
|
||||
self.assertEquals(context, {
|
||||
'port': 8777,
|
||||
'metering_secret': 'mysecret',
|
||||
'api_workers': 1,
|
||||
'metering_time_to_live': 7776000,
|
||||
'event_time_to_live': 7776000,
|
||||
})
|
||||
self.assertTrue(type(context['metering_time_to_live']) is int)
|
||||
self.assertTrue(type(context['event_time_to_live']) is int)
|
||||
|
||||
def test_ceilometer_service_context(self):
|
||||
self.relation_ids.return_value = ['ceilometer-service:0']
|
||||
self.related_units.return_value = ['ceilometer/0']
|
||||
|
|
Loading…
Reference in New Issue