devserver: return empty host log if not events were logged
This fixes a bug where the /api/hostlog?ip=foo URL returns no value when
no events were logged for a given IP address, which causes a problem on
the client side (who is expecting a valid JSON object). Instead, we're
not returning an empty log.
BUG=None
TEST=Devserver returns empty log (list) for queries about idle or
non-existent hosts
Change-Id: If2b27b02272dcf38b732918115e7bd7bb2e49a7a
Reviewed-on: https://gerrit.chromium.org/gerrit/34825
Reviewed-by: Chris Sosa <sosa@chromium.org>
Commit-Ready: Gilad Arnold <garnold@chromium.org>
Tested-by: Gilad Arnold <garnold@chromium.org>
diff --git a/autoupdate.py b/autoupdate.py
index 87e31de..e1b884a 100644
--- a/autoupdate.py
+++ b/autoupdate.py
@@ -870,13 +870,19 @@
def HandleHostLogPing(self, ip):
"""Returns a complete log of events for host in JSON format."""
+ # If all events requested, return a dictionary of logs keyed by IP address.
if ip == 'all':
return json.dumps(
dict([(key, self.host_infos.table[key].log)
for key in self.host_infos.table]))
+
+ # Otherwise we're looking for a specific IP address, so find its log.
if ip in self.host_infos.table:
return json.dumps(self.host_infos.GetHostInfo(ip).log)
+ # If no events were logged for this IP, return an empty log.
+ return json.dumps([])
+
def HandleSetUpdatePing(self, ip, label):
"""Sets forced_update_label for a given host."""
assert ip, 'No ip provided.'