devserver: Fix fileinfo API
The 'fileinfo' devserver API is broken since since there was no unittest
for it. This CL fixes the API and adds unittest for it.
BUG=chromium:1018237
TEST=devserver_integration_test.py
TEST=./devserver.py --static_dir=/mnt/host/source/devserver/static
then:
curl http://127.0.0.1:8080/api/fileinfo/reef-release/R80-12622.0.0/update.gz
(assuming reef-release/R80-12622.0.0/full_update has been staged.)
returns:
{"sha256": "HPVNNZq9/rZG1imLrACEhRskstwohQpX5gjQJLCAXZ8=", "size": 1010445126}
Change-Id: I6876b9004bc264aba131b41ac158e544fe704711
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/dev-util/+/1884310
Tested-by: Amin Hassani <ahassani@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Amin Hassani <ahassani@chromium.org>
diff --git a/devserver.py b/devserver.py
index 0d8aa07..2d156f3 100755
--- a/devserver.py
+++ b/devserver.py
@@ -580,6 +580,10 @@
Example URL:
http://myhost/api/fileinfo/some/path/to/file
"""
+ # TODO(ahassani): A better way of doing this is to just return the the
+ # content of the payloads' property file instead. That has all this info
+ # except that the key for sha256 is 'sha256_hex', but still base64 encdoed.
+
file_path = os.path.join(updater.static_dir, *args)
if not os.path.exists(file_path):
raise DevServerError('file not found: %s' % file_path)
@@ -591,9 +595,9 @@
'failed to get info for file %s: %s' % (file_path, e))
return json.dumps({
- autoupdate.Autoupdate.SIZE_ATTR: file_size,
- autoupdate.Autoupdate.SHA256_ATTR: file_sha256,
- })
+ 'size': file_size,
+ 'sha256': file_sha256,
+ }, sort_keys=True)
class DevServerRoot(object):