Commit 2945c6da authored by Stephen Roe's avatar Stephen Roe Committed by Commit Bot

[fuchsia] Add diagnostics for qemu-img fuchsia image generation errors.

Reports qemu-img exit code and command output.  The exit code allows
locating these intermittent errors via BigQuery.  Logging the command
output will give more information on the failure.

See http://crbug.com/1063106#c7

Bug: 1063106
Change-Id: I60d7240eb4183e70ae25aa8efb514ba05ac356df
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2208109
Commit-Queue: Stephen Roe <steveroe@google.com>
Reviewed-by: default avatarWez <wez@chromium.org>
Cr-Commit-Position: refs/heads/master@{#770232}
parent 81d41d48
...@@ -18,6 +18,7 @@ TODO(crbug.com/1046861): Remove this workaround when the bug is fixed. ...@@ -18,6 +18,7 @@ TODO(crbug.com/1046861): Remove this workaround when the bug is fixed.
import logging import logging
import subprocess import subprocess
import tempfile
import time import time
...@@ -33,7 +34,9 @@ def _ExecQemuImgWithTimeout(command): ...@@ -33,7 +34,9 @@ def _ExecQemuImgWithTimeout(command):
""" """
logging.info('qemu-img starting') logging.info('qemu-img starting')
p = subprocess.Popen(command) command_output_file = tempfile.NamedTemporaryFile('w')
p = subprocess.Popen(command, stdout=command_output_file,
stderr=subprocess.STDOUT)
start_sec = time.time() start_sec = time.time()
while p.poll() is None and time.time() - start_sec < QEMU_IMG_TIMEOUT_SEC: while p.poll() is None and time.time() - start_sec < QEMU_IMG_TIMEOUT_SEC:
time.sleep(1) time.sleep(1)
...@@ -41,10 +44,17 @@ def _ExecQemuImgWithTimeout(command): ...@@ -41,10 +44,17 @@ def _ExecQemuImgWithTimeout(command):
logging.info('qemu-img duration: %f' % float(stop_sec - start_sec)) logging.info('qemu-img duration: %f' % float(stop_sec - start_sec))
if p.poll() is None: if p.poll() is None:
returncode = None
p.kill() p.kill()
return None p.wait()
else:
returncode = p.returncode
return p.returncode log_level = logging.WARN if returncode else logging.DEBUG
for line in open(command_output_file.name, 'r'):
logging.log(log_level, 'qemu-img stdout: ' + line.strip())
return returncode
def ExecQemuImgWithRetry(command): def ExecQemuImgWithRetry(command):
......
...@@ -67,9 +67,12 @@ def HandleExceptionAndReturnExitCode(): ...@@ -67,9 +67,12 @@ def HandleExceptionAndReturnExitCode():
return 73 return 73
return 72 return 72
elif type is subprocess.CalledProcessError: elif type is subprocess.CalledProcessError:
if value.cmd[0] == 'scp': if os.path.basename(value.cmd[0]) == 'scp':
print('Error: scp operation failed - %s' % str(value)) print('Error: scp operation failed - %s' % str(value))
return 81 return 81
if os.path.basename(value.cmd[0]) == 'qemu-img':
print('Error: qemu-img fuchsia image generation failed.')
return 82
return 80 return 80
else: else:
return 1 return 1
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