Return cache settings as numbers not strings

While we're at it, let's also put in some tests to ensure that we're
processing data types properly.

Change-Id: I0442d234e8422a58738612b2da114f61cc9afc5c
This commit is contained in:
Monty Taylor 2015-11-06 06:39:34 -05:00
parent 1b91e007fd
commit 5b993208b9
3 changed files with 19 additions and 8 deletions

View File

@ -299,15 +299,17 @@ class CloudConfig(object):
if self._openstack_config:
return self._openstack_config.get_cache_expiration()
def get_cache_resource_expiration(self, resource):
def get_cache_resource_expiration(self, resource, default=None):
"""Get expiration time for a resource
:param resource: Name of the resource type
:param default: Default value to return if not found (optional,
defaults to None)
:returns: Expiration time for the resource type or None
:returns: Expiration time for the resource type as float or default
"""
if self._openstack_config:
expiration = self._openstack_config.get_cache_expiration()
if resource not in expiration:
return None
return expiration[resource]
return default
return float(expiration[resource])

View File

@ -246,13 +246,13 @@ class OpenStackConfig(object):
return new_config
def get_cache_expiration_time(self):
return self._cache_expiration_time
return int(self._cache_expiration_time)
def get_cache_interval(self):
return self._cache_expiration_time
return self.get_cache_expiration_time()
def get_cache_max_age(self):
return self._cache_expiration_time
return self.get_cache_expiration_time()
def get_cache_path(self):
return self._cache_path

View File

@ -39,6 +39,13 @@ VENDOR_CONF = {
}
}
USER_CONF = {
'cache': {
'max_age': '1',
'expiration': {
'server': 5,
'image': '7',
},
},
'client': {
'force_ipv4': True,
},
@ -104,7 +111,6 @@ USER_CONF = {
'region_name': 'test-region',
}
},
'cache': {'max_age': 1},
}
NO_CONF = {
'cache': {'max_age': 1},
@ -155,3 +161,6 @@ class TestCase(base.BaseTestCase):
self.assertEqual('testproject', cc.auth['project_name'])
elif 'project_id' in cc.auth:
self.assertEqual('testproject', cc.auth['project_id'])
self.assertEqual(cc.get_cache_expiration_time(), 1)
self.assertEqual(cc.get_cache_resource_expiration('server'), 5.0)
self.assertEqual(cc.get_cache_resource_expiration('image'), 7.0)