(2.10) RAPI: Pass depends body arg (if any) to opcode
authorDimitris Aragiorgis <dimara@grnet.gr>
Thu, 14 Nov 2013 12:10:52 +0000 (14:10 +0200)
committerDimitris Aragiorgis <dimara@grnet.gr>
Thu, 27 Mar 2014 07:57:08 +0000 (09:57 +0200)
Most rlib2 classes override the default _GetDefaultData() method with
custom methods that parse a request's body and query args and return a
(body, specific_static) tuple eventually passed to FillOpCode().
Job dependencies are defined in the `depends` body argument that might
get lost because most of those methods return {} as the body. In order
not to modify every custom method we update the returned body with
the `depends` argument of the original request body for all RAPI calls
inside OpcodeResource._GenericHandler(). It's up to the client to
include the `depends` argument with the job dependencies if desired.

Signed-off-by: Dimitris Aragiorgis <dimara@grnet.gr>
Reviewed-by: Hrvoje Ribicic <riba@google.com>

lib/rapi/baserlib.py

index c396f98..f65954c 100644 (file)
@@ -462,6 +462,12 @@ class OpcodeResource(ResourceBase):
   method to do their own opcode input processing (e.g. for static values). The
   C{$METHOD$_RENAME} variable defines which values are renamed (see
   L{baserlib.FillOpcode}).
+  Still default behavior cannot be totally overriden. There are opcode params
+  that are available to all opcodes, e.g. "depends". In case those params
+  (currently only "depends") are found in the original request's body, they are
+  added to the dictionary of parsed parameters and eventually passed to the
+  opcode. If the parsed body is not represented as a dictionary object, the
+  values are not added.
 
   @cvar GET_OPCODE: Set this to a class derived from L{opcodes.OpCode} to
     automatically generate a GET handler submitting the opcode
@@ -528,8 +534,18 @@ class OpcodeResource(ResourceBase):
       }
     return common_static
 
+  def _GetDepends(self):
+    ret = {}
+    if isinstance(self.request_body, dict):
+      depends = self.getBodyParameter("depends", None)
+      if depends:
+        ret.update({"depends": depends})
+    return ret
+
   def _GenericHandler(self, opcode, rename, fn):
     (body, specific_static) = fn()
+    if isinstance(body, dict):
+      body.update(self._GetDepends())
     static = self._GetCommonStatic()
     if specific_static:
       static.update(specific_static)