Introduce Dev Server API. Adds hostinfo, setnextupdate methods.
Adds a couple methods in preparation for AU testing where no SSH access
to the host is available. Instead information about the update process
must be gleaned from the queries made to the Dev Server.
hostinfo provides information on the last received update type and
status as well as known version information. Information is returned in
a JSON dictionary.
setnextupdate takes an update label (as normally provided to /update)
and causes the next update ping from that host to use that url for the
update.
BUG=none
TEST=Ran Dev Server. Queried API w/ valid and invalid. Verified next
update used set one.
http://172.31.26.251:8081/api/hostinfo/172.31.26.144
Change-Id: I907b419371aab5774c618fa9192ef056cd6aa046
Reviewed-on: http://gerrit.chromium.org/gerrit/5933
Reviewed-by: Chris Sosa <sosa@chromium.org>
Tested-by: Dale Curtis <dalecurtis@chromium.org>
diff --git a/devserver_test.py b/devserver_test.py
index 7b6f5a9..e97517b 100755
--- a/devserver_test.py
+++ b/devserver_test.py
@@ -6,6 +6,7 @@
"""Regression tests for devserver."""
+import json
import os
import signal
import shutil
@@ -37,6 +38,14 @@
# TODO(girts): use a random available port.
UPDATE_URL = 'http://127.0.0.1:8080/update'
+API_HOST_INFO_BAD_URL = 'http://127.0.0.1:8080/api/hostinfo/'
+API_HOST_INFO_URL = API_HOST_INFO_BAD_URL + '127.0.0.1'
+
+API_SET_UPDATE_BAD_URL = 'http://127.0.0.1:8080/api/setnextupdate/'
+API_SET_UPDATE_URL = API_SET_UPDATE_BAD_URL + '127.0.0.1'
+
+API_SET_UPDATE_REQUEST = 'new_update-test/the-new-update'
+
# Run all tests while being in /
base_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
os.chdir("/")
@@ -166,6 +175,84 @@
finally:
os.kill(pid, signal.SIGKILL)
+ def testApiBadSetNextUpdateRequest(self):
+ """Tests sending a bad setnextupdate request."""
+ pid = self._StartServer()
+ try:
+ # Wait for the server to start up.
+ time.sleep(1)
+
+ # Send bad request and ensure it fails...
+ try:
+ request = urllib2.Request(API_SET_UPDATE_URL, '')
+ connection = urllib2.urlopen(request)
+ connection.read()
+ connection.close()
+ self.fail('Invalid setnextupdate request did not fail!')
+ except urllib2.URLError:
+ pass
+ finally:
+ os.kill(pid, signal.SIGKILL)
+
+ def testApiBadSetNextUpdateURL(self):
+ """Tests contacting a bad setnextupdate url."""
+ pid = self._StartServer()
+ try:
+ # Wait for the server to start up.
+ time.sleep(1)
+
+ # Send bad request and ensure it fails...
+ try:
+ connection = urllib2.urlopen(API_SET_UPDATE_BAD_URL)
+ connection.read()
+ connection.close()
+ self.fail('Invalid setnextupdate url did not fail!')
+ except urllib2.URLError:
+ pass
+ finally:
+ os.kill(pid, signal.SIGKILL)
+
+ def testApiBadHostInfoURL(self):
+ """Tests contacting a bad hostinfo url."""
+ pid = self._StartServer()
+ try:
+ # Wait for the server to start up.
+ time.sleep(1)
+
+ # Send bad request and ensure it fails...
+ try:
+ connection = urllib2.urlopen(API_HOST_INFO_BAD_URL)
+ connection.read()
+ connection.close()
+ self.fail('Invalid hostinfo url did not fail!')
+ except urllib2.URLError:
+ pass
+ finally:
+ os.kill(pid, signal.SIGKILL)
+
+ def testApiHostInfoAndSetNextUpdate(self):
+ """Tests using the setnextupdate and hostinfo api commands."""
+ pid = self._StartServer()
+ try:
+ # Wait for the server to start up.
+ time.sleep(1)
+
+ # Send setnextupdate command.
+ request = urllib2.Request(API_SET_UPDATE_URL, API_SET_UPDATE_REQUEST)
+ connection = urllib2.urlopen(request)
+ response = connection.read()
+ connection.close()
+
+ # Send hostinfo command and verify the setnextupdate worked.
+ connection = urllib2.urlopen(API_HOST_INFO_URL)
+ response = connection.read()
+ connection.close()
+
+ self.assertEqual(
+ json.loads(response)['forced_update_label'], API_SET_UPDATE_REQUEST)
+ finally:
+ os.kill(pid, signal.SIGKILL)
+
if __name__ == '__main__':
unittest.main()