[autotest] Improve clarity of RPC failure for shards
frontend/afe/rpc_utils.fanout_rpc is the function that forwards
RPC to shards.
Add additional message which RPC failed on which shard for more
clarity.
BUG=chromium:448273
TEST=puppylab. Test 2 cases. One is to try cli/atest label add
-m test_host51 newlabel -w localhost:8001 when lumpyshard is
unreachable. This raises URLError exception.
The another is to try same atest command when test_host51 is
removed from lumpyshard. This raises DoesNotExist exception.
DEPLOY=apache
Change-Id: Ie58c3360bb4fa920bd807eca4545b294d179697a
Reviewed-on: https://chromium-review.googlesource.com/250953
Reviewed-by: Mungyung Ryu <mkryu@google.com>
Tested-by: Mungyung Ryu <mkryu@google.com>
Commit-Queue: Mungyung Ryu <mkryu@google.com>
diff --git a/frontend/afe/rpc_utils.py b/frontend/afe/rpc_utils.py
index 99c183c..5d37be2 100644
--- a/frontend/afe/rpc_utils.py
+++ b/frontend/afe/rpc_utils.py
@@ -6,7 +6,10 @@
__author__ = 'showard@google.com (Steve Howard)'
-import datetime, os, inspect
+import datetime
+import inspect
+import os
+import sys
import django.http
from autotest_lib.frontend.afe import models, model_logic
from autotest_lib.client.common_lib import control_data, error
@@ -1100,7 +1103,13 @@
for shard, hostnames in shard_host_map.iteritems():
if include_hostnames:
kwargs['hosts'] = hostnames
- run_rpc_on_multiple_hostnames(rpc_name, [shard], **kwargs)
+ try:
+ run_rpc_on_multiple_hostnames(rpc_name, [shard], **kwargs)
+ except:
+ ei = sys.exc_info()
+ new_exc = error.RPCException('RPC %s failed on shard %s due to '
+ '%s: %s' % (rpc_name, shard, ei[0].__name__, ei[1]))
+ raise new_exc.__class__, new_exc, ei[2]
def forward_multi_host_rpc_to_shards(func):