autotest: Make RPC 'get_host_attributes' respect static attributes
BUG=chromium:792309
TEST=Ran unittest. Call RPC 'get_host_attributes' locally.
Change-Id: Iae7dccfc0c63481f07c6b4122774e7f5e02f2bd0
Reviewed-on: https://chromium-review.googlesource.com/929889
Commit-Ready: Xixuan Wu <[email protected]>
Tested-by: Xixuan Wu <[email protected]>
Reviewed-by: Shuqian Zhao <[email protected]>
diff --git a/frontend/afe/rpc_interface_unittest.py b/frontend/afe/rpc_interface_unittest.py
index bf31ccb..4041fff 100755
--- a/frontend/afe/rpc_interface_unittest.py
+++ b/frontend/afe/rpc_interface_unittest.py
@@ -307,6 +307,25 @@
'test_attribute2': 'test_value2',
'static_attribute1': 'static_value2'})
+ def test_get_host_attribute_with_static(self):
+ host1 = models.Host.objects.create(hostname='test_host1')
+ host1.set_attribute('test_attribute1', 'test_value1')
+ self._set_static_attribute(host1, 'test_attribute1', 'static_value1')
+ host2 = models.Host.objects.create(hostname='test_host2')
+ host2.set_attribute('test_attribute1', 'test_value1')
+ host2.set_attribute('test_attribute2', 'test_value2')
+
+ attributes = rpc_interface.get_host_attribute(
+ 'test_attribute1',
+ hostname__in=['test_host1', 'test_host2'])
+ hosts = [attr['host'] for attr in attributes]
+ values = [attr['value'] for attr in attributes]
+ self.assertEquals(set(hosts),
+ set(['test_host1', 'test_host2']))
+ self.assertEquals(set(values),
+ set(['test_value1', 'static_value1']))
+
+
def test_get_hosts_by_attribute_without_static(self):
host1 = models.Host.objects.create(hostname='test_host1')
host1.set_attribute('test_attribute1', 'test_value1')
@@ -744,6 +763,22 @@
set(['test_host1', 'test_host2']))
+ def test_get_host_attribute(self):
+ host1 = models.Host.objects.create(hostname='test_host1')
+ host1.set_attribute('test_attribute1', 'test_value1')
+ host2 = models.Host.objects.create(hostname='test_host2')
+ host2.set_attribute('test_attribute1', 'test_value1')
+
+ attributes = rpc_interface.get_host_attribute(
+ 'test_attribute1',
+ hostname__in=['test_host1', 'test_host2'])
+ hosts = [attr['host'] for attr in attributes]
+ values = [attr['value'] for attr in attributes]
+ self.assertEquals(set(hosts),
+ set(['test_host1', 'test_host2']))
+ self.assertEquals(set(values), set(['test_value1']))
+
+
def test_get_hosts(self):
hosts = rpc_interface.get_hosts()
self._check_hostnames(hosts, [host.hostname for host in self.hosts])