[Kimchi-devel] [PATCH][Wok] Return collection list without resource with lookup problems

Rodrigo Trujillo rodrigo.trujillo at linux.vnet.ibm.com
Thu Apr 21 04:59:49 UTC 2016


When a collection receives a GET request, it is going to fetch all
resources names, in a list,  and perform a lookup for each resource,
building the return list with all data.
There is a potencial race condition problem in this approach. If a
given resource is removed between list of names creation and its
lookup call, wok is going to fail and the exception is not treated.
This patch fix this problem catching the exception, logging the problem
and completing the GET request. So, the resource with problem is
discarted and other resources are returned.

Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo at linux.vnet.ibm.com>
---
 src/wok/control/base.py | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/wok/control/base.py b/src/wok/control/base.py
index 7aeb844..f314d18 100644
--- a/src/wok/control/base.py
+++ b/src/wok/control/base.py
@@ -34,7 +34,7 @@ from wok.exception import InvalidOperation, InvalidParameter
 from wok.exception import MissingParameter, NotFoundError
 from wok.exception import OperationFailed, UnauthorizedError, WokException
 from wok.reqlogger import RequestRecord
-from wok.utils import get_plugin_from_request, utf8_dict
+from wok.utils import get_plugin_from_request, utf8_dict, wok_log
 
 
 # Default request log messages
@@ -364,7 +364,14 @@ class Collection(object):
                 # internal text, get_list changes ident to unicode for sorted
                 args = self.resource_args + [ident]
                 res = self.resource(self.model, *args)
-                res.lookup()
+                try:
+                    res.lookup()
+                except Exception as e:
+                    # In case of errors when fetching a resource info, pass and
+                    # log the error, so, other resources are returned
+                    wok_log.error("Problem in lookup of resource '%s'. "
+                                  "Detail: %s" % (ident, e.message))
+                    continue
                 res_list.append(res)
             return res_list
         except AttributeError:
-- 
2.1.0




More information about the Kimchi-devel mailing list