From patchwork Tue Aug 4 02:28:21 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Goldish X-Patchwork-Id: 39049 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 n742SXmK018808 for ; Tue, 4 Aug 2009 02:28:33 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932360AbZHDC21 (ORCPT ); Mon, 3 Aug 2009 22:28:27 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S932326AbZHDC20 (ORCPT ); Mon, 3 Aug 2009 22:28:26 -0400 Received: from mx1.redhat.com ([66.187.233.31]:40508 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932159AbZHDC2Z (ORCPT ); Mon, 3 Aug 2009 22:28:25 -0400 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n742SNN2025658; Mon, 3 Aug 2009 22:28:23 -0400 Received: from mail05.corp.redhat.com (zmail05.collab.prod.int.phx2.redhat.com [10.5.5.46]) by int-mx1.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n742SLVj022115; Mon, 3 Aug 2009 22:28:21 -0400 Date: Mon, 3 Aug 2009 22:28:21 -0400 (EDT) From: Michael Goldish To: Lucas Meneghel Rodrigues Cc: kvm@vger.kernel.org, dhuff@redhat.com, autotest@test.kernel.org Message-ID: <1941964121.1414421249352901620.JavaMail.root@zmail05.collab.prod.int.phx2.redhat.com> In-Reply-To: <447716066.1414231249352459058.JavaMail.root@zmail05.collab.prod.int.phx2.redhat.com> Subject: Re: [PATCH 2/6] KVM test: Introducing unattended install subtest MIME-Version: 1.0 X-Originating-IP: [10.5.5.72] X-Scanned-By: MIMEDefang 2.58 on 172.16.52.254 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The test code looks nice and simple. However, I don't think putting some of the code in a class helps much (it doesn't hurt either). What do you think about this alternative, replacing from 'watcher = ...': server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server.bind(('', 12323)) server.listen(1) end_time = time.time() + float(params.get("timeout", 3000)) while True: server.settimeout(end_time - time.time()) try: (client, addr) = server.accept() except socket.timeout: server.close() raise error.TestFail('Timeout elapsed while waiting for install to ' 'finish.') msg = client.recv(1024) logging.debug("Received '%s' from %s", msg, addr) if msg == 'done': logging.info('Guest reported successful installation') server.close() break else: logging.error('Got invalid string from client: %s.' % msg) It's not necessarily shorter, but I find it a bit simpler. The only meaningful difference here is the timeout handling. In your original code, if a client sends anything other than 'done' (very unlikely), the server will wait another 3000 secs. With this code, the server will wait up to a total of 'timeout' secs (user specified). I find this code short and simple enough to leave outside a class, but it's a matter of personal preference, so it's up to you. ----- Original Message ----- From: "Lucas Meneghel Rodrigues" To: autotest@test.kernel.org Cc: kvm@vger.kernel.org, dhuff@redhat.com, "Lucas Meneghel Rodrigues" Sent: Tuesday, August 4, 2009 1:38:50 AM (GMT+0200) Auto-Detected Subject: [PATCH 2/6] KVM test: Introducing unattended install subtest 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: