From: Feng Yang <[email protected]> This function allow user send command with parameters. e.g. balloon value=1073741824. Also log command to debug.
This patch make cmd() in HumanMonitor and QMPMonitor classes to support the same commands like "memsave val=0 size=1024 filename=memsave". There are some limitations though: 1. Must follow Human monitor command parameter order in command. 2. Special monitor commands such as "migrate [-d]" still won't work. Note by lmr: I am still not entirely convinced that we should apply this patch, but I have rebased it and included a second patch that makes it more usable, since it silences the excess of output generated by the screendump thread. Let's see... Signed-off-by: Feng Yang <[email protected]> --- client/tests/kvm/kvm_monitor.py | 46 ++++++++++++++++++++++++++++---------- 1 files changed, 34 insertions(+), 12 deletions(-) diff --git a/client/tests/kvm/kvm_monitor.py b/client/tests/kvm/kvm_monitor.py index 8440835..f62c583 100644 --- a/client/tests/kvm/kvm_monitor.py +++ b/client/tests/kvm/kvm_monitor.py @@ -4,7 +4,7 @@ Interfaces to the QEMU monitor. @copyright: 2008-2010 Red Hat Inc. """ -import socket, time, threading, logging +import socket, time, threading, logging, re import kvm_utils try: import json @@ -188,6 +188,7 @@ class HumanMonitor(Monitor): try: try: + logging.debug("[human] monitor cmd: %s", command) self._socket.sendall(command + "\n") except socket.error: raise MonitorSendError("Could not send monitor command '%s'" % @@ -256,13 +257,14 @@ class HumanMonitor(Monitor): # - A command wrapper should use self._help_str if it requires information # about the monitor's capabilities. - def cmd(self, command, timeout=20): + def cmd(self, cmdline, timeout=20): """ - Send a simple command with no parameters and return its output. - Should only be used for commands that take no parameters and are - implemented under the same name for both the human and QMP monitors. - - @param command: Command to send + Send a simple command with/without parameters and return its output. + Implemented under the same name for both the human and QMP monitors. + Command with parameters should in following format e.g.: + 'memsave val=0 size=10240 filename=memsave' + Command without parameter: 'memsave' + @param comline: Command to send @param timeout: Time duration to wait for (qemu) prompt after command @return: The output of the command @raise MonitorLockError: Raised if the lock cannot be acquired @@ -270,6 +272,10 @@ class HumanMonitor(Monitor): @raise MonitorProtocolError: Raised if the (qemu) prompt cannot be found after sending the command """ + command = cmdline.split()[0] + re_str = "(?<=\=)\w*" + command += " " + ' '.join(re.findall(re_str, cmdline)) + return self._get_command_output(command, timeout) @@ -486,6 +492,7 @@ class QMPMonitor(Monitor): try: cmdobj = self._build_cmd(cmd, args, id) try: + logging.debug("[qmp] monitor cmd: %s" % cmdobj) self._socket.sendall(json.dumps(cmdobj) + "\n") except socket.error: raise MonitorSendError("Could not send QMP command '%s'" % cmd) @@ -601,11 +608,13 @@ class QMPMonitor(Monitor): # Note: all of the following functions raise exceptions in a similar manner # to cmd() and _get_command_output(). - def cmd(self, command, timeout=20): + def cmd(self, cmdline, timeout=20): """ - Send a simple command with no parameters and return its output. - Should only be used for commands that take no parameters and are - implemented under the same name for both the human and QMP monitors. + Send a simple command with/without parameters and return its output. + Implemented under the same name for both the human and QMP monitors. + Command with parameters should in following format e.g.: + 'memsave val=0 size=10240 filename=memsave' + Command without parameter: 'memsave' @param command: Command to send @param timeout: Time duration to wait for response @@ -614,7 +623,20 @@ class QMPMonitor(Monitor): @raise MonitorSendError: Raised if the command cannot be sent @raise MonitorProtocolError: Raised if no response is received """ - return self._get_command_output(command, timeout=timeout) + cmdargs = cmdline.split() + command = cmdargs[0] + args = {} + for arg in cmdargs[1:]: + opt = arg.split('=') + try: + try: + value = int(opt[1]) + except ValueError: + value = opt[1] + args[opt[0]] = value + except: + logging.debug("Fail to create args, please check command") + return self._get_command_output(command, args, timeout=timeout) def quit(self): -- 1.7.2.2 _______________________________________________ Autotest mailing list [email protected] http://test.kernel.org/cgi-bin/mailman/listinfo/autotest
