migration: fix, perf testing framework
The following changes since commit 206d0c24361a083fbdcb2cc86fb75dc8b7f251a2:
Merge remote-tracking branch 'remotes/mst/tags/for_upstream' into staging (2016-07-21 20:12:37 +0100)
are available in the git repository at:
http://git.kernel.org/pub/scm/virt/qemu/amit/migration.git tags/migration-for-2.7-6
for you to fetch changes up to 409437e16df273fc5f78f6cd1cb53023eaeb9b72:
tests: introduce a framework for testing migration performance (2016-07-22 13:23:39 +0530)
----------------------------------------------------------------
Migration:
- Fix a postcopy bug
- Add a testsuite for measuring migration performance
----------------------------------------------------------------
Daniel P. Berrange (6):
scripts: add __init__.py file to scripts/qmp/
scripts: add a 'debug' parameter to QEMUMonitorProtocol
scripts: refactor the VM class in iotests for reuse
scripts: set timeout when waiting for qemu monitor connection
scripts: ensure monitor socket has SO_REUSEADDR set
tests: introduce a framework for testing migration performance
Dr. David Alan Gilbert (1):
migration: set state to post-migrate on failure
configure | 2 + migration/migration.c | 4 + scripts/qemu.py | 202 +++++++++++ scripts/qmp/__init__.py | 0 scripts/qmp/qmp.py | 15 +- scripts/qtest.py | 34 ++ tests/Makefile.include | 12 + tests/migration/.gitignore | 2 + tests/migration/guestperf-batch.py | 26 ++ tests/migration/guestperf-plot.py | 26 ++ tests/migration/guestperf.py | 27 ++ tests/migration/guestperf/__init__.py | 0 tests/migration/guestperf/comparison.py | 124 +++++++ tests/migration/guestperf/engine.py | 439 ++++++++++++++++++++++ tests/migration/guestperf/hardware.py | 62 ++++ tests/migration/guestperf/plot.py | 623 ++++++++++++++++++++++++++++++++ tests/migration/guestperf/progress.py | 117 ++++++ tests/migration/guestperf/report.py | 98 +++++ tests/migration/guestperf/scenario.py | 95 +++++ tests/migration/guestperf/shell.py | 255 +++++++++++++ tests/migration/guestperf/timings.py | 55 +++ tests/migration/stress.c | 367 +++++++++++++++++++ tests/qemu-iotests/iotests.py | 135 +------ 23 files changed, 2587 insertions(+), 133 deletions(-) create mode 100644 scripts/qemu.py create mode 100644 scripts/qmp/__init__.py create mode 100644 tests/migration/.gitignore create mode 100755 tests/migration/guestperf-batch.py create mode 100755 tests/migration/guestperf-plot.py create mode 100755 tests/migration/guestperf.py create mode 100644 tests/migration/guestperf/__init__.py create mode 100644 tests/migration/guestperf/comparison.py create mode 100644 tests/migration/guestperf/engine.py create mode 100644 tests/migration/guestperf/hardware.py create mode 100644 tests/migration/guestperf/plot.py create mode 100644 tests/migration/guestperf/progress.py create mode 100644 tests/migration/guestperf/report.py create mode 100644 tests/migration/guestperf/scenario.py create mode 100644 tests/migration/guestperf/shell.py create mode 100644 tests/migration/guestperf/timings.py create mode 100644 tests/migration/stress.c
Signature · 1 line
2.7.4
[Qemu-devel] [PULL 2/7] scripts: add __init__.py file to scripts/qmp/
From: "Daniel P. Berrange" <[email protected]>
When searching for modules to load, python will ignore any sub-directory which does not contain __init__.py. This means that both scripts and scripts/qmp/ have to be explicitly added to the python path. By adding a __init__.py file to scripts/qmp, we only need add scripts/ to the python path and can then simply do 'from qmp import qmp' to load scripts/qmp/qmp.py.
Message-Id: <[email protected]>
--- scripts/qmp/__init__.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 scripts/qmp/__init__.py
scripts/qmp/__init__.py new file +0 -0
Signature · 1 line
2.7.4
[Qemu-devel] [PULL 1/7] migration: set state to post-migrate on failure
In reply to Amit ShahFrom: "Dr. David Alan Gilbert" <[email protected]>
If a migration fails/is cancelled during the postcopy stage we currently end up with the runstate as finish-migrate, where it should be post-migrate. There's a small window in precopy where I think the same thing can happen, but I've never seen it.
It rarely matters; the only postcopy case is if you restart a migration, which again is a case that rarely matters in postcopy because it's only safe to restart the migration if you know the destination hasn't been running (which you might if you started the destination with -S and hadn't got around to 'c' ing it before the postcopy failed). Even then it's a small window but potentially you could hit if there's a problem loading the devices on the destination.
This corresponds to:
https://bugzilla.redhat.com/show_bug.cgi?id=1355683
Message-Id: <[email protected]>
--- migration/migration.c | 4 ++++ 1 file changed, 4 insertions(+)
migration/migration.c +4 -0
@@ -1837,6 +1837,10 @@ static void *migration_thread(void *opaque) }else {if (old_vm_running && !entered_postcopy) {vm_start (); + }else { +if (runstate_check (RUN_STATE_FINISH_MIGRATE )) { +runstate_set (RUN_STATE_POSTMIGRATE ); + } } }qemu_bh_schedule (s->cleanup_bh);
Signature · 1 line
2.7.4
[Qemu-devel] [PULL 3/7] scripts: add a 'debug' parameter to QEMUMonitorProtocol
In reply to Amit ShahFrom: "Daniel P. Berrange" <[email protected]>
Add a 'debug' parameter to the QEMUMonitorProtocol class which will cause it to print out all JSON strings on sys.stderr
Message-Id: <[email protected]>
--- scripts/qmp/qmp.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
scripts/qmp/qmp.py +11 -2
@@ -11,6 +11,7 @@ import json import errno import socket +import sys class QMPError(Exception): pass
@@ -25,7 +26,7 @@ class QMPTimeoutError(QMPError): pass class QEMUMonitorProtocol: - def __init__(self, address, server=False): + def __init__(self, address, server=False, debug=False): """ Create a QEMUMonitorProtocol class.
@@ -39,6 +40,7 @@ class QEMUMonitorProtocol: """ self.__events = [] self.__address = address + self._debug = debug self.__sock = self.__get_sock() if server: self.__sock.bind(self.__address)
@@ -68,6 +70,8 @@ class QEMUMonitorProtocol: return resp = json.loads(data) if 'event' in resp: + if self._debug: + print >>sys.stderr, "QMP:<<< %s" % resp self.__events.append(resp) if not only_event: continue
@@ -148,13 +152,18 @@ class QEMUMonitorProtocol: @return QMP response as a Python dict or None if the connection has been closed """ + if self._debug: + print >>sys.stderr, "QMP:>>> %s" % qmp_cmd try: self.__sock.sendall(json.dumps(qmp_cmd)) except socket.error as err: if err[0] == errno.EPIPE: return raise socket.error(err) - return self.__json_read() + resp = self.__json_read() + if self._debug: + print >>sys.stderr, "QMP:<<< %s" % resp + return resp def cmd(self, name, args=None, id=None): """
Signature · 1 line
2.7.4
[Qemu-devel] [PULL 4/7] scripts: refactor the VM class in iotests for reuse
In reply to Amit ShahFrom: "Daniel P. Berrange" <[email protected]>
The iotests module has a python class for controlling QEMU processes. Pull the generic functionality out of this file and create a scripts/qemu.py module containing a QEMUMachine class. Put the QTest integration support into a subclass QEMUQtestMachine.
Message-Id: <[email protected]>
--- scripts/qemu.py | 202 ++++++++++++++++++++++++++++++++++++++++++ scripts/qtest.py | 34 +++++++ tests/qemu-iotests/iotests.py | 135 +--------------------------- 3 files changed, 240 insertions(+), 131 deletions(-) create mode 100644 scripts/qemu.py
scripts/qemu.py new file +202 -0
@@ -0,0 +1,202 @@ +# QEMU library +# +# Copyright (C) 2015-2016 Red Hat Inc. +# Copyright (C) 2012 IBM Corp. +# +# Authors: +# Fam Zheng <[email protected]> +# +# This work is licensed under the terms of the GNU GPL, version 2. See +# the COPYING file in the top-level directory. +# +# Based on qmp.py. +# + +import errno +import string +import os +import sys +import subprocess +import qmp.qmp + + +class QEMUMachine(object): + '''A QEMU VM''' + + def __init__(self, binary, args=[], wrapper=[], name=None, test_dir="/var/tmp", + monitor_address=None, debug=False): + if name is None: + name = "qemu-%d" % os.getpid() + if monitor_address is None: + monitor_address = os.path.join(test_dir, name + "-monitor.sock") + self._monitor_address = monitor_address + self._qemu_log_path = os.path.join(test_dir, name + ".log") + self._popen = None + self._binary = binary + self._args = args + self._wrapper = wrapper + self._events = [] + self._iolog = None + self._debug = debug + + # 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) + + def add_fd(self, fd, fdset, opaque, opts=''): + '''Pass a file descriptor to the VM''' + options = ['fd=%d' % fd, + 'set=%d' % fdset, + 'opaque=%s' % opaque] + if opts: + options.append(opts) + + self._args.append('-add-fd') + self._args.append(','.join(options)) + return self + + def send_fd_scm(self, fd_file_path): + # In iotest.py, the qmp should always use unix socket. + assert self._qmp.is_scm_available() + bin = socket_scm_helper + if os.path.exists(bin) == False: + print "Scm help program does not present, path '%s'." % bin + return -1 + fd_param = ["%s" % bin, + "%d" % self._qmp.get_sock_fd(), + "%s" % fd_file_path] + devnull = open('/dev/null', 'rb') + p = subprocess.Popen(fd_param, stdin=devnull, stdout=sys.stdout, + stderr=sys.stderr) + return p.wait() + + @staticmethod + def _remove_if_exists(path): + '''Remove file object at path if it exists''' + try: + os.remove(path) + except OSError as exception: + if exception.errno == errno.ENOENT: + return + raise + + def get_pid(self): + if not self._popen: + return None + return self._popen.pid + + def _load_io_log(self): + with open(self._qemu_log_path, "r") as fh: + self._iolog = fh.read() + + def _base_args(self): + if isinstance(self._monitor_address, tuple): + moncdev = "socket,id=mon,host=%s,port=%s" % ( + self._monitor_address[0], + self._monitor_address[1]) + else: + moncdev = 'socket,id=mon,path=%s' % self._monitor_address + return ['-chardev', moncdev, + '-mon', 'chardev=mon,mode=control', + '-display', 'none', '-vga', 'none'] + + def _pre_launch(self): + self._qmp = qmp.qmp.QEMUMonitorProtocol(self._monitor_address, server=True, + debug=self._debug) + + def _post_launch(self): + self._qmp.accept() + + def _post_shutdown(self): + if not isinstance(self._monitor_address, tuple): + self._remove_if_exists(self._monitor_address) + self._remove_if_exists(self._qemu_log_path) + + def launch(self): + '''Launch the VM and establish a QMP connection''' + devnull = open('/dev/null', 'rb') + qemulog = open(self._qemu_log_path, 'wb') + 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: + if self._popen: + self._popen.kill() + self._load_io_log() + self._post_shutdown() + self._popen = None + raise + + def shutdown(self): + '''Terminate the VM and clean up''' + if not self._popen is None: + try: + self._qmp.cmd('quit') + self._qmp.close() + except: + self._popen.kill() + + exitcode = self._popen.wait() + if exitcode < 0: + sys.stderr.write('qemu received signal %i: %s\n' % (-exitcode, ' '.join(self._args))) + self._load_io_log() + self._post_shutdown() + self._popen = None + + underscore_to_dash = string.maketrans('_', '-') + def qmp(self, cmd, conv_keys=True, **args): + '''Invoke a QMP command and return the result dict''' + qmp_args = dict() + for k in args.keys(): + if conv_keys: + qmp_args[k.translate(self.underscore_to_dash)] = args[k] + else: + qmp_args[k] = args[k] + + return self._qmp.cmd(cmd, args=qmp_args) + + def command(self, cmd, conv_keys=True, **args): + reply = self.qmp(cmd, conv_keys, **args) + if reply is None: + raise Exception("Monitor is closed") + if "error" in reply: + raise Exception(reply["error"]["desc"]) + return reply["return"] + + def get_qmp_event(self, wait=False): + '''Poll for one queued QMP events and return it''' + if len(self._events) > 0: + return self._events.pop(0) + return self._qmp.pull_event(wait=wait) + + def get_qmp_events(self, wait=False): + '''Poll for queued QMP events and return a list of dicts''' + events = self._qmp.get_events(wait=wait) + events.extend(self._events) + del self._events[:] + self._qmp.clear_events() + return events + + def event_wait(self, name, timeout=60.0, match=None): + # Search cached events + for event in self._events: + if (event['event'] == name) and event_match(event, match): + self._events.remove(event) + return event + + # Poll for new events + while True: + event = self._qmp.pull_event(wait=timeout) + if (event['event'] == name) and event_match(event, match): + return event + self._events.append(event) + + return None + + def get_log(self): + return self._iolog
scripts/qtest.py +34 -0
@@ -13,6 +13,11 @@ import errno import socket +import string +import os +import subprocess +import qmp.qmp +import qemu class QEMUQtestProtocol(object): def __init__(self, address, server=False):
@@ -69,3 +74,32 @@ class QEMUQtestProtocol(object): def settimeout(self, timeout): self._sock.settimeout(timeout) + + +class QEMUQtestMachine(qemu.QEMUMachine): + '''A QEMU VM''' + + def __init__(self, binary, args=[], name=None, test_dir="/var/tmp"): + super(self, QEMUQtestMachine).__init__(binary, args, name, test_dir) + self._qtest_path = os.path.join(test_dir, name + "-qtest.sock") + + def _base_args(self): + args = super(self, QEMUQtestMachine)._base_args() + args.extend(['-qtest', 'unix:path=' + self._qtest_path]) + return args + + def _pre_launch(self): + super(self, QEMUQtestMachine)._pre_launch() + self._qtest = QEMUQtestProtocol(self._qtest_path, server=True) + + def _post_launch(self): + super(self, QEMUQtestMachine)._post_launch() + self._qtest.accept() + + def _post_shutdown(self): + super(self, QEMUQtestMachine)._post_shutdown() + self._remove_if_exists(self._qtest_path) + + def qtest(self, cmd): + '''Send a qtest command to guest''' + return self._qtest.cmd(cmd)
tests/qemu-iotests/iotests.py +4 -131
169 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PULL 4/7] scripts: refactor the VM class in iotests for reuse
Quoted 17 lines · Amit Shah
From: "Daniel P. Berrange" <[email protected]>
The iotests module has a python class for controlling QEMU processes. Pull the generic functionality out of this file and create a
scripts/qemu.pymodule containing a QEMUMachine class. Put the QTest integration support into a subclass QEMUQtestMachine.Signed-off-by Daniel P. Berrange <[email protected]>Message-Id: <[email protected]>
Signed-off-by Amit Shah <[email protected]>--- scripts/qemu.py | 202 ++++++++++++++++++++++++++++++++++++++++++ scripts/qtest.py | 34 +++++++ tests/qemu-iotests/iotests.py | 135 +--------------------------- 3 files changed, 240 insertions(+), 131 deletions(-) create mode 100644 scripts/qemu.py
[...]
Quoted 4 lines
tests/qemu-iotests/iotests.py +0
-0
[...]
tests/qemu-iotests/iotests.py def event_match(event, match=None): · line 148
Quoted 6 lines
tests/qemu-iotests/iotests.py +1
-1@@ -148,27 +145,12 @@ def event_match(event, match=None): return True -class VM(object): +class VM(qtest.QEMUMachine):
Should this not be qtest.QEMUQtestMachine?
With QEMUMachine, I get failures like this when attempting to run tests for the wrong format (e.g. ./check -raw 30):
Traceback (most recent call last):
File "030", line 23, in <module>
import iotests
File "./tests/qemu-iotests/iotests.py", line 148, in <module>
class VM(qtest.QEMUMachine):
AttributeError: 'module' object has no attribute 'QEMUMachine
Max
Quoted 24 lines
tests/qemu-iotests/iotests.py +1
-16'''A QEMU VM''' def __init__(self): - self._monitor_path = os.path.join(test_dir, 'qemu-mon.%d' % os.getpid()) - self._qemu_log_path = os.path.join(test_dir, 'qemu-log.%d' % os.getpid()) - self._qtest_path = os.path.join(test_dir, 'qemu-qtest.%d' % os.getpid()) - self._args = qemu_args + ['-chardev', - 'socket,id=mon,path=' + self._monitor_path, - '-mon', 'chardev=mon,mode=control', - '-qtest', 'unix:path=' + self._qtest_path, - '-machine', 'accel=qtest', - '-display', 'none', '-vga', 'none'] + super(self, VM).__init__(qemu_prog, qemu_opts, test_dir) self._num_drives = 0 - self._events = [] - - # 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) def add_drive_raw(self, opts): self._args.append('-drive')
Re: [Qemu-devel] [PULL 4/7] scripts: refactor the VM class in iotests for reuse
In reply to Amit ShahQuoted 9 lines · Amit Shah
From: "Daniel P. Berrange" <[email protected]>
The iotests module has a python class for controlling QEMU processes. Pull the generic functionality out of this file and create a
scripts/qemu.pymodule containing a QEMUMachine class. Put the QTest integration support into a subclass QEMUQtestMachine.Signed-off-by Daniel P. Berrange <[email protected]>
Quoted 8 lines
Message-Id: <[email protected]>
Signed-off-by Amit Shah <[email protected]>--- scripts/qemu.py | 202 ++++++++++++++++++++++++++++++++++++++++++ scripts/qtest.py | 34 +++++++ tests/qemu-iotests/iotests.py | 135 +--------------------------- 3 files changed, 240 insertions(+), 131 deletions(-) create mode 100644 scripts/qemu.py
Hm, I have even more questions...
(I'm starting to wonder if I'm doing anything horribly wrong, because this patch basically completely breaks the Python iotests for me.)
Quoted 119 lines
scripts/qemu.py new file +113
-0@@ -0,0 +1,202 @@ +# QEMU library +# +# Copyright (C) 2015-2016 Red Hat Inc. +# Copyright (C) 2012 IBM Corp. +# +# Authors: +# Fam Zheng <[email protected]> +# +# This work is licensed under the terms of the GNU GPL, version 2. See +# the COPYING file in the top-level directory. +# +# Based on qmp.py. +# + +import errno +import string +import os +import sys +import subprocess +import qmp.qmp + + +class QEMUMachine(object): + '''A QEMU VM''' + + def __init__(self, binary, args=[], wrapper=[], name=None, test_dir="/var/tmp", + monitor_address=None, debug=False): + if name is None: + name = "qemu-%d" % os.getpid() + if monitor_address is None: + monitor_address = os.path.join(test_dir, name + "-monitor.sock") + self._monitor_address = monitor_address + self._qemu_log_path = os.path.join(test_dir, name + ".log") + self._popen = None + self._binary = binary + self._args = args + self._wrapper = wrapper + self._events = [] + self._iolog = None + self._debug = debug + + # 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) + + def add_fd(self, fd, fdset, opaque, opts=''): + '''Pass a file descriptor to the VM''' + options = ['fd=%d' % fd, + 'set=%d' % fdset, + 'opaque=%s' % opaque] + if opts: + options.append(opts) + + self._args.append('-add-fd') + self._args.append(','.join(options)) + return self + + def send_fd_scm(self, fd_file_path): + # In iotest.py, the qmp should always use unix socket. + assert self._qmp.is_scm_available() + bin = socket_scm_helper + if os.path.exists(bin) == False: + print "Scm help program does not present, path '%s'." % bin + return -1 + fd_param = ["%s" % bin, + "%d" % self._qmp.get_sock_fd(), + "%s" % fd_file_path] + devnull = open('/dev/null', 'rb') + p = subprocess.Popen(fd_param, stdin=devnull, stdout=sys.stdout, + stderr=sys.stderr) + return p.wait() + + @staticmethod + def _remove_if_exists(path): + '''Remove file object at path if it exists''' + try: + os.remove(path) + except OSError as exception: + if exception.errno == errno.ENOENT: + return + raise + + def get_pid(self): + if not self._popen: + return None + return self._popen.pid + + def _load_io_log(self): + with open(self._qemu_log_path, "r") as fh: + self._iolog = fh.read() + + def _base_args(self): + if isinstance(self._monitor_address, tuple): + moncdev = "socket,id=mon,host=%s,port=%s" % ( + self._monitor_address[0], + self._monitor_address[1]) + else: + moncdev = 'socket,id=mon,path=%s' % self._monitor_address + return ['-chardev', moncdev, + '-mon', 'chardev=mon,mode=control', + '-display', 'none', '-vga', 'none'] + + def _pre_launch(self): + self._qmp = qmp.qmp.QEMUMonitorProtocol(self._monitor_address, server=True, + debug=self._debug) + + def _post_launch(self): + self._qmp.accept() + + def _post_shutdown(self): + if not isinstance(self._monitor_address, tuple):
scripts/qemu.py line 123
Quoted 10 lines
scripts/qemu.py new file +10
-0+ self._remove_if_exists(self._monitor_address) + self._remove_if_exists(self._qemu_log_path) + + def launch(self): + '''Launch the VM and establish a QMP connection''' + devnull = open('/dev/null', 'rb') + qemulog = open(self._qemu_log_path, 'wb') + try: + self._pre_launch() + args = self._wrapper + [self._binary] + self._base_args() + self._args
self._binary is already an array. This is because it's taken directly from... [1]
The superfluous array brackets result in:
AttributeError: 'list' object has no attribute 'rfind'
Quoted 62 lines
scripts/qemu.py new file +62
-0+ self._popen = subprocess.Popen(args, stdin=devnull, stdout=qemulog, + stderr=subprocess.STDOUT, shell=False) + self._post_launch() + except: + if self._popen: + self._popen.kill() + self._load_io_log() + self._post_shutdown() + self._popen = None + raise + + def shutdown(self): + '''Terminate the VM and clean up''' + if not self._popen is None: + try: + self._qmp.cmd('quit') + self._qmp.close() + except: + self._popen.kill() + + exitcode = self._popen.wait() + if exitcode < 0: + sys.stderr.write('qemu received signal %i: %s\n' % (-exitcode, ' '.join(self._args))) + self._load_io_log() + self._post_shutdown() + self._popen = None + + underscore_to_dash = string.maketrans('_', '-') + def qmp(self, cmd, conv_keys=True, **args): + '''Invoke a QMP command and return the result dict''' + qmp_args = dict() + for k in args.keys(): + if conv_keys: + qmp_args[k.translate(self.underscore_to_dash)] = args[k] + else: + qmp_args[k] = args[k] + + return self._qmp.cmd(cmd, args=qmp_args) + + def command(self, cmd, conv_keys=True, **args): + reply = self.qmp(cmd, conv_keys, **args) + if reply is None: + raise Exception("Monitor is closed") + if "error" in reply: + raise Exception(reply["error"]["desc"]) + return reply["return"] + + def get_qmp_event(self, wait=False): + '''Poll for one queued QMP events and return it''' + if len(self._events) > 0: + return self._events.pop(0) + return self._qmp.pull_event(wait=wait) + + def get_qmp_events(self, wait=False): + '''Poll for queued QMP events and return a list of dicts''' + events = self._qmp.get_events(wait=wait) + events.extend(self._events) + del self._events[:] + self._qmp.clear_events() + return events + + def event_wait(self, name, timeout=60.0, match=None):
scripts/qemu.py line 195
Quoted 10 lines
scripts/qemu.py new file +10
-0+ # Search cached events + for event in self._events: + if (event['event'] == name) and event_match(event, match): + self._events.remove(event) + return event + + # Poll for new events + while True: + event = self._qmp.pull_event(wait=timeout) + if (event['event'] == name) and event_match(event, match):
event_match is not defined in this file.
Quoted 24 lines
scripts/qemu.py new file +7
-0+ return event + self._events.append(event) + + return None + + def get_log(self): + return self._iologscripts/qtest.py +5
-0@@ -13,6 +13,11 @@ import errno import socket +import string +import os +import subprocess +import qmp.qmp +import qemu class QEMUQtestProtocol(object): def __init__(self, address, server=False):
scripts/qtest.py class QEMUQtestProtocol(object): · line 83
Quoted 10 lines
scripts/qtest.py +7
-0@@ -69,3 +74,32 @@ class QEMUQtestProtocol(object): def settimeout(self, timeout): self._sock.settimeout(timeout) + + +class QEMUQtestMachine(qemu.QEMUMachine): + '''A QEMU VM''' + + def __init__(self, binary, args=[], name=None, test_dir="/var/tmp"): + super(self, QEMUQtestMachine).__init__(binary, args, name, test_dir)
You're passing name as wrapper. Probably wrong.
Also, shouldn't the arguments to super() be the other way around? I.e. super(QEMUQtestMachine, self)? On one hand, this is what Stack Overflow tells me, and it also makes Python stop complaining when running any Python iotest.
scripts/qtest.py class QEMUQtestProtocol(object): · line 84
Quoted 1 line
scripts/qtest.py +1
-0+ self._qtest_path = os.path.join(test_dir, name + "-qtest.sock")
What if name is None?
Quoted 55 lines
scripts/qtest.py +21
-0+ + def _base_args(self): + args = super(self, QEMUQtestMachine)._base_args() + args.extend(['-qtest', 'unix:path=' + self._qtest_path]) + return args + + def _pre_launch(self): + super(self, QEMUQtestMachine)._pre_launch() + self._qtest = QEMUQtestProtocol(self._qtest_path, server=True) + + def _post_launch(self): + super(self, QEMUQtestMachine)._post_launch() + self._qtest.accept() + + def _post_shutdown(self): + super(self, QEMUQtestMachine)._post_shutdown() + self._remove_if_exists(self._qtest_path) + + def qtest(self, cmd): + '''Send a qtest command to guest''' + return self._qtest.cmd(cmd)tests/qemu-iotests/iotests.py +3
-6@@ -24,8 +24,6 @@ import string import unittest import sys sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'scripts')) -sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'scripts', 'qmp')) -import qmp import qtest import struct import json@@ -41,9 +39,8 @@ qemu_io_args = [os.environ.get('QEMU_IO_PROG', 'qemu-io')] if os.environ.get('QEMU_IO_OPTIONS'): qemu_io_args += os.environ['QEMU_IO_OPTIONS'].strip().split(' ') -qemu_args = [os.environ.get('QEMU_PROG', 'qemu')] -if os.environ.get('QEMU_OPTIONS'): - qemu_args += os.environ['QEMU_OPTIONS'].strip().split(' ') +qemu_prog = [os.environ.get('QEMU_PROG', 'qemu')] +qemu_opts = os.environ.get('QEMU_OPTIONS', '').strip().split(' ') imgfmt = os.environ.get('IMGFMT', 'raw') imgproto = os.environ.get('IMGPROTO', 'file')@@ -148,27 +145,12 @@ def event_match(event, match=None): return True -class VM(object): +class VM(qtest.QEMUMachine): '''A QEMU VM''' def __init__(self):
tests/qemu-iotests/iotests.py def event_match(event, match=None): · line 152
Quoted 10 lines
tests/qemu-iotests/iotests.py +1
-9- self._monitor_path = os.path.join(test_dir, 'qemu-mon.%d' % os.getpid()) - self._qemu_log_path = os.path.join(test_dir, 'qemu-log.%d' % os.getpid()) - self._qtest_path = os.path.join(test_dir, 'qemu-qtest.%d' % os.getpid()) - self._args = qemu_args + ['-chardev', - 'socket,id=mon,path=' + self._monitor_path, - '-mon', 'chardev=mon,mode=control', - '-qtest', 'unix:path=' + self._qtest_path, - '-machine', 'accel=qtest', - '-display', 'none', '-vga', 'none'] + super(self, VM).__init__(qemu_prog, qemu_opts, test_dir)
Same super() issue as above.
Also, if this is indeed supposed to subclass qtest.QEMUQtestMachine, then you are passing test_dir as name, which would be wrong.
[1] ...here. qemu_prog is an array.
tests/qemu-iotests/iotests.py def event_match(event, match=None): · line 156
Quoted 11 lines
tests/qemu-iotests/iotests.py +0
-7self._num_drives = 0 - self._events = [] - - # 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) def add_drive_raw(self, opts): self._args.append('-drive')
[...]
But even after working around all of this, I'm still getting a socket timeout which I can't really figure out why. All I know is that the qemu process doesn't seem to get started really well:
$ ps -e | grep qemu 19255 pts/5 00:00:00 qemu-system-x86 <defunct>
The stdout log however is empty and there's no useful output in the iotest itself.
Max
Re: [Qemu-devel] [PULL 4/7] scripts: refactor the VM class in iotests for reuse
Quoted 19 lines · Max Reitz
Quoted 9 lines · Amit Shah
From: "Daniel P. Berrange" <[email protected]>
The iotests module has a python class for controlling QEMU processes. Pull the generic functionality out of this file and create a
scripts/qemu.pymodule containing a QEMUMachine class. Put the QTest integration support into a subclass QEMUQtestMachine.Signed-off-by Daniel P. Berrange <[email protected]>Quoted 8 lines
Message-Id: <[email protected]>
Signed-off-by Amit Shah <[email protected]>--- scripts/qemu.py | 202 ++++++++++++++++++++++++++++++++++++++++++ scripts/qtest.py | 34 +++++++ tests/qemu-iotests/iotests.py | 135 +--------------------------- 3 files changed, 240 insertions(+), 131 deletions(-) create mode 100644 scripts/qemu.py
Quoted 4 lines
Hm, I have even more questions...
(I'm starting to wonder if I'm doing anything horribly wrong, because this patch basically completely breaks the Python iotests for me.)
[snip]
I'll investigate this and send any neccessary fixes asap.
Regards,
Daniel
Signature · 4 lines
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
[Qemu-devel] [PULL 6/7] scripts: ensure monitor socket has SO_REUSEADDR set
In reply to Amit ShahFrom: "Daniel P. Berrange" <[email protected]>
If tests use a TCP based monitor socket, the connection will go into a TIMED_WAIT state when the test exits. This will randomly prevent the test from being re-run without a certain time period. Set the SO_REUSEADDR flag on the socket to ensure we can immediately re-run the tests
Message-Id: <[email protected]>
--- scripts/qmp/qmp.py | 1 + 1 file changed, 1 insertion(+)
scripts/qmp/qmp.py +1 -0
@@ -43,6 +43,7 @@ class QEMUMonitorProtocol: self._debug = debug self.__sock = self.__get_sock() if server: + self.__sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.__sock.bind(self.__address) self.__sock.listen(1)
Signature · 1 line
2.7.4
[Qemu-devel] [PULL 5/7] scripts: set timeout when waiting for qemu monitor connection
In reply to Amit ShahFrom: "Daniel P. Berrange" <[email protected]>
If QEMU fails to launch for some reason, the QEMUMonitorProtocol class accept() method will wait forever in a socket accept call. Set a timeout of 15 seconds so that we fail more gracefully instead of hanging the test script forever
Message-Id: <[email protected]>
--- scripts/qmp/qmp.py | 1 + 1 file changed, 1 insertion(+)
scripts/qmp/qmp.py +1 -0
@@ -140,6 +140,7 @@ class QEMUMonitorProtocol: @raise QMPConnectError if the greeting is not received @raise QMPCapabilitiesError if fails to negotiate capabilities """ + self.__sock.settimeout(15) self.__sock, _ = self.__sock.accept() self.__sockfile = self.__sock.makefile() return self.__negotiate_capabilities()
Signature · 1 line
2.7.4
[Qemu-devel] [PULL 7/7] tests: introduce a framework for testing migration performance
In reply to Amit ShahFrom: "Daniel P. Berrange" <[email protected]>
This introduces a moderately general purpose framework for testing performance of migration.
The initial guest workload is provided by the included 'stress' program, which is configured to spawn one thread per guest CPU and run a maximally memory intensive workload. It will loop over GB of memory, xor'ing each byte with data from a 4k array of random bytes. This ensures heavy read and write load across all of guest memory to stress the migration performance. While running the 'stress' program will record how long it takes to xor each GB of memory and print this data for later reporting.
The test engine will spawn a pair of QEMU processes, either on the same host, or with the target on a remote host via ssh, using the host kernel and a custom initrd built with 'stress' as the /init binary. Kernel command line args are set to ensure a fast kernel boot time (< 1 second) between launching QEMU and the stress program starting execution.
None the less, the test engine will initially wait N seconds for the guest workload to stablize, before starting the migration operation. When migration is running, the engine will use pause, post-copy, autoconverge, xbzrle compression and multithread compression features, as well as downtime & bandwidth tuning to encourage completion. If migration completes, the test engine will wait N seconds again for the guest workooad to stablize on the target host. If migration does not complete after a preset number of iterations, it will be aborted.
While the QEMU process is running on the source host, the test engine will sample the host CPU usage of QEMU as a whole, and each vCPU thread. While migration is running, it will record all the stats reported by 'query-migration'. Finally, it will capture the output of the stress program running in the guest.
All the data produced from a single test execution is recorded in a structured JSON file. A separate program is then able to create interactive charts using the "plotly" python + javascript libraries, showing the characteristics of the migration.
The data output provides visualization of the effect on guest vCPU workloads from the migration process, the corresponding vCPU utilization on the host, and the overall CPU hit from QEMU on the host. This is correlated from statistics from the migration process, such as downtime, vCPU throttling and iteration number.
While the tests can be run individually with arbitrary parameters, there is also a facility for producing batch reports for a number of pre-defined scenarios / comparisons, in order to be able to get standardized results across different hardware configurations (eg TCP vs RDMA, or comparing different VCPU counts / memory sizes, etc).
To use this, first you must build the initrd image
$ make tests/migration/initrd-stress.img
To run a a one-shot test with all default parameters
$ ./tests/migration/guestperf.py > result.json
This has many command line args for varying its behaviour. For example, to increase the RAM size and CPU count and bind it to specific host NUMA nodes
$ ./tests/migration/guestperf.py \
--mem 4 --cpus 2 \
--src-mem-bind 0 --src-cpu-bind 0,1 \
--dst-mem-bind 1 --dst-cpu-bind 2,3 \
> result.jsonUsing mem + cpu binding is strongly recommended on NUMA machines, otherwise the guest performance results will vary wildly between runs of the test due to lucky/unlucky NUMA placement, making sensible data analysis impossible.
To make it run across separate hosts:
$ ./tests/migration/guestperf.py \
--dst-host somehostname > result.jsonTo request that post-copy is enabled, with switchover after 5 iterations
$ ./tests/migration/guestperf.py \
--post-copy --post-copy-iters 5 > result.jsonOnce a result.json file is created, a graph of the data can be generated, showing guest workload performance per thread and the migration iteration points:
$ ./tests/migration/guestperf-plot.py --output result.html \
--migration-iters --split-guest-cpu result.jsonTo further include host vCPU utilization and overall QEMU utilization
$ ./tests/migration/guestperf-plot.py --output result.html \
--migration-iters --split-guest-cpu \
--qemu-cpu --vcpu-cpu result.jsonNB, the 'guestperf-plot.py' command requires that you have the plotly python library installed. eg you must do
$ pip install --user plotly
Viewing the result.html file requires that you have the plotly.min.js file in the same directory as the HTML output. This js file is installed as part of the plotly python library, so can be found in
$HOME/.local/lib/python2.7/site-packages/plotly/offline/plotly.min.js
The guestperf-plot.py program can accept multiple json files to plot, enabling results from different configurations to be compared.
Finally, to run the entire standardized set of comparisons
$ ./tests/migration/guestperf-batch.py \
--dst-host somehost \
--mem 4 --cpus 2 \
--src-mem-bind 0 --src-cpu-bind 0,1 \
--dst-mem-bind 1 --dst-cpu-bind 2,3
--output tcp-somehost-4gb-2cpuwill store JSON files from all scenarios in the directory named tcp-somehost-4gb-2cpu
Message-Id: <[email protected]>
--- configure | 2 + tests/Makefile.include | 12 + tests/migration/.gitignore | 2 + tests/migration/guestperf-batch.py | 26 ++ tests/migration/guestperf-plot.py | 26 ++ tests/migration/guestperf.py | 27 ++ tests/migration/guestperf/__init__.py | 0 tests/migration/guestperf/comparison.py | 124 +++++++ tests/migration/guestperf/engine.py | 439 ++++++++++++++++++++++ tests/migration/guestperf/hardware.py | 62 ++++ tests/migration/guestperf/plot.py | 623 ++++++++++++++++++++++++++++++++ tests/migration/guestperf/progress.py | 117 ++++++ tests/migration/guestperf/report.py | 98 +++++ tests/migration/guestperf/scenario.py | 95 +++++ tests/migration/guestperf/shell.py | 255 +++++++++++++ tests/migration/guestperf/timings.py | 55 +++ tests/migration/stress.c | 367 +++++++++++++++++++ 17 files changed, 2330 insertions(+) create mode 100644 tests/migration/.gitignore create mode 100755 tests/migration/guestperf-batch.py create mode 100755 tests/migration/guestperf-plot.py create mode 100755 tests/migration/guestperf.py create mode 100644 tests/migration/guestperf/__init__.py create mode 100644 tests/migration/guestperf/comparison.py create mode 100644 tests/migration/guestperf/engine.py create mode 100644 tests/migration/guestperf/hardware.py create mode 100644 tests/migration/guestperf/plot.py create mode 100644 tests/migration/guestperf/progress.py create mode 100644 tests/migration/guestperf/report.py create mode 100644 tests/migration/guestperf/scenario.py create mode 100644 tests/migration/guestperf/shell.py create mode 100644 tests/migration/guestperf/timings.py create mode 100644 tests/migration/stress.c
configure +2 -0
@@ -3121,6 +3121,7 @@ else if test "$found" = "no"; then LIBS="$pthread_lib $LIBS" fi + PTHREAD_LIB="$pthread_lib" break fi done
@@ -5537,6 +5538,7 @@ echo "LDFLAGS_NOPIE=$LDFLAGS_NOPIE" >> $config_host_mak echo "LD_REL_FLAGS=$LD_REL_FLAGS" >> $config_host_mak echo "LIBS+=$LIBS" >> $config_host_mak echo "LIBS_TOOLS+=$libs_tools" >> $config_host_mak +echo "PTHREAD_LIB=$PTHREAD_LIB" >> $config_host_mak echo "EXESUF=$EXESUF" >> $config_host_mak echo "DSOSUF=$DSOSUF" >> $config_host_mak echo "LDFLAGS_SHARED=$LDFLAGS_SHARED" >> $config_host_mak
tests/Makefile.include +12 -0
@@ -627,6 +627,18 @@ tests/test-filter-redirector$(EXESUF): tests/test-filter-redirector.o $(qtest-ob tests/ivshmem-test$(EXESUF): tests/ivshmem-test.o contrib/ivshmem-server/ivshmem-server.o $(libqos-pc-obj-y) tests/vhost-user-bridge$(EXESUF): tests/vhost-user-bridge.o +tests/migration/stress$(EXESUF): tests/migration/stress.o + $(call quiet-command, $(LINKPROG) -static -O3 $(PTHREAD_LIB) -o $@ $< ," LINK $(TARGET_DIR)$@") + +INITRD_WORK_DIR=tests/migration/initrd + +tests/migration/initrd-stress.img: tests/migration/stress$(EXESUF) + mkdir -p $(INITRD_WORK_DIR) + cp $< $(INITRD_WORK_DIR)/init + (cd $(INITRD_WORK_DIR) && (find | cpio --quiet -o -H newc | gzip -9)) > $@ + rm $(INITRD_WORK_DIR)/init + rmdir $(INITRD_WORK_DIR) + ifeq ($(CONFIG_POSIX),y) LIBS += -lutil endif
tests/migration/.gitignore new file +2 -0
@@ -0,0 +1,2 @@ +initrd-stress.img +stress
tests/migration/guestperf-batch.py new file +26 -0
@@ -0,0 +1,26 @@ +#!/usr/bin/python +# +# Migration test batch comparison invokation +# +# Copyright (c) 2016 Red Hat, Inc. +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, see <http://www.gnu.org/licenses/>. +# + +import sys + +from guestperf.shell import BatchShell + +shell = BatchShell() +sys.exit(shell.run(sys.argv[1:]))
tests/migration/guestperf-plot.py new file +26 -0
@@ -0,0 +1,26 @@ +#!/usr/bin/python +# +# Migration test graph plotting command +# +# Copyright (c) 2016 Red Hat, Inc. +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, see <http://www.gnu.org/licenses/>. +# + +import sys + +from guestperf.shell import PlotShell + +shell = PlotShell() +sys.exit(shell.run(sys.argv[1:]))
tests/migration/guestperf.py new file +27 -0
@@ -0,0 +1,27 @@ +#!/usr/bin/python +# +# Migration test direct invokation command +# +# Copyright (c) 2016 Red Hat, Inc. +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, see <http://www.gnu.org/licenses/>. +# + + +import sys + +from guestperf.shell import Shell + +shell = Shell() +sys.exit(shell.run(sys.argv[1:]))
tests/migration/guestperf/__init__.py new file +0 -0
tests/migration/guestperf/comparison.py new file +124 -0
124 lines not on this page · raw message
tests/migration/guestperf/engine.py new file +439 -0
439 lines not on this page · raw message
tests/migration/guestperf/hardware.py new file +62 -0
62 lines not on this page · raw message
tests/migration/guestperf/plot.py new file +623 -0
623 lines not on this page · raw message
tests/migration/guestperf/progress.py new file +117 -0
117 lines not on this page · raw message
tests/migration/guestperf/report.py new file +98 -0
98 lines not on this page · raw message
tests/migration/guestperf/scenario.py new file +95 -0
95 lines not on this page · raw message
tests/migration/guestperf/shell.py new file +255 -0
255 lines not on this page · raw message
tests/migration/guestperf/timings.py new file +55 -0
55 lines not on this page · raw message
tests/migration/stress.c new file +367 -0
367 lines not on this page · raw message
Signature · 1 line
2.7.4
Peter Maydell
AppliedQuoted 10 lines · Amit Shah
The following changes since commit
206d0c24361a083fbdcb2cc86fb75dc8b7f251a2:Merge remote-tracking branch 'remotes/mst/tags/for_upstream' into staging (2016-07-21 20:12:37 +0100)
are available in the git repository at:
http://git.kernel.org/pub/scm/virt/qemu/amit/migration.git tags/migration-for-2.7-6
for you to fetch changes up to
409437e16df273fc5f78f6cd1cb53023eaeb9b72:
Quoted 9 lines
tests: introduce a framework for testing migration performance (2016-07-22 13:23:39 +0530)
----------------------------------------------------------------
Migration:
- Fix a postcopy bug
- Add a testsuite for measuring migration performance----------------------------------------------------------------
Applied, thanks.
-- PMM