From patchwork Thu Oct 15 10:13:55 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Goldish X-Patchwork-Id: 54001 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n9FAN5BI025773 for ; Thu, 15 Oct 2009 10:23:05 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756552AbZJOKRh (ORCPT ); Thu, 15 Oct 2009 06:17:37 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1755746AbZJOKRh (ORCPT ); Thu, 15 Oct 2009 06:17:37 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50483 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751200AbZJOKRg (ORCPT ); Thu, 15 Oct 2009 06:17:36 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n9FAH5tO025168; Thu, 15 Oct 2009 06:17:05 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n9FAH4dd003282; Thu, 15 Oct 2009 06:17:04 -0400 Received: from localhost.localdomain (dhcp-1-188.tlv.redhat.com [10.35.1.188]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n9FAH1x1004569; Thu, 15 Oct 2009 06:17:02 -0400 From: Michael Goldish To: autotest@test.kernel.org, kvm@vger.kernel.org Cc: Michael Goldish Subject: [KVM-AUTOTEST PATCH 1/3] KVM test: VM.send_monitor_cmd() minor cleanup Date: Thu, 15 Oct 2009 12:13:55 +0200 Message-Id: <1255601637-6355-1-git-send-email-mgoldish@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org diff --git a/client/tests/kvm/kvm_vm.py b/client/tests/kvm/kvm_vm.py index 82f1eb4..a8d96ca 100755 --- a/client/tests/kvm/kvm_vm.py +++ b/client/tests/kvm/kvm_vm.py @@ -465,7 +465,7 @@ class VM: end_time = time.time() + timeout while time.time() < end_time: try: - o += s.recv(16384) + o += s.recv(1024) if o.splitlines()[-1].split()[-1] == "(qemu)": return (True, o) except: @@ -481,27 +481,32 @@ class VM: except: logging.debug("Could not connect to monitor socket") return (1, "") - status, data = read_up_to_qemu_prompt(s, timeout) - if not status: - s.close() - logging.debug("Could not find (qemu) prompt; output so far:" \ - + kvm_utils.format_str_for_message(data)) - return (1, "") - # Send command - s.sendall(command + "\n") - # Receive command output - data = "" - if block: + + # Send the command and get the resulting output + try: status, data = read_up_to_qemu_prompt(s, timeout) - data = "\n".join(data.splitlines()[1:]) if not status: - s.close() - logging.debug("Could not find (qemu) prompt after command;" - " output so far: %s", - kvm_utils.format_str_for_message(data)) - return (1, data) - s.close() - return (0, data) + logging.debug("Could not find (qemu) prompt; output so far:" + + kvm_utils.format_str_for_message(data)) + return (1, "") + # Send command + s.sendall(command + "\n") + # Receive command output + data = "" + if block: + status, data = read_up_to_qemu_prompt(s, timeout) + data = "\n".join(data.splitlines()[1:]) + if not status: + logging.debug("Could not find (qemu) prompt after command; " + "output so far:" + + kvm_utils.format_str_for_message(data)) + return (1, data) + return (0, data) + + # Clean up before exiting + finally: + s.shutdown(socket.SHUT_RDWR) + s.close() def destroy(self, gracefully=True):