Skip to content
Snippets Groups Projects
Commit f7d9b3aa authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

RPC/test_delay: Use callable for timeout calculation


This avoids having to override the function in the RPC runner.

Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarRené Nussbaumer <rn@google.com>
parent 26d502d0
No related branches found
No related tags found
No related merge requests found
...@@ -129,9 +129,6 @@ def _WriteBaseClass(sw, clsname, calls): ...@@ -129,9 +129,6 @@ def _WriteBaseClass(sw, clsname, calls):
funcargs.extend(map(compat.fst, args)) funcargs.extend(map(compat.fst, args))
assert "read_timeout" not in funcargs
funcargs.append("read_timeout=%s" % timeout)
funcargs.append("_def=_CALLS[%r]" % name) funcargs.append("_def=_CALLS[%r]" % name)
funcdef = "def call_%s(%s):" % (name, utils.CommaJoin(funcargs)) funcdef = "def call_%s(%s):" % (name, utils.CommaJoin(funcargs))
...@@ -154,7 +151,7 @@ def _WriteBaseClass(sw, clsname, calls): ...@@ -154,7 +151,7 @@ def _WriteBaseClass(sw, clsname, calls):
else: else:
buf.write("node_list") buf.write("node_list")
buf.write(", read_timeout, [%s])" % buf.write(", [%s])" %
# Function arguments # Function arguments
utils.CommaJoin(map(compat.fst, args))) utils.CommaJoin(map(compat.fst, args)))
......
...@@ -430,17 +430,22 @@ class _RpcClientBase: ...@@ -430,17 +430,22 @@ class _RpcClientBase:
else: else:
return encoder_fn(argkind)(value) return encoder_fn(argkind)(value)
def _Call(self, cdef, node_list, timeout, args): def _Call(self, cdef, node_list, args):
"""Entry point for automatically generated RPC wrappers. """Entry point for automatically generated RPC wrappers.
""" """
(procedure, _, _, argdefs, postproc_fn, _) = cdef (procedure, _, timeout, argdefs, postproc_fn, _) = cdef
if callable(timeout):
read_timeout = timeout(args)
else:
read_timeout = timeout
body = serializer.DumpJson(map(self._encoder, body = serializer.DumpJson(map(self._encoder,
zip(map(compat.snd, argdefs), args)), zip(map(compat.snd, argdefs), args)),
indent=False) indent=False)
result = self._proc(node_list, procedure, body, read_timeout=timeout) result = self._proc(node_list, procedure, body, read_timeout=read_timeout)
if postproc_fn: if postproc_fn:
return postproc_fn(result) return postproc_fn(result)
...@@ -620,20 +625,6 @@ class RpcRunner(_RpcClientBase, ...@@ -620,20 +625,6 @@ class RpcRunner(_RpcClientBase,
""" """
return self._InstDict(instance, osp=osparams) return self._InstDict(instance, osp=osparams)
#
# Begin RPC calls
#
def call_test_delay(self, node_list, duration): # pylint: disable=W0221
"""Sleep for a fixed time on given node(s).
This is a multi-node call.
"""
# TODO: Use callable timeout calculation
return _generated_rpc.RpcClientDefault.call_test_delay(self,
node_list, duration, read_timeout=int(duration + 5))
class JobQueueRunner(_RpcClientBase, _generated_rpc.RpcClientJobQueue): class JobQueueRunner(_RpcClientBase, _generated_rpc.RpcClientJobQueue):
"""RPC wrappers for job queue. """RPC wrappers for job queue.
......
...@@ -24,7 +24,8 @@ RPC definition fields: ...@@ -24,7 +24,8 @@ RPC definition fields:
- Name as string - Name as string
- L{SINGLE} for single-node calls, L{MULTI} for multi-node - L{SINGLE} for single-node calls, L{MULTI} for multi-node
- Timeout (e.g. L{TMO_NORMAL}) - Timeout (e.g. L{TMO_NORMAL}), or callback receiving all arguments in a
tuple to calculate timeout
- List of arguments as tuples - List of arguments as tuples
- Name as string - Name as string
...@@ -149,6 +150,13 @@ def _ImpExpStatusPostProc(result): ...@@ -149,6 +150,13 @@ def _ImpExpStatusPostProc(result):
return result return result
def _TestDelayTimeout((duration, )):
"""Calculate timeout for "test_delay" RPC.
"""
return int(duration + 5)
_FILE_STORAGE_CALLS = [ _FILE_STORAGE_CALLS = [
("file_storage_dir_create", SINGLE, TMO_FAST, [ ("file_storage_dir_create", SINGLE, TMO_FAST, [
("file_storage_dir", None, "File storage directory"), ("file_storage_dir", None, "File storage directory"),
...@@ -457,7 +465,7 @@ _MISC_CALLS = [ ...@@ -457,7 +465,7 @@ _MISC_CALLS = [
], None, "Call an iallocator on a remote node"), ], None, "Call an iallocator on a remote node"),
("test_delay", MULTI, None, [ ("test_delay", MULTI, None, [
("duration", None, None), ("duration", None, None),
], None, "Sleep for a fixed time on given node(s)"), ], _TestDelayTimeout, "Sleep for a fixed time on given node(s)"),
("hypervisor_validate_params", MULTI, TMO_NORMAL, [ ("hypervisor_validate_params", MULTI, TMO_NORMAL, [
("hvname", None, "Hypervisor name"), ("hvname", None, "Hypervisor name"),
("hvfull", None, "Parameters to be validated"), ("hvfull", None, "Parameters to be validated"),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment