Commit be4ea27c authored by Kevin Marshall's avatar Kevin Marshall Committed by Commit Bot

[Fuchsia] Add 'pm serve' liveness check to runner scripts.

Changes the runner script to block script execution and generate log
spam until it has positive confirmation the "pm serve" is serving
HTTP traffic.

"pm serve" is now started immediately after the repo is created, allowing
it to bind its socket in parallel with "pm publish" operations.


Bug: 973754
Change-Id: I92730010524a646204ead8fb8b113968b4179b5a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1659594
Auto-Submit: Kevin Marshall <kmarshall@chromium.org>
Reviewed-by: default avatarWez <wez@chromium.org>
Commit-Queue: Wez <wez@chromium.org>
Cr-Commit-Position: refs/heads/master@{#669122}
parent a2197be6
...@@ -11,6 +11,7 @@ import remote_cmd ...@@ -11,6 +11,7 @@ import remote_cmd
import shutil import shutil
import subprocess import subprocess
import sys import sys
import urllib2
import tempfile import tempfile
import time import time
...@@ -26,6 +27,9 @@ _REPO_NAME = 'chrome_runner' ...@@ -26,6 +27,9 @@ _REPO_NAME = 'chrome_runner'
# mitigation against hangs due to amber/network-related failures. # mitigation against hangs due to amber/network-related failures.
_INSTALL_TIMEOUT_SECS = 5 * 60 _INSTALL_TIMEOUT_SECS = 5 * 60
# Maximum amount of time to block while waitin for "pm serve" to come up.
_PM_SERVE_LIVENESS_TIMEOUT_SECS = 10
def _GetPackageInfo(package_path): def _GetPackageInfo(package_path):
"""Returns a tuple with the name and version of a package.""" """Returns a tuple with the name and version of a package."""
...@@ -57,6 +61,22 @@ class _MapRemoteDataPathForPackage: ...@@ -57,6 +61,22 @@ class _MapRemoteDataPathForPackage:
return self.data_path + path[5:] return self.data_path + path[5:]
return path return path
def _WaitForPmServeToBeReady(port):
"""Blocks until "pm serve" starts serving HTTP traffic at |port|."""
timeout = time.time() + _PM_SERVE_LIVENESS_TIMEOUT_SECS
while True:
try:
urllib2.urlopen('http://localhost:%d' % port, timeout=1).read()
break
except urllib2.URLError:
logging.info('Waiting until \'pm serve\' is up...')
if time.time() >= timeout:
raise Exception('Timed out while waiting for \'pm serve\'.')
time.sleep(1)
class FuchsiaTargetException(Exception): class FuchsiaTargetException(Exception):
def __init__(self, message): def __init__(self, message):
...@@ -240,7 +260,6 @@ class Target(object): ...@@ -240,7 +260,6 @@ class Target(object):
return 'x86_64' return 'x86_64'
raise Exception('Unknown target_cpu %s:' % self._target_cpu) raise Exception('Unknown target_cpu %s:' % self._target_cpu)
def InstallPackage(self, package_path, package_name, package_deps): def InstallPackage(self, package_path, package_name, package_deps):
"""Installs a package and it's dependencies on the device. If the package is """Installs a package and it's dependencies on the device. If the package is
already installed then it will be updated to the new version. already installed then it will be updated to the new version.
...@@ -254,11 +273,7 @@ class Target(object): ...@@ -254,11 +273,7 @@ class Target(object):
tuf_root = tempfile.mkdtemp() tuf_root = tempfile.mkdtemp()
pm_serve_task = None pm_serve_task = None
# Publish all packages to the serving TUF repository under |tuf_root|.
subprocess.check_call([_PM, 'newrepo', '-repo', tuf_root]) subprocess.check_call([_PM, 'newrepo', '-repo', tuf_root])
all_packages = [package_path] + package_deps
for next_package_path in all_packages:
_PublishPackage(tuf_root, next_package_path)
# Serve the |tuf_root| using 'pm serve' and configure the target to pull # Serve the |tuf_root| using 'pm serve' and configure the target to pull
# from it. # from it.
...@@ -266,6 +281,14 @@ class Target(object): ...@@ -266,6 +281,14 @@ class Target(object):
pm_serve_task = subprocess.Popen( pm_serve_task = subprocess.Popen(
[_PM, 'serve', '-d', os.path.join(tuf_root, 'repository'), '-l', [_PM, 'serve', '-d', os.path.join(tuf_root, 'repository'), '-l',
':%d' % serve_port, '-q']) ':%d' % serve_port, '-q'])
# Publish all packages to the serving TUF repository under |tuf_root|.
all_packages = [package_path] + package_deps
for next_package_path in all_packages:
_PublishPackage(tuf_root, next_package_path)
_WaitForPmServeToBeReady(serve_port)
remote_port = common.ConnectPortForwardingTask(self, serve_port, 0) remote_port = common.ConnectPortForwardingTask(self, serve_port, 0)
self._RegisterAmberRepository(tuf_root, remote_port) self._RegisterAmberRepository(tuf_root, remote_port)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment