diff --git a/os_client_config/cloud_config.py b/os_client_config/cloud_config.py index 8e0b963..79a6ebf 100644 --- a/os_client_config/cloud_config.py +++ b/os_client_config/cloud_config.py @@ -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]) diff --git a/os_client_config/config.py b/os_client_config/config.py index fd28c69..8d2a2ee 100644 --- a/os_client_config/config.py +++ b/os_client_config/config.py @@ -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 diff --git a/os_client_config/tests/base.py b/os_client_config/tests/base.py index 67c80f2..3d94e25 100644 --- a/os_client_config/tests/base.py +++ b/os_client_config/tests/base.py @@ -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)