[Autotest] Add free disk space check in devserver
Add a new method, check_health, to collect the health status of devserver.
Initially, collect the free disk space. The method is extendable to return more
information. The caller will determine if the devserver is ready for staging
image based on the returned health status.
BUG=chromium:219330
TEST=tested with run_suite in local machine, which runs as devserver as well.
DEPLOY=apache
Change-Id: Ib97672ca142b73ee9e0e4dbe8b6cc2c4c583b979
Reviewed-on: https://gerrit.chromium.org/gerrit/49252
Tested-by: Dan Shi <dshi@chromium.org>
Reviewed-by: Chris Sosa <sosa@chromium.org>
Commit-Queue: Dan Shi <dshi@chromium.org>
diff --git a/devserver.py b/devserver.py
index 11e8937..238a65d 100755
--- a/devserver.py
+++ b/devserver.py
@@ -724,6 +724,22 @@
return updater.HandleUpdatePing(data, label)
+ @cherrypy.expose
+ def check_health(self):
+ """Collect the health status of devserver to see if it's ready for staging.
+
+ @return: A JSON dictionary containing all or some of the following fields:
+ free_disk (int): free disk space in GB
+ """
+ # Get free disk space.
+ stat = os.statvfs(updater.static_dir)
+ free_disk = stat.f_bsize * stat.f_bavail / 1000000000
+
+ return json.dumps({
+ 'free_disk': free_disk,
+ })
+
+
def _CleanCache(cache_dir, wipe):
"""Wipes any excess cached items in the cache_dir.