diff options
author | Monty Taylor <mordred@inaugust.com> | 2015-11-06 06:39:34 -0500 |
---|---|---|
committer | Monty Taylor <mordred@inaugust.com> | 2015-11-06 06:40:28 -0500 |
commit | 5b993208b97a459429bcb5f6fb852372c576cdaf (patch) | |
tree | d7decfa6e633456bfda5241ccd76e9fb9daee1d3 | |
parent | 1b91e007fdeda8703056d50abe431e167afb9e03 (diff) | |
download | os-client-config-5b993208b97a459429bcb5f6fb852372c576cdaf.tar.gz |
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
-rw-r--r-- | os_client_config/cloud_config.py | 10 | ||||
-rw-r--r-- | os_client_config/config.py | 6 | ||||
-rw-r--r-- | os_client_config/tests/base.py | 11 |
3 files changed, 19 insertions, 8 deletions
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) |