403b09
From 5138ff563b1ac870ecc77485c200d839e17622a8 Mon Sep 17 00:00:00 2001
403b09
From: David Kupka <dkupka@redhat.com>
403b09
Date: Thu, 4 Aug 2016 16:07:08 +0200
403b09
Subject: [PATCH] schema cache: Do not read fingerprint and format from cache
403b09
403b09
Fingerprint can be obtained from schema filename of from ServerInfo
403b09
instance. Use FORMAT in path to avoid openening schema just to read its
403b09
format.
403b09
403b09
https://fedorahosted.org/freeipa/ticket/6048
403b09
403b09
Reviewed-By: Jan Cholasta <jcholast@redhat.com>
403b09
---
403b09
 ipaclient/remote_plugins/schema.py | 29 +++++------------------------
403b09
 1 file changed, 5 insertions(+), 24 deletions(-)
403b09
403b09
diff --git a/ipaclient/remote_plugins/schema.py b/ipaclient/remote_plugins/schema.py
403b09
index b49ccbb7f7905e2561598d66beca6d8b1d5ed48e..c62b74408b448faf794ed9e2b315b03fc1a5a315 100644
403b09
--- a/ipaclient/remote_plugins/schema.py
403b09
+++ b/ipaclient/remote_plugins/schema.py
403b09
@@ -19,6 +19,7 @@ from ipalib import errors, parameters, plugable
403b09
 from ipalib.frontend import Object
403b09
 from ipalib.output import Output
403b09
 from ipalib.parameters import DefaultFrom, Flag, Password, Str
403b09
+from ipapython.ipautil import fsdecode
403b09
 from ipapython.dn import DN
403b09
 from ipapython.dnsutil import DNSName
403b09
 from ipapython.ipa_log_manager import log_mgr
403b09
@@ -437,7 +438,7 @@ class Schema(object):
403b09
 
403b09
     """
403b09
     namespaces = {'classes', 'commands', 'topics'}
403b09
-    _DIR = os.path.join(USER_CACHE_PATH, 'ipa', 'schema')
403b09
+    _DIR = os.path.join(USER_CACHE_PATH, 'ipa', 'schema', FORMAT)
403b09
 
403b09
     def __init__(self, api, server_info, client):
403b09
         self._dict = {}
403b09
@@ -483,34 +484,14 @@ class Schema(object):
403b09
         path = os.path.join(self._DIR, filename)
403b09
         return _LockedZipFile(path, mode)
403b09
 
403b09
-    def _get_schema_fingerprint(self, schema):
403b09
-        try:
403b09
-            fmt = json.loads(schema.read('format'))
403b09
-        except KeyError:
403b09
-            fmt = '0'
403b09
-
403b09
-        if fmt != FORMAT:
403b09
-            raise RuntimeError('invalid format')
403b09
-
403b09
-        return json.loads(schema.read('fingerprint'))
403b09
-
403b09
     def _fetch(self, client):
403b09
         if not client.isconnected():
403b09
             client.connect(verbose=False)
403b09
 
403b09
-        fps = []
403b09
         try:
403b09
-            files = os.listdir(self._DIR)
403b09
+            fps = [fsdecode(f) for f in os.listdir(self._DIR)]
403b09
         except EnvironmentError:
403b09
-            pass
403b09
-        else:
403b09
-            for filename in files:
403b09
-                try:
403b09
-                    with self._open_schema(filename, 'r') as schema:
403b09
-                        fps.append(
403b09
-                            unicode(self._get_schema_fingerprint(schema)))
403b09
-                except Exception:
403b09
-                    continue
403b09
+            fps = []
403b09
 
403b09
         kwargs = {u'version': u'2.170'}
403b09
         if fps:
403b09
@@ -537,7 +518,7 @@ class Schema(object):
403b09
 
403b09
     def _read_schema(self):
403b09
         with self._open_schema(self._fingerprint, 'r') as schema:
403b09
-            self._dict['fingerprint'] = self._get_schema_fingerprint(schema)
403b09
+            self._dict['fingerprint'] = self._fingerprint
403b09
 
403b09
             for name in schema.namelist():
403b09
                 ns, _slash, key = name.partition('/')
403b09
-- 
403b09
2.7.4
403b09