Merge "Cast time-to-live values to int"

This commit is contained in:
Jenkins 2017-05-15 13:21:42 +00:00 committed by Gerrit Code Review
commit cf70a3ab26
2 changed files with 23 additions and 2 deletions

View File

@ -95,12 +95,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

View File

@ -134,6 +134,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']