Refactor storage of runtime exclusive storage flag in QA
[ganeti-local] / autotools / build-rpc
index 33e9cfc..2de71d5 100755 (executable)
@@ -40,6 +40,9 @@ from ganeti import build
 _SINGLE = "single-node"
 _MULTI = "multi-node"
 
+#: Expected length of a rpc definition
+_RPC_DEF_LEN = 8
+
 
 def _WritePreamble(sw):
   """Writes a preamble for the RPC wrapper output.
@@ -77,7 +80,7 @@ def _WriteDocstring(sw, name, timeout, kind, args, desc):
     sw.Write("")
 
   note = ["This is a %s call" % kind]
-  if timeout:
+  if timeout and not callable(timeout):
     note.append(" with a timeout of %s" % utils.FormatSeconds(timeout))
   sw.Write("@note: %s", "".join(note))
 
@@ -117,7 +120,12 @@ def _WriteBaseClass(sw, clsname, calls):
     sw.Write("_CALLS = rpc_defs.CALLS[%r]", clsname)
     sw.Write("")
 
-    for (name, kind, timeout, args, _, desc) in calls:
+    for v in calls:
+      if len(v) != _RPC_DEF_LEN:
+        raise ValueError("Procedure %s has only %d elements, expected %d" %
+                         (v[0], len(v), _RPC_DEF_LEN))
+
+    for (name, kind, _, timeout, args, _, _, desc) in sorted(calls):
       funcargs = ["self"]
 
       if kind == _SINGLE:
@@ -129,9 +137,6 @@ def _WriteBaseClass(sw, clsname, calls):
 
       funcargs.extend(map(compat.fst, args))
 
-      assert "read_timeout" not in funcargs
-      funcargs.append("read_timeout=%s" % timeout)
-
       funcargs.append("_def=_CALLS[%r]" % name)
 
       funcdef = "def call_%s(%s):" % (name, utils.CommaJoin(funcargs))
@@ -146,7 +151,7 @@ def _WriteBaseClass(sw, clsname, calls):
         buf.write("return ")
 
         # In case line gets too long and is wrapped in a bad spot
-        buf.write("( ")
+        buf.write("(")
 
         buf.write("self._Call(_def, ")
         if kind == _SINGLE:
@@ -154,7 +159,7 @@ def _WriteBaseClass(sw, clsname, calls):
         else:
           buf.write("node_list")
 
-        buf.write(", read_timeout, [%s])" %
+        buf.write(", [%s])" %
                   # Function arguments
                   utils.CommaJoin(map(compat.fst, args)))
 
@@ -190,7 +195,13 @@ def main():
     assert module.SINGLE == _SINGLE
     assert module.MULTI == _MULTI
 
-    for (clsname, calls) in module.CALLS.items():
+    dups = utils.FindDuplicates(itertools.chain(*map(lambda value: value.keys(),
+                                                     module.CALLS.values())))
+    if dups:
+      raise Exception("Found duplicate RPC definitions for '%s'" %
+                      utils.CommaJoin(sorted(dups)))
+
+    for (clsname, calls) in sorted(module.CALLS.items()):
       _WriteBaseClass(sw, clsname, calls.values())
 
   print buf.getvalue()