From patchwork Mon Aug 3 22:38:50 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lucas Meneghel Rodrigues X-Patchwork-Id: 39024 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 n73MdDT7017606 for ; Mon, 3 Aug 2009 22:39:14 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754999AbZHCWjI (ORCPT ); Mon, 3 Aug 2009 18:39:08 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1755023AbZHCWjI (ORCPT ); Mon, 3 Aug 2009 18:39:08 -0400 Received: from mx2.redhat.com ([66.187.237.31]:60577 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753272AbZHCWjC (ORCPT ); Mon, 3 Aug 2009 18:39:02 -0400 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n73Md3Xo002367; Mon, 3 Aug 2009 18:39:03 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n73Md2xI026944; Mon, 3 Aug 2009 18:39:02 -0400 Received: from localhost.localdomain (vpn-10-57.bos.redhat.com [10.16.10.57]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n73MctNg025566; Mon, 3 Aug 2009 18:39:00 -0400 From: Lucas Meneghel Rodrigues To: autotest@test.kernel.org Cc: kvm@vger.kernel.org, dhuff@redhat.com, Lucas Meneghel Rodrigues Subject: [PATCH 2/6] KVM test: Introducing unattended install subtest Date: Mon, 3 Aug 2009 19:38:50 -0300 Message-Id: <1249339134-5600-3-git-send-email-lmr@redhat.com> In-Reply-To: <1249339134-5600-2-git-send-email-lmr@redhat.com> References: <1249339134-5600-1-git-send-email-lmr@redhat.com> <1249339134-5600-2-git-send-email-lmr@redhat.com> X-Scanned-By: MIMEDefang 2.58 on 172.16.27.26 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org In order to resolve the question, 'how will the guest operating system tell the host operating system that the unattended install process finish', we took the simple approach and created a simple socket communication ack process: The test instantiates a server tcp socket on port 12323, and waits during a specified amount of time. For guests, the vast majority of the unattended install processes can deal with executing commands at the end of the install process. Let's take advantage of that and make clients tell the server about the end of the process using simple programs that can do that. The implementation of that strategy varies trough different operating systems. This is the kvm test implementation code, client programs will follow on later patches. Signed-off-by: Lucas Meneghel Rodrigues --- client/tests/kvm/kvm.py | 2 + client/tests/kvm/kvm_tests.py | 81 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 82 insertions(+), 1 deletions(-) diff --git a/client/tests/kvm/kvm.py b/client/tests/kvm/kvm.py index 070e463..db6899b 100644 --- a/client/tests/kvm/kvm.py +++ b/client/tests/kvm/kvm.py @@ -56,6 +56,8 @@ class kvm(test.test): "linux_s3": test_routine("kvm_tests", "run_linux_s3"), "stress_boot": test_routine("kvm_tests", "run_stress_boot"), "timedrift": test_routine("kvm_tests", "run_timedrift"), + "unattended_install": test_routine("kvm_tests", + "run_unattended_install"), } # Make it possible to import modules from the test's bindir diff --git a/client/tests/kvm/kvm_tests.py b/client/tests/kvm/kvm_tests.py index 9784ec9..f45fefc 100644 --- a/client/tests/kvm/kvm_tests.py +++ b/client/tests/kvm/kvm_tests.py @@ -1,4 +1,4 @@ -import time, os, logging, re, commands +import time, os, logging, re, commands, socket from autotest_lib.client.common_lib import utils, error import kvm_utils, kvm_subprocess, ppm_utils, scan_results @@ -9,6 +9,85 @@ KVM test definitions. """ +class UnattendedInstallWatcher: + """ + Mechanism to verify whether an unattended guest install actually did finish. + It opens a TCP socket and waits until it receives a message. If it does get + the expected message from the guest, it will finish gracefully. + """ + def __init__(self, timeout, msg): + self.port = 12323 + self.buf_size = 1024 + self.timeout = timeout + self.msg = msg + + + def check_answer(self, connection): + """ + Verify if client has sent the correct ACK message. + + @param connection: Tuple with client socket connection and address. + @return: True, in case the client has responded accordingly; False if + the string doesn't match the server expectations. + """ + (client, addr) = connection + msg = client.recv(self.buf_size) + logging.debug("Received '%s' from %s", msg, addr) + if msg == self.msg: + logging.info('Guest reported successful installation') + return True + else: + logging.error('Got invalid string from client: %s.' % msg) + return False + + + def run_server(self): + """ + Initializes and runs the server socket and listens for connections. + """ + server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + address = ('', self.port) + server.bind(address) + server.listen(1) + + while True: + try: + server.settimeout(self.timeout) + connection = server.accept() + if self.check_answer(connection): + break + except: + server.close() + raise + + +def run_unattended_install(test, params, env): + """ + Unattended install test: + 1) Starts a VM with an appropriated setup to start an unattended OS install. + 2) Wait until the install reports to the install watcher its end. + + @param test: KVM test object. + @param params: Dictionary with the test parameters. + @param env: Dictionary with test environment. + """ + vm = kvm_utils.env_get_vm(env, params.get("main_vm")) + if not vm: + raise error.TestError("VM object not found in environment") + if not vm.is_alive(): + raise error.TestError("VM seems to be dead; Test requires a living VM") + + logging.info("Starting unattended install watch process") + watcher = UnattendedInstallWatcher(timeout=3000, msg='done') + try: + watcher.run_server() + except socket.timeout: + raise error.TestFail('Timeout elapsed while waiting for install to ' + 'finish.') + + logging.info("Unattended install finished successfuly") + + def run_boot(test, params, env): """ KVM reboot test: