Commit 2ff587d4 authored by Agata Murawska's avatar Agata Murawska
Browse files

Move necessary constants from rpc & rpc_defs to constants



As timeout constants will now be used also on Haskell side, they have
been moved from rpc_defs and rpc to constants. The same is true for
connection timeout for connecting to nodes.
Signed-off-by: default avatarAgata Murawska <agatamurawska@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 951accad
......@@ -653,6 +653,17 @@ RUNPARTS_STATUS = frozenset([RUNPARTS_SKIP, RUNPARTS_RUN, RUNPARTS_ERR])
(RPC_ENCODING_NONE,
RPC_ENCODING_ZLIB_BASE64) = range(2)
# Various time constants for the timeout table
RPC_TMO_URGENT = 60 # one minute
RPC_TMO_FAST = 5 * 60 # five minutes
RPC_TMO_NORMAL = 15 * 60 # 15 minutes
RPC_TMO_SLOW = 3600 # one hour
RPC_TMO_4HRS = 4 * 3600
RPC_TMO_1DAY = 86400
# Timeout for connecting to nodes (seconds)
RPC_CONNECT_TIMEOUT = 5
# os related constants
OS_SCRIPT_CREATE = "create"
OS_SCRIPT_IMPORT = "import"
......
......@@ -55,22 +55,11 @@ from ganeti import _generated_rpc
import ganeti.http.client # pylint: disable=W0611
# Timeout for connecting to nodes (seconds)
_RPC_CONNECT_TIMEOUT = 5
_RPC_CLIENT_HEADERS = [
"Content-type: %s" % http.HTTP_APP_JSON,
"Expect:",
]
# Various time constants for the timeout table
_TMO_URGENT = 60 # one minute
_TMO_FAST = 5 * 60 # five minutes
_TMO_NORMAL = 15 * 60 # 15 minutes
_TMO_SLOW = 3600 # one hour
_TMO_4HRS = 4 * 3600
_TMO_1DAY = 86400
#: Special value to describe an offline host
_OFFLINE = object()
......@@ -114,7 +103,7 @@ def _ConfigRpcCurl(curl):
curl.setopt(pycurl.SSLCERT, noded_cert)
curl.setopt(pycurl.SSLKEYTYPE, "PEM")
curl.setopt(pycurl.SSLKEY, noded_cert)
curl.setopt(pycurl.CONNECTTIMEOUT, _RPC_CONNECT_TIMEOUT)
curl.setopt(pycurl.CONNECTTIMEOUT, constants.RPC_CONNECT_TIMEOUT)
def RunWithRPC(fn):
......
This diff is collapsed.
......@@ -76,7 +76,7 @@ class TestRpcProcessor(unittest.TestCase):
self.assertEqual(req.host, "127.0.0.1")
self.assertEqual(req.port, 24094)
self.assertEqual(req.path, "/version")
self.assertEqual(req.read_timeout, rpc._TMO_URGENT)
self.assertEqual(req.read_timeout, constants.RPC_TMO_URGENT)
req.success = True
req.resp_status_code = http.HTTP_OK
req.resp_body = serializer.DumpJson((True, 123))
......@@ -242,7 +242,8 @@ class TestRpcProcessor(unittest.TestCase):
http_proc = \
_FakeRequestProcessor(compat.partial(self._GetHttpErrorResponse,
httperrnodes, failnodes))
result = proc(nodes, "vg_list", body, rpc._TMO_URGENT, NotImplemented,
result = proc(nodes, "vg_list", body,
constants.RPC_TMO_URGENT, NotImplemented,
_req_process_fn=http_proc)
self.assertEqual(sorted(result.keys()), sorted(nodes))
......@@ -491,7 +492,7 @@ class TestCompress(unittest.TestCase):
class TestRpcClientBase(unittest.TestCase):
def testNoHosts(self):
cdef = ("test_call", NotImplemented, None, rpc_defs.TMO_SLOW, [],
cdef = ("test_call", NotImplemented, None, constants.RPC_TMO_SLOW, [],
None, None, NotImplemented)
http_proc = _FakeRequestProcessor(NotImplemented)
client = rpc._RpcClientBase(rpc._StaticResolver([]), NotImplemented,
......@@ -561,7 +562,7 @@ class TestRpcClientBase(unittest.TestCase):
AT2: hash,
}
cdef = ("test_call", NotImplemented, None, rpc_defs.TMO_NORMAL, [
cdef = ("test_call", NotImplemented, None, constants.RPC_TMO_NORMAL, [
("arg0", None, NotImplemented),
("arg1", AT1, NotImplemented),
("arg1", AT2, NotImplemented),
......@@ -605,7 +606,7 @@ class TestRpcClientBase(unittest.TestCase):
res.payload = sum(res.payload)
return res
cdef = ("test_call", NotImplemented, None, rpc_defs.TMO_NORMAL, [],
cdef = ("test_call", NotImplemented, None, constants.RPC_TMO_NORMAL, [],
None, _PostProc, NotImplemented)
# Seeded random generator
......@@ -642,7 +643,7 @@ class TestRpcClientBase(unittest.TestCase):
self.assertEqual(len(data), 1)
return data[0] + node
cdef = ("test_call", NotImplemented, None, rpc_defs.TMO_NORMAL, [
cdef = ("test_call", NotImplemented, None, constants.RPC_TMO_NORMAL, [
("arg0", None, NotImplemented),
], _PreProc, None, NotImplemented)
......@@ -687,7 +688,8 @@ class TestRpcClientBase(unittest.TestCase):
]
for (resolver_opts, arg0, expected) in tests:
cdef = ("test_call", NotImplemented, resolver_opts, rpc_defs.TMO_NORMAL, [
cdef = ("test_call", NotImplemented, resolver_opts,
constants.RPC_TMO_NORMAL, [
("arg0", None, NotImplemented),
], None, None, NotImplemented)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment