From: "Aníbal Limón" <anibal.limon@linux.intel.com>
To: yocto@yoctoproject.org
Cc: richard.purdie@intel.com, benjamin.esquivel@intel.com
Subject: [[PATCH][qa-tools] 06/16] tests/toaster/helpers.py: Fix toaster_start deadlocks.
Date: Tue, 9 Feb 2016 16:43:15 -0600 [thread overview]
Message-ID: <1455057798-3213-7-git-send-email-anibal.limon@linux.intel.com> (raw)
In-Reply-To: <1455057798-3213-1-git-send-email-anibal.limon@linux.intel.com>
When call toaster_start on failing scenarios (already started) it
becomes blocked on process.communicate() function so add my own
function for solve this issue.
The new function uses a tempfile instead of PIPE for avoid deadlocks.
Signed-off-by: Aníbal Limón <anibal.limon@linux.intel.com>
---
tests/toaster/helpers.py | 38 ++++++++++++++++++++++++++++++++++----
1 file changed, 34 insertions(+), 4 deletions(-)
diff --git a/tests/toaster/helpers.py b/tests/toaster/helpers.py
index 7b82e88..5e54723 100644
--- a/tests/toaster/helpers.py
+++ b/tests/toaster/helpers.py
@@ -2,17 +2,47 @@ import subprocess
import os
import shutil
import signal
+import tempfile
TOASTER_TEST_BRANCH = 'toaster_tests'
VENV_NAME = 'venv'
SHELL_CMD = os.environ['SHELL'] if 'SHELL' in os.environ else "/bin/bash"
+def _check_output1(*popenargs, **kwargs):
+ """
+ Almost the same as subprocess.check_output but change the stdout from
+ PIPE to tempfile to avoid deadlocks when trying to read the PIPE using
+ communicate(). This scenario can be seen calling toaster_start on failure
+ scenarios.
+
+ This causes a little overhead by the tempfile.
+ """
+
+ f = tempfile.TemporaryFile(mode='rw+')
+ if 'stdout' in kwargs:
+ raise ValueError('stdout argument not allowed, it will be overridden.')
+ process = subprocess.Popen(stdout=f, *popenargs, **kwargs)
+ retcode = process.wait()
+
+ f.flush()
+ os.fsync(f.fileno())
+ f.seek(0, 0)
+ output = f.read()
+ f.close()
+
+ if retcode:
+ cmd = kwargs.get("args")
+ if cmd is None:
+ cmd = popenargs[0]
+ raise subprocess.CalledProcessError(retcode, cmd, output=output)
+ return output
+
def _execute_command(directory, cmd):
- subprocess.check_call([SHELL_CMD, "-c", "cd %s; %s" % \
+ return _check_output1([SHELL_CMD, "-c", "cd %s; %s" % \
(directory, cmd)], stderr=subprocess.STDOUT)
def _execute_command_venv(directory, venv, cmd):
- _execute_command(directory, "source %s/%s/bin/activate; %s" % \
+ return _execute_command(directory, "source %s/%s/bin/activate; %s" % \
(directory, venv, cmd))
def toaster_clone(directory, repo, ref='master', rm=False):
@@ -33,11 +63,11 @@ def toaster_setup(directory):
" bitbake/toaster-requirements.txt")
def toaster_start(directory):
- _execute_command_venv(directory, VENV_NAME,
+ return _execute_command_venv(directory, VENV_NAME,
"source %s/oe-init-build-env; source %s/bitbake/bin/toaster start" % \
(directory, directory))
def toaster_stop(directory):
- _execute_command_venv(directory, VENV_NAME,
+ return _execute_command_venv(directory, VENV_NAME,
"source %s/oe-init-build-env; source %s/bitbake/bin/toaster stop" % \
(directory, directory))
--
2.1.4
next prev parent reply other threads:[~2016-02-09 22:41 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-09 22:43 [[PATCH][qa-tools] 00/16] Add Toaster test suite support Aníbal Limón
2016-02-09 22:43 ` [[PATCH][qa-tools] 01/16] README.md: Update instructions on how install host deps on debian Aníbal Limón
2016-02-09 22:43 ` [[PATCH][qa-tools] 02/16] utils/run/toaster.sh: Get rid of toaster shell script Aníbal Limón
2016-02-09 22:43 ` [[PATCH][qa-tools] 03/16] toaster: Add helpers for clone, setup, start and stop Aníbal Limón
2016-02-09 22:43 ` [[PATCH][qa-tools] 04/16] tests/toaster/__init__.py: Add support for clone/setup/start/stop Aníbal Limón
2016-02-09 22:43 ` [[PATCH][qa-tools] 05/16] tests/toaster/helpers.py: When execute bash remove interactive mode Aníbal Limón
2016-02-09 22:43 ` Aníbal Limón [this message]
2016-02-09 22:43 ` [[PATCH][qa-tools] 07/16] ts/toaster/helpers.py: Add new class ToasterHelper instead functions Aníbal Limón
2016-02-09 22:43 ` [[PATCH][qa-tools] 08/16] toaster/helper.py: Add force mode to stop method Aníbal Limón
2016-02-09 22:43 ` [[PATCH][qa-tools] 09/16] toaster/__init__.py: Update toaster test to match new ToasterHelper Aníbal Limón
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1455057798-3213-7-git-send-email-anibal.limon@linux.intel.com \
--to=anibal.limon@linux.intel.com \
--cc=benjamin.esquivel@intel.com \
--cc=richard.purdie@intel.com \
--cc=yocto@yoctoproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.