Commit c2dc025a authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

rpc.ConfigRunner: Fix uploading file

Commit 601dfcbb

 made some changes to the default encoders. This made
“ConfigRunner.call_upload_file” fail due to a missing encoder. This
patch applies the necessary changes to ConfigRunner and updates the
unittest for “call_upload_file”.
Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent 30a83755
......@@ -710,7 +710,8 @@ class ConfigRunner(_RpcClientBase, _generated_rpc.RpcClientConfig):
"""RPC wrappers for L{config}.
"""
def __init__(self, context, address_list):
def __init__(self, context, address_list, _req_process_fn=None,
_getents=None):
"""Initializes this class.
"""
......@@ -725,6 +726,13 @@ class ConfigRunner(_RpcClientBase, _generated_rpc.RpcClientConfig):
# Caller provided an address list
resolver = _StaticResolver(address_list)
_RpcClientBase.__init__(self, resolver, _ENCODERS.get,
lock_monitor_cb=lock_monitor_cb)
encoders = _ENCODERS.copy()
encoders.update({
rpc_defs.ED_FILE_DETAILS: compat.partial(_PrepareFileUpload, _getents),
})
_RpcClientBase.__init__(self, resolver, encoders.get,
lock_monitor_cb=lock_monitor_cb,
_req_process_fn=_req_process_fn)
_generated_rpc.RpcClientConfig.__init__(self)
......@@ -716,18 +716,24 @@ class TestRpcRunner(unittest.TestCase):
req.resp_body = serializer.DumpJson((True, None))
http_proc = _FakeRequestProcessor(_VerifyRequest)
cfg = _FakeConfigForRpcRunner()
runner = rpc.RpcRunner(cfg, None, _req_process_fn=http_proc,
_getents=mocks.FakeGetentResolver)
std_runner = rpc.RpcRunner(_FakeConfigForRpcRunner(), None,
_req_process_fn=http_proc,
_getents=mocks.FakeGetentResolver)
cfg_runner = rpc.ConfigRunner(None, ["192.0.2.13"],
_req_process_fn=http_proc,
_getents=mocks.FakeGetentResolver)
nodes = [
"node1.example.com",
]
result = runner.call_upload_file(nodes, tmpfile.name)
self.assertEqual(len(result), len(nodes))
for (idx, (node, res)) in enumerate(result.items()):
self.assertFalse(res.fail_msg)
for runner in [std_runner, cfg_runner]:
result = runner.call_upload_file(nodes, tmpfile.name)
self.assertEqual(len(result), len(nodes))
for (idx, (node, res)) in enumerate(result.items()):
self.assertFalse(res.fail_msg)
if __name__ == "__main__":
......
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