[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 <[email protected]>
Tested-by: Mungyung Ryu <[email protected]>
Reviewed-by: Fang Deng <[email protected]>
Reviewed-by: Dan Shi <[email protected]>
diff --git a/frontend/afe/rpc_interface_unittest.py b/frontend/afe/rpc_interface_unittest.py
index 70bba4d..eec4b41 100755
--- a/frontend/afe/rpc_interface_unittest.py
+++ b/frontend/afe/rpc_interface_unittest.py
@@ -458,7 +458,7 @@
self.god.stub_with(frontend_wrappers, 'RetryingAFE', mock_afe)
mock_afe2 = frontend_wrappers.RetryingAFE.expect_new(
- server=shard_hostname)
+ server=shard_hostname, user=None)
mock_afe2.run.expect_call('modify_host_local', id=host.id,
locked=True, lock_reason='_modify_host_helper lock')
elif on_shard:
@@ -467,7 +467,7 @@
self.god.stub_with(frontend_wrappers, 'RetryingAFE', mock_afe)
mock_afe2 = frontend_wrappers.RetryingAFE.expect_new(
- server=rpc_utils.get_global_afe_hostname())
+ server=rpc_utils.get_global_afe_hostname(), user=None)
mock_afe2.run.expect_call('modify_host', id=host.id,
locked=True, lock_reason='_modify_host_helper lock')
@@ -523,14 +523,16 @@
# will be affected no matter what his status is.
filters_to_use = {'status': 'Ready'}
- mock_afe2 = frontend_wrappers.RetryingAFE.expect_new(server='shard2')
+ mock_afe2 = frontend_wrappers.RetryingAFE.expect_new(
+ server='shard2', user=None)
mock_afe2.run.expect_call(
'modify_hosts_local',
host_filter_data={'id__in': [shard1.id, shard2.id]},
update_data={'locked': True,
'lock_reason': 'Testing forward to shard'})
- mock_afe1 = frontend_wrappers.RetryingAFE.expect_new(server='shard1')
+ mock_afe1 = frontend_wrappers.RetryingAFE.expect_new(
+ server='shard1', user=None)
mock_afe1.run.expect_call(
'modify_hosts_local',
host_filter_data={'id__in': [shard1.id, shard2.id]},
@@ -561,7 +563,8 @@
'MockAFE')
self.god.stub_with(frontend_wrappers, 'RetryingAFE', mock_afe)
- mock_afe1 = frontend_wrappers.RetryingAFE.expect_new(server='shard1')
+ mock_afe1 = frontend_wrappers.RetryingAFE.expect_new(
+ server='shard1', user=None)
mock_afe1.run.expect_call('delete_host', id=host1.id)
rpc_interface.delete_host(id=host1.id)
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