[autotest] Forward user when forwaring/routing RPCs.
User account information is passed to RPC server via
HTTP header. We can pass the user info to the header when
creating server.frontend.RpcClient object. We should forward
the user info when forwaring/routing RPCs not to lose the
user account info in the receiving side.
BUG=chromium:533159
TEST=puppylab. Lock a sharded host with root account and check
the host is locked by root in the master DB and the shard DB.
Change-Id: I185e49f028c8fdfdf630855412a6e370d5684491
Reviewed-on: https://chromium-review.googlesource.com/300594
Commit-Ready: Mungyung Ryu <mkryu@google.com>
Tested-by: Mungyung Ryu <mkryu@google.com>
Reviewed-by: Fang Deng <fdeng@chromium.org>
Reviewed-by: Dan Shi <dshi@chromium.org>
diff --git a/frontend/afe/rpc_utils.py b/frontend/afe/rpc_utils.py
index 1b91f88..9e96956 100644
--- a/frontend/afe/rpc_utils.py
+++ b/frontend/afe/rpc_utils.py
@@ -12,6 +12,8 @@
import os
import sys
import django.http
+
+from autotest_lib.frontend import thread_local
from autotest_lib.frontend.afe import models, model_logic
from autotest_lib.client.common_lib import control_data, error
from autotest_lib.client.common_lib import global_config, priorities
@@ -1257,7 +1259,8 @@
# Make sure this function is not called on shards but only on master.
assert not server_utils.is_shard()
for shard_hostname in shard_hostnames:
- afe = frontend_wrappers.RetryingAFE(server=shard_hostname)
+ afe = frontend_wrappers.RetryingAFE(server=shard_hostname,
+ user=thread_local.get_user())
afe.run(rpc_call, **kwargs)
@@ -1335,7 +1338,8 @@
if server_utils.is_shard():
afe = frontend_wrappers.RetryingAFE(
- server=get_global_afe_hostname())
+ server=get_global_afe_hostname(),
+ user=thread_local.get_user())
return afe.run(func.func_name, **kwargs)
return func(**kwargs)
return replacement