[autotest] Allow create_suite_job RPC to pick a devserver in desired subnet.
This change allows create_suite_job RPC to pick a devserver in the same subnet
of the duts may run tests. The assumption is that duts in the same pool and
board are in the same subnet, which should be true once ACL is enforced.
BUG=chromium:577363
TEST=run in local setup
update global config:
prefer_local_devserver: True
add couple devservers in different subnet
call run_suite, confirm the desired desverver is picked
Change-Id: I3435c13a7c5b25a429609780e0d8471a066e501d
Reviewed-on: https://chromium-review.googlesource.com/339250
Commit-Ready: Dan Shi <dshi@google.com>
Tested-by: Dan Shi <dshi@google.com>
Reviewed-by: Dan Shi <dshi@google.com>
diff --git a/frontend/afe/rpc_utils.py b/frontend/afe/rpc_utils.py
index 173f84c..f2965d2 100644
--- a/frontend/afe/rpc_utils.py
+++ b/frontend/afe/rpc_utils.py
@@ -1321,3 +1321,25 @@
return afe.run(func.func_name, **kwargs)
return func(**kwargs)
return replacement
+
+
+def get_sample_dut(board, pool):
+ """Get a dut with the given board and pool.
+
+ This method is used to help to locate a dut with the given board and pool.
+ The dut then can be used to identify a devserver in the same subnet.
+
+ @param board: Name of the board.
+ @param pool: Name of the pool.
+
+ @return: Name of a dut with the given board and pool.
+ """
+ if not board or not pool:
+ return None
+
+ hosts = get_host_query(
+ ('pool:%s' % pool, 'board:%s' % board), False, False, True, {})
+ if not hosts:
+ return None
+
+ return list(hosts)[0].get_object_dict()['hostname']