summaryrefslogtreecommitdiffstats
path: root/ipaclient/remote_plugins
diff options
context:
space:
mode:
authorDavid Kupka <dkupka@redhat.com>2016-08-16 15:32:47 +0200
committerJan Cholasta <jcholast@redhat.com>2016-08-17 14:16:04 +0200
commitf2c26119f5bb0e45c3d85c9b13150ba503f492e8 (patch)
treeed50a6d8ce67cbd7a9a3181fe0f771f7ea27717b /ipaclient/remote_plugins
parent1b79ac67d709bbb9e665f0e741af89828281477d (diff)
downloadfreeipa-f2c26119f5bb0e45c3d85c9b13150ba503f492e8.tar.gz
freeipa-f2c26119f5bb0e45c3d85c9b13150ba503f492e8.tar.xz
freeipa-f2c26119f5bb0e45c3d85c9b13150ba503f492e8.zip
schema cache: Read schema instead of rewriting it when SchemaUpToDate
https://fedorahosted.org/freeipa/ticket/6048 Reviewed-By: Jan Cholasta <jcholast@redhat.com>
Diffstat (limited to 'ipaclient/remote_plugins')
-rw-r--r--ipaclient/remote_plugins/schema.py46
1 files changed, 24 insertions, 22 deletions
diff --git a/ipaclient/remote_plugins/schema.py b/ipaclient/remote_plugins/schema.py
index 0a4c88bed..4b03e0d3e 100644
--- a/ipaclient/remote_plugins/schema.py
+++ b/ipaclient/remote_plugins/schema.py
@@ -17,6 +17,7 @@ import six
from ipaclient.frontend import ClientCommand, ClientMethod
from ipalib import errors, parameters, plugable
+from ipalib.errors import SchemaUpToDate
from ipalib.frontend import Object
from ipalib.output import Output
from ipalib.parameters import DefaultFrom, Flag, Password, Str
@@ -369,15 +370,14 @@ class Schema(object):
self._dict[ns] = {}
self._namespaces[ns] = _SchemaNameSpace(self, ns)
- is_known = False
- if not api.env.force_schema_check:
- try:
- self._fingerprint = server_info['fingerprint']
- self._expiration = server_info['expiration']
- except KeyError:
- pass
- else:
- is_known = True
+ try:
+ self._fingerprint = server_info['fingerprint']
+ self._expiration = server_info['expiration']
+ except KeyError:
+ is_known = False
+ else:
+ is_known = (not api.env.force_schema_check and
+ self._expiration > time.time())
if is_known:
try:
@@ -391,14 +391,15 @@ class Schema(object):
self._fetch(client)
except NotAvailable:
raise
+ except SchemaUpToDate as e:
+ self._fingerprint = e.fingerprint
+ self._expiration = time.time() + e.ttl
+ self._read_schema()
else:
self._write_schema()
- finally:
- try:
- server_info['fingerprint'] = self._fingerprint
- server_info['expiration'] = self._expiration
- except AttributeError:
- pass
+
+ server_info['fingerprint'] = self._fingerprint
+ server_info['expiration'] = self._expiration
@contextlib.contextmanager
def _open(self, filename, mode):
@@ -431,21 +432,22 @@ class Schema(object):
schema = client.forward(u'schema', **kwargs)['result']
except errors.CommandError:
raise NotAvailable()
- except errors.SchemaUpToDate as e:
- fp = e.fingerprint
- ttl = e.ttl
- else:
+
+ try:
fp = schema['fingerprint']
- ttl = schema.pop('ttl', 0)
- schema.pop('version', None)
+ ttl = schema.pop('ttl')
+ schema.pop('version')
for key, value in schema.items():
if key in self.namespaces:
value = {m['full_name']: m for m in value}
self._dict[key] = value
+ except KeyError as e:
+ logger.warning("Failed to fetch schema: %s", e)
+ raise NotAvailable()
self._fingerprint = fp
- self._expiration = ttl + time.time()
+ self._expiration = time.time() + ttl
def _read_schema(self):
self._file.truncate(0)