scripts/qemu.py small fixes
cover scripts/qemu.py small fixes
First commit fixes the 'is_running()' method, which is not working currently.
Second commit includes the qemu command line and its output when there's an exception during the launch() and the VM is not started.
Last commit renames self._args to self.args. The leading underscore represents that the variable is private and as such it should not be accessed externally. But that variable is the main API for inclusion of Qemu command arguments, so the rename makes it public.
Amador Pahim (3):
qemu.py: fix is_running()
qemu.py: include debug information on launch error qemu.py: make 'args' public
scripts/qemu.py | 32 +++++++++++++++++++++++--------- tests/qemu-iotests/iotests.py | 18 +++++++++--------- 2 files changed, 32 insertions(+), 18 deletions(-)
Signature · 1 line
2.13.3
PATCH 1/3 qemu.py: fix is_running()
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.
--- scripts/qemu.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/qemu.py +1 -1
@@ -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:
Signature · 1 line
2.13.3
PATCH 2/3 qemu.py: include debug information on launch error
In reply to Amador PahimWhen 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:
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
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:
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
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'.
--- scripts/qemu.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)
scripts/qemu.py +16 -2
@@ -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
Signature · 1 line
2.13.3
PATCH 3/3 qemu.py: make 'args' public
In reply to Amador PahimLet's make args public so users can extend it without felling like abusing the internal API.
--- scripts/qemu.py | 12 ++++++------ tests/qemu-iotests/iotests.py | 18 +++++++++--------- 2 files changed, 15 insertions(+), 15 deletions(-)
scripts/qemu.py +6 -6
@@ -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()
tests/qemu-iotests/iotests.py +9 -9
@@ -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):
Signature · 1 line
2.13.3
This series seems to have some coding style problems. See output below for more information:
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: [email protected]
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 [email protected]