From patchwork Tue Jan 11 13:13:20 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Goldish X-Patchwork-Id: 471511 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 p0BDDSjg008028 for ; Tue, 11 Jan 2011 13:13:32 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932133Ab1AKNNZ (ORCPT ); Tue, 11 Jan 2011 08:13:25 -0500 Received: from mx1.redhat.com ([209.132.183.28]:23636 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755993Ab1AKNNX (ORCPT ); Tue, 11 Jan 2011 08:13:23 -0500 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 p0BDDMaB009225 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 11 Jan 2011 08:13:22 -0500 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 p0BDDLlN022798; Tue, 11 Jan 2011 08:13:21 -0500 Received: from qu0061.eng.lab.tlv.redhat.com ([10.35.16.61]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id p0BDD9nU025030; Tue, 11 Jan 2011 08:13:20 -0500 From: Michael Goldish To: autotest@test.kernel.org, kvm@vger.kernel.org Cc: Michael Goldish Subject: [KVM-AUTOTEST PATCH 08/26] KVM test: unattended_install.py style changes Date: Tue, 11 Jan 2011 15:13:20 +0200 Message-Id: <1294751618-21631-8-git-send-email-mgoldish@redhat.com> In-Reply-To: <1294751618-21631-1-git-send-email-mgoldish@redhat.com> References: <1294751618-21631-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 X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Tue, 11 Jan 2011 13:13:33 +0000 (UTC) diff --git a/client/tests/kvm/tests/unattended_install.py b/client/tests/kvm/tests/unattended_install.py index 9617603..57d3d00 100644 --- a/client/tests/kvm/tests/unattended_install.py +++ b/client/tests/kvm/tests/unattended_install.py @@ -1,8 +1,9 @@ import logging, time, socket from autotest_lib.client.common_lib import error -import kvm_utils, kvm_test_utils +import kvm_utils, kvm_test_utils, kvm_vm +@error.context_aware def run_unattended_install(test, params, env): """ Unattended install test: @@ -13,47 +14,38 @@ def run_unattended_install(test, params, env): @param params: Dictionary with the test parameters. @param env: Dictionary with test environment. """ - buf = 1024 vm = env.get_vm(params["main_vm"]) vm.verify_alive() + install_timeout = int(params.get("timeout", 3000)) + post_install_delay = int(params.get("post_install_delay", 0)) port = vm.get_port(int(params.get("guest_port_unattended_install"))) - if params.get("post_install_delay"): - post_install_delay = int(params.get("post_install_delay")) - else: - post_install_delay = 0 - install_timeout = float(params.get("timeout", 3000)) - logging.info("Starting unattended install watch process. " - "Timeout set to %ds (%d min)", install_timeout, - install_timeout/60) + logging.info("Waiting for installation to finish. Timeout set to %ds " + "(%d min).", install_timeout, install_timeout/60) + error.context("waiting for installation to finish") + start_time = time.time() - time_elapsed = 0 - while time_elapsed < install_timeout: - if not vm.is_alive(): - raise error.TestError("Guest died before end of OS install") + while time.time() - start_time < install_timeout: + vm.verify_alive() client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - addr = vm.get_address() - if addr is not None: - try: - client.connect((addr, port)) - msg = client.recv(1024) - if msg == 'done': - if post_install_delay: - logging.debug("Post install delay specified, " - "waiting %ss...", post_install_delay) - time.sleep(post_install_delay) - break - except socket.error: - pass - time.sleep(1) + try: + client.connect((vm.get_address(), port)) + if client.recv(1024) == "done": + break + except (socket.error, kvm_vm.VMAddressError): + pass client.close() - end_time = time.time() - time_elapsed = int(end_time - start_time) - - if time_elapsed < install_timeout: - logging.info('Guest reported successful installation after %ds ' - '(%d min)', time_elapsed, time_elapsed/60) + time.sleep(10) else: - raise error.TestFail('Timeout elapsed while waiting for install to ' - 'finish.') + raise error.TestFail("Timeout elapsed while waiting for installation " + "to finish") + + time_elapsed = time.time() - start_time + logging.info("Guest reported successful installation after %ds (%d min)", + time_elapsed, time_elapsed/60) + + if post_install_delay: + logging.debug("Post install delay specified, waiting %ss...", + post_install_delay) + time.sleep(post_install_delay)