[autotest] Add a new RPC interface, get_host_attribute.
Retrieve a host's attribute from afe_host_attributes table.
When you need to get only attribute info of a host, this RPC call is
lighter than using get_hosts RPC call.
DEPLOY=apache
BUG=chromium:215160
TEST=AUTOTEST_ROOT$ python
>>import common
>>from autotest_lib.server.cros.dynamic_suite import tools, frontend_wrappers
>>afe = frontend_wrappers.RetryingAFE(timeout_min=5, delay_sec=10)
>>afe.get_host_attribute('need_crash_logs', hostname=<host ip>)
Change-Id: I86bc17091c078823c270206d80bd572f2fbbeb95
Reviewed-on: https://chromium-review.googlesource.com/221510
Reviewed-by: Fang Deng <fdeng@chromium.org>
Commit-Queue: Mungyung Ryu <mkryu@google.com>
Tested-by: Mungyung Ryu <mkryu@google.com>
diff --git a/frontend/afe/rpc_interface.py b/frontend/afe/rpc_interface.py
index cfd861d..3b5eef3 100644
--- a/frontend/afe/rpc_interface.py
+++ b/frontend/afe/rpc_interface.py
@@ -170,6 +170,24 @@
models.Host.smart_get(id).labels.remove(*labels)
+def get_host_attribute(attribute, **host_filter_data):
+ """
+ @param attribute: string name of attribute
+ @param host_filter_data: filter data to apply to Hosts to choose hosts to
+ act upon
+ """
+ hosts = rpc_utils.get_host_query((), False, False, True, host_filter_data)
+ hosts = list(hosts)
+ models.Host.objects.populate_relationships(hosts, models.HostAttribute,
+ 'attribute_list')
+ host_attr_dicts = []
+ for host_obj in hosts:
+ for attr_obj in host_obj.attribute_list:
+ if attr_obj.attribute == attribute:
+ host_attr_dicts.append(attr_obj.get_object_dict())
+ return rpc_utils.prepare_for_serialization(host_attr_dicts)
+
+
def set_host_attribute(attribute, value, **host_filter_data):
"""
@param attribute string name of attribute