From mboxrd@z Thu Jan 1 00:00:00 1970 From: Michael Goldish Subject: Re: [Autotest] [KVM-AUTOTEST PATCH 11/14] KVM test: add kvm_monitor.py, an interface to QEMU monitors Date: Mon, 14 Jun 2010 08:59:17 +0300 Message-ID: <4C15C535.7080507@redhat.com> References: <1276439625-32472-2-git-send-email-mgoldish@redhat.com> <1276439625-32472-3-git-send-email-mgoldish@redhat.com> <1276439625-32472-4-git-send-email-mgoldish@redhat.com> <1276439625-32472-5-git-send-email-mgoldish@redhat.com> <1276439625-32472-6-git-send-email-mgoldish@redhat.com> <1276439625-32472-7-git-send-email-mgoldish@redhat.com> <1276439625-32472-8-git-send-email-mgoldish@redhat.com> <1276439625-32472-9-git-send-email-mgoldish@redhat.com> <1276439625-32472-10-git-send-email-mgoldish@redhat.com> <1276439625-32472-11-git-send-email-mgoldish@redhat.com> <20100614013218.GA5266@z> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Cc: autotest@test.kernel.org, kvm@vger.kernel.org To: Amos Kong Return-path: Received: from mx1.redhat.com ([209.132.183.28]:10812 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751644Ab0FNF7k (ORCPT ); Mon, 14 Jun 2010 01:59:40 -0400 In-Reply-To: <20100614013218.GA5266@z> Sender: kvm-owner@vger.kernel.org List-ID: On 06/14/2010 04:32 AM, Amos Kong wrote: > On Sun, Jun 13, 2010 at 05:33:42PM +0300, Michael Goldish wrote: >> This module should replace vm.send_monitor_cmd(). Instead of connecting to the >> monitor each time a command is issued, this module maintains a continuous >> connection to the monitor. It disconnects when a test terminates and >> reconnects as soon as the next test begins (upon unpickling). >> >> It currently contains only an interface to the human monitor. A QMP interface >> will be introduced in a future patch. >> >> Signed-off-by: Michael Goldish >> --- >> client/tests/kvm/kvm_monitor.py | 356 +++++++++++++++++++++++++++++++++++++++ >> 1 files changed, 356 insertions(+), 0 deletions(-) >> create mode 100644 client/tests/kvm/kvm_monitor.py >> >> diff --git a/client/tests/kvm/kvm_monitor.py b/client/tests/kvm/kvm_monitor.py >> new file mode 100644 >> index 0000000..c5cf9c3 >> --- /dev/null >> +++ b/client/tests/kvm/kvm_monitor.py >> @@ -0,0 +1,356 @@ >> +""" >> +Interfaces to the QEMU monitor. >> + >> +@copyright: 2008-2010 Red Hat Inc. >> +""" >> + > > ... > >> +class HumanMonitor(Monitor): >> + """ >> + Wraps "human monitor" commands. >> + """ >> + >> + def __init__(self, filename, suppress_exceptions=False): >> + """ >> + Connect to the monitor socket and find the (qemu) prompt. >> + >> + @param filename: Monitor socket filename >> + @raise MonitorConnectError: Raised if the connection fails and >> + suppress_exceptions is False >> + @raise MonitorProtocolError: Raised if the initial (qemu) prompt isn't >> + found and suppress_exceptions is False >> + """ >> + try: >> + Monitor.__init__(self, filename) >> + >> + self.protocol = "human" >> + >> + # Find the initial (qemu) prompt >> + s, o = self._read_up_to_qemu_prompt(20) >> + if not s: >> + raise MonitorProtocolError("Could not find (qemu) prompt " >> + "after connecting to monitor. " >> + "Output so far: %r" % o) >> + >> + # Save the output of 'help' for future use >> + self.help = self._get_command_output("help") > > Hi Michael, > > Here, self.help is a string type. > But you repeatedly define a sub function self.help() below. > > If I call vm.monitor.help() in testcase, will touch this err: > TypeError: 'str' object is not callable Oops. I'll fix that. > How about using self.help_str = self._get_command_output("help")? > and remove help sub function, Not only repeated name, but repeated function. > > > Amos OK, it might be a good idea to remove help() altogether, especially since QMP doesn't support it AFAIK. BTW, testcases are supposed to use vm.monitor.cmd(), not vm.monitor._get_command_output(). >> + >> + except MonitorError, e: >> + if suppress_exceptions: >> + logging.warn(e) >> + else: >> + raise >> + > > ... > >> + >> + def help(self): >> + """ >> + Send "help" and return the output. >> + """ >> + return self._get_command_output("help") > > ... > -- > To unsubscribe from this list: send the line "unsubscribe kvm" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html