From patchwork Mon Oct 18 18:45:25 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 262641 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id o9IIjenq008244 for ; Mon, 18 Oct 2010 18:45:41 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755398Ab0JRSpg (ORCPT ); Mon, 18 Oct 2010 14:45:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53198 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753245Ab0JRSpf (ORCPT ); Mon, 18 Oct 2010 14:45:35 -0400 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o9IIjYFF016349 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 18 Oct 2010 14:45:34 -0400 Received: from doriath (ovpn-113-21.phx2.redhat.com [10.3.113.21]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o9IIjVga006600 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Mon, 18 Oct 2010 14:45:33 -0400 Date: Mon, 18 Oct 2010 16:45:25 -0200 From: Luiz Capitulino To: Michael Goldish Cc: autotest@test.kernel.org, kvm@vger.kernel.org Subject: Re: [Autotest] [KVM-AUTOTEST PATCH] [RFC] KVM test: kvm_monitor.py: refactor _get_command_output() Message-ID: <20101018164525.38d2d105@doriath> In-Reply-To: <1287407620-30026-3-git-send-email-mgoldish@redhat.com> References: <1287407620-30026-1-git-send-email-mgoldish@redhat.com> <1287407620-30026-2-git-send-email-mgoldish@redhat.com> <1287407620-30026-3-git-send-email-mgoldish@redhat.com> Organization: Red Hat Mime-Version: 1.0 X-Scanned-By: MIMEDefang 2.67 on 10.5.11.16 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Mon, 18 Oct 2010 18:45:41 +0000 (UTC) diff --git a/client/tests/kvm/kvm_monitor.py b/client/tests/kvm/kvm_monitor.py index 6bff07f..cfe05bf 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, select import kvm_utils try: import json @@ -58,7 +58,6 @@ class Monitor: self.filename = filename self._lock = threading.RLock() self._socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) - self._socket.setblocking(False) try: self._socket.connect(filename) @@ -105,13 +104,14 @@ class Monitor: def _recvall(self): s = "" while True: - try: + i, o, e = select.select([self._socket], [], [], 0) + if len(i) > 0: data = self._socket.recv(1024) - except socket.error: - break - if not data: + if not data: + break + s += data + else: break - s += data return s @@ -158,19 +158,19 @@ class HumanMonitor(Monitor): # Private methods def _read_up_to_qemu_prompt(self, timeout=20): - o = "" - end_time = time.time() + timeout - while time.time() < end_time: - try: + buf = "" + while True: + i, o, e = select.select([self._socket], [], [], timeout) + if len(i) > 0: data = self._socket.recv(1024) - if not data: - break - o += data - if o.splitlines()[-1].split()[-1] == "(qemu)": - return True, "\n".join(o.splitlines()[:-1]) - except (socket.error, IndexError): - time.sleep(0.01) - return False, "\n".join(o.splitlines()) + buf += data + try: + if buf.splitlines()[-1].split()[-1] == "(qemu)": + return True, "\n".join(buf.splitlines()[:-1]) + except IndexError: + continue + else: + return False, "\n".join(buf.splitlines()) def _send_command(self, command):