* [Qemu-devel] [PATCH 1/3] qemu.py: fix is_running()
2017-07-18 10:15 [Qemu-devel] [PATCH 0/3] scripts/qemu.py small fixes Amador Pahim
@ 2017-07-18 10:15 ` Amador Pahim
2017-07-18 10:15 ` [Qemu-devel] [PATCH 2/3] qemu.py: include debug information on launch error Amador Pahim
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Amador Pahim @ 2017-07-18 10:15 UTC (permalink / raw)
To: qemu-devel; +Cc: armbru, crosa, ldoktor, Amador Pahim
Current implementation is broken. It does not really test if the child
process is running.
The Popen.returncode will only be set after by a poll(), wait() or
communicate(). If the Popen fails to launch a VM, the Popen.returncode
will not turn to None by itself.
Instead of using Popen.returncode, let's use Popen.poll(), which
actually checks if child process has terminated.
Signed-off-by: Amador Pahim <apahim@redhat.com>
---
scripts/qemu.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/scripts/qemu.py b/scripts/qemu.py
index 880e3e8219..f0fade32bd 100644
--- a/scripts/qemu.py
+++ b/scripts/qemu.py
@@ -86,7 +86,7 @@ class QEMUMachine(object):
raise
def is_running(self):
- return self._popen and (self._popen.returncode is None)
+ return self._popen and (self._popen.poll() is None)
def exitcode(self):
if self._popen is None:
--
2.13.3
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [Qemu-devel] [PATCH 2/3] qemu.py: include debug information on launch error
2017-07-18 10:15 [Qemu-devel] [PATCH 0/3] scripts/qemu.py small fixes Amador Pahim
2017-07-18 10:15 ` [Qemu-devel] [PATCH 1/3] qemu.py: fix is_running() Amador Pahim
@ 2017-07-18 10:15 ` Amador Pahim
2017-07-18 10:15 ` [Qemu-devel] [PATCH 3/3] qemu.py: make 'args' public Amador Pahim
2017-07-18 18:59 ` [Qemu-devel] [PATCH 0/3] scripts/qemu.py small fixes no-reply
3 siblings, 0 replies; 5+ messages in thread
From: Amador Pahim @ 2017-07-18 10:15 UTC (permalink / raw)
To: qemu-devel; +Cc: armbru, crosa, ldoktor, Amador Pahim
When launching a VM, if an exception happens and the VM is not
initiated, it is useful to see the qemu command line that was executed
and the output of that command.
Before the patch:
>>> VM = qemu.QEMUMachine('../aarch64-softmmu/qemu-system-aarch64')
>>> VM.launch()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "qemu.py", line 137, in launch
self._post_launch()
File "qemu.py", line 121, in _post_launch
self._qmp.accept()
File "qmp/qmp.py", line 145, in accept
self.__sock, _ = self.__sock.accept()
File "/usr/lib64/python2.7/socket.py", line 206, in accept
sock, addr = self._sock.accept()
socket.timeout: timed out
After the patch:
>>> VM = qemu.QEMUMachine('../aarch64-softmmu/qemu-system-aarch64')
>>> VM.launch()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "qemu.py", line 156, in launch
raise RuntimeError(msg)
RuntimeError: Error launching VM.
Original Exception:
Traceback (most recent call last):
File "qemu.py", line 138, in launch
self._post_launch()
File "qemu.py", line 122, in _post_launch
self._qmp.accept()
File "qmp/qmp.py", line 145, in accept
self.__sock, _ = self.__sock.accept()
File "/usr/lib64/python2.7/socket.py", line 206, in accept
sock, addr = self._sock.accept()
timeout: timed out
Command:
/usr/bin/qemu-system-aarch64 -chardev socket,id=mon,
path=/var/tmp/qemu-23958-monitor.sock -mon chardev=mon,mode=control
-display none -vga none
Output:
qemu-system-aarch64: No machine specified, and there is no default
Use -machine help to list supported machines
Also, if the launch() faces an exception, the 'except' now will use args
to fill the debug information. So this patch assigns 'args' earlier,
assuring it will be available for the 'except'.
Signed-off-by: Amador Pahim <apahim@redhat.com>
---
scripts/qemu.py | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
diff --git a/scripts/qemu.py b/scripts/qemu.py
index f0fade32bd..cf47df4932 100644
--- a/scripts/qemu.py
+++ b/scripts/qemu.py
@@ -18,6 +18,7 @@ import os
import sys
import subprocess
import qmp.qmp
+import traceback
class QEMUMachine(object):
@@ -129,17 +130,30 @@ class QEMUMachine(object):
'''Launch the VM and establish a QMP connection'''
devnull = open('/dev/null', 'rb')
qemulog = open(self._qemu_log_path, 'wb')
+ args = self._wrapper + [self._binary] + self._base_args() + self.args
try:
self._pre_launch()
- args = self._wrapper + [self._binary] + self._base_args() + self._args
self._popen = subprocess.Popen(args, stdin=devnull, stdout=qemulog,
stderr=subprocess.STDOUT, shell=False)
self._post_launch()
except:
+ self._load_io_log()
if self.is_running():
self._popen.kill()
self._popen.wait()
- self._load_io_log()
+ else:
+ exc_type, exc_value, exc_traceback = sys.exc_info()
+ msg = ("Error launching VM.\n"
+ "Original Exception: \n%s\n"
+ "Command:\n%s\n"
+ "Output:\n%s\n" %
+ (''.join(traceback.format_exception(exc_type,
+ exc_value,
+ exc_traceback)),
+ ' '.join(args),
+ self._iolog))
+ self._post_shutdown()
+ raise RuntimeError(msg)
self._post_shutdown()
raise
--
2.13.3
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [Qemu-devel] [PATCH 3/3] qemu.py: make 'args' public
2017-07-18 10:15 [Qemu-devel] [PATCH 0/3] scripts/qemu.py small fixes Amador Pahim
2017-07-18 10:15 ` [Qemu-devel] [PATCH 1/3] qemu.py: fix is_running() Amador Pahim
2017-07-18 10:15 ` [Qemu-devel] [PATCH 2/3] qemu.py: include debug information on launch error Amador Pahim
@ 2017-07-18 10:15 ` Amador Pahim
2017-07-18 18:59 ` [Qemu-devel] [PATCH 0/3] scripts/qemu.py small fixes no-reply
3 siblings, 0 replies; 5+ messages in thread
From: Amador Pahim @ 2017-07-18 10:15 UTC (permalink / raw)
To: qemu-devel; +Cc: armbru, crosa, ldoktor, Amador Pahim
Let's make args public so users can extend it without felling like
abusing the internal API.
Signed-off-by: Amador Pahim <apahim@redhat.com>
---
scripts/qemu.py | 12 ++++++------
tests/qemu-iotests/iotests.py | 18 +++++++++---------
2 files changed, 15 insertions(+), 15 deletions(-)
diff --git a/scripts/qemu.py b/scripts/qemu.py
index cf47df4932..d3e19ad695 100644
--- a/scripts/qemu.py
+++ b/scripts/qemu.py
@@ -34,7 +34,7 @@ class QEMUMachine(object):
self._qemu_log_path = os.path.join(test_dir, name + ".log")
self._popen = None
self._binary = binary
- self._args = list(args) # Force copy args in case we modify them
+ self.args = list(args) # Force copy args in case we modify them
self._wrapper = wrapper
self._events = []
self._iolog = None
@@ -44,8 +44,8 @@ class QEMUMachine(object):
# This can be used to add an unused monitor instance.
def add_monitor_telnet(self, ip, port):
args = 'tcp:%s:%d,server,nowait,telnet' % (ip, port)
- self._args.append('-monitor')
- self._args.append(args)
+ self.args.append('-monitor')
+ self.args.append(args)
def add_fd(self, fd, fdset, opaque, opts=''):
'''Pass a file descriptor to the VM'''
@@ -55,8 +55,8 @@ class QEMUMachine(object):
if opts:
options.append(opts)
- self._args.append('-add-fd')
- self._args.append(','.join(options))
+ self.args.append('-add-fd')
+ self.args.append(','.join(options))
return self
def send_fd_scm(self, fd_file_path):
@@ -168,7 +168,7 @@ class QEMUMachine(object):
exitcode = self._popen.wait()
if exitcode < 0:
- sys.stderr.write('qemu received signal %i: %s\n' % (-exitcode, ' '.join(self._args)))
+ sys.stderr.write('qemu received signal %i: %s\n' % (-exitcode, ' '.join(self.args)))
self._load_io_log()
self._post_shutdown()
diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
index abcf3c10e2..6925d8841e 100644
--- a/tests/qemu-iotests/iotests.py
+++ b/tests/qemu-iotests/iotests.py
@@ -150,13 +150,13 @@ class VM(qtest.QEMUQtestMachine):
self._num_drives = 0
def add_device(self, opts):
- self._args.append('-device')
- self._args.append(opts)
+ self.args.append('-device')
+ self.args.append(opts)
return self
def add_drive_raw(self, opts):
- self._args.append('-drive')
- self._args.append(opts)
+ self.args.append('-drive')
+ self.args.append(opts)
return self
def add_drive(self, path, opts='', interface='virtio', format=imgfmt):
@@ -172,17 +172,17 @@ class VM(qtest.QEMUQtestMachine):
if opts:
options.append(opts)
- self._args.append('-drive')
- self._args.append(','.join(options))
+ self.args.append('-drive')
+ self.args.append(','.join(options))
self._num_drives += 1
return self
def add_blockdev(self, opts):
- self._args.append('-blockdev')
+ self.args.append('-blockdev')
if isinstance(opts, str):
- self._args.append(opts)
+ self.args.append(opts)
else:
- self._args.append(','.join(opts))
+ self.args.append(','.join(opts))
return self
def pause_drive(self, drive, event=None):
--
2.13.3
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH 0/3] scripts/qemu.py small fixes
2017-07-18 10:15 [Qemu-devel] [PATCH 0/3] scripts/qemu.py small fixes Amador Pahim
` (2 preceding siblings ...)
2017-07-18 10:15 ` [Qemu-devel] [PATCH 3/3] qemu.py: make 'args' public Amador Pahim
@ 2017-07-18 18:59 ` no-reply
3 siblings, 0 replies; 5+ messages in thread
From: no-reply @ 2017-07-18 18:59 UTC (permalink / raw)
To: apahim; +Cc: famz, qemu-devel, ldoktor, armbru, crosa
Hi,
This series seems to have some coding style problems. See output below for
more information:
Subject: [Qemu-devel] [PATCH 0/3] scripts/qemu.py small fixes
Message-id: 20170718101521.1223-1-apahim@redhat.com
Type: series
=== TEST SCRIPT BEGIN ===
#!/bin/bash
BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0
git config --local diff.renamelimit 0
git config --local diff.renames True
commits="$(git log --format=%H --reverse $BASE..)"
for c in $commits; do
echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
failed=1
echo
fi
n=$((n+1))
done
exit $failed
=== TEST SCRIPT END ===
Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
Switched to a new branch 'test'
3f76a61 qemu.py: make 'args' public
0153001 qemu.py: include debug information on launch error
31a1f63 qemu.py: fix is_running()
=== OUTPUT BEGIN ===
Checking PATCH 1/3: qemu.py: fix is_running()...
Checking PATCH 2/3: qemu.py: include debug information on launch error...
ERROR: unnecessary whitespace before a quoted newline
#94: FILE: scripts/qemu.py:147:
+ "Original Exception: \n%s\n"
total: 1 errors, 0 warnings, 39 lines checked
Your patch has style problems, please review. If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
Checking PATCH 3/3: qemu.py: make 'args' public...
ERROR: line over 90 characters
#52: FILE: scripts/qemu.py:171:
+ sys.stderr.write('qemu received signal %i: %s\n' % (-exitcode, ' '.join(self.args)))
total: 1 errors, 0 warnings, 75 lines checked
Your patch has style problems, please review. If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
=== OUTPUT END ===
Test command exited with code: 1
---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to patchew-devel@freelists.org
^ permalink raw reply [flat|nested] 5+ messages in thread