autoupdate.py: Allow max_updates through update URL
Currently in order to put a ceiling on the number of updates that can be
performed in a devserver, we need to spawn a new devserver with flag
--max_updates. The problem is now for each run of an autotest, they
should spwan a new devserver alongside the lab devservers which is not
ideal.
We solve this problem by dynamically configuring the devserver
using a unique identifier. This is done by calling into 'session_id' API
of the devserver. Then clients can send their requests appending this
session_id to be responded likewise.
For maximum updates, we first configure the devserver to set a
'max_updates' data for a unique session ID. Then client can send
requests using the session ID as a query string be capped on the number
of updates they get.
BUG=chromium:1004489
TEST=autoupdate_unittest.py
TEST=devserver_integration_test.py
Change-Id: Ieef921b177ba0ec789d6471a34a4f8e44f5482af
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/dev-util/+/1996148
Tested-by: Amin Hassani <ahassani@chromium.org>
Commit-Queue: Amin Hassani <ahassani@chromium.org>
Reviewed-by: Allen Li <ayatane@chromium.org>
diff --git a/devserver_integration_test.py b/devserver_integration_test.py
index fbde817..c1846e3 100755
--- a/devserver_integration_test.py
+++ b/devserver_integration_test.py
@@ -56,6 +56,14 @@
</app>
</request>
""")
+DOWNLOAD_STARTED_REQUEST = Template("""<?xml version="1.0" encoding="UTF-8"?>
+<request protocol="3.0" updater="ChromeOSUpdateEngine" updaterversion="0.1.0.0" ismachine="1">
+ <os version="Indy" platform="Chrome OS" sp="0.11.254.2011_03_09_1814_i686"></os>
+ <app appid="$appid" version="11.254.2011_03_09_1814" lang="en-US" track="developer-build" board="x86-generic" hardware_class="BETA DVT" delta_okay="true">
+ <event eventtype="13" eventresult="1"></event>
+ </app>
+</request>
+""")
# RPC constants.
STAGE = 'stage'
@@ -402,6 +410,38 @@
connection.close()
self.assertEqual(update_data, contents)
+ def testMaxUpdates(self):
+ """Tests MaxUpdates functionality of autoupdate."""
+ update_label = '/'.join([UPDATE, LABEL])
+ update_request = UPDATE_REQUEST.substitute({'appid': '{DEV-BUILD}'})
+ download_started_request = DOWNLOAD_STARTED_REQUEST.substitute(
+ {'appid': '{DEV-BUILD}'})
+
+ session = 'foo-id'
+ post_data = json.dumps({'max_updates': 2})
+ self._MakeRPC('session/%s' % session, data=post_data)
+
+ # The first request should provide an actual update.
+ response = self._MakeRPC(update_label, data=update_request)
+ self.assertIn('updatecheck status="ok"', response)
+ # Tell devserver we started to download.
+ response = self._MakeRPC(update_label, data=download_started_request,
+ session=session)
+
+ # Another update request also should go fine.
+ response = self._MakeRPC(update_label, data=update_request,
+ session=session)
+ self.assertIn('updatecheck status="ok"', response)
+ # Tell devserver we started to download.
+ response = self._MakeRPC(update_label, data=download_started_request,
+ session=session)
+
+ # But the third update request should not be valid anymore since we hit the
+ # max updates ceiling.
+ response = self._MakeRPC(update_label, data=update_request,
+ session=session)
+ self.assertIn('updatecheck status="noupdate"', response)
+
def testPidFile(self):
"""Test that using a pidfile works correctly."""
with open(self.pidfile, 'r') as f: