From patchwork Fri Jun 18 09:28:46 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Cao, Chen" X-Patchwork-Id: 106819 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o5I9Sj3m005708 for ; Fri, 18 Jun 2010 09:28:45 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759097Ab0FRJ2o (ORCPT ); Fri, 18 Jun 2010 05:28:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:10421 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753553Ab0FRJ2n (ORCPT ); Fri, 18 Jun 2010 05:28:43 -0400 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o5I9SfYF028027 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 18 Jun 2010 05:28:41 -0400 Received: from dhcp-91-197.nay.redhat.com (dhcp-91-197.nay.redhat.com [10.66.91.197]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o5I9ScNV012147; Fri, 18 Jun 2010 05:28:39 -0400 Subject: [KVM-AUTOTEST PATCH 2/2] KVM-test: rename autoit to guest_test and update the sample config file To: lmr@redhat.com, autotest@test.kernel.org From: Chen Cao Cc: kvm@vger.kernel.org Date: Fri, 18 Jun 2010 17:28:46 +0800 Message-ID: <20100618092813.11860.22539.stgit@dhcp-91-197.nay.redhat.com> In-Reply-To: <20100618092426.11860.79768.stgit@dhcp-91-197.nay.redhat.com> References: <20100618092426.11860.79768.stgit@dhcp-91-197.nay.redhat.com> User-Agent: StGit/0.15-83-g972d5-dirty MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.67 on 10.5.11.17 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 (demeter.kernel.org [140.211.167.41]); Fri, 18 Jun 2010 09:28:45 +0000 (UTC) diff --git a/client/tests/kvm/tests/autoit.py b/client/tests/kvm/tests/autoit.py deleted file mode 100644 index 0373f38..0000000 --- a/client/tests/kvm/tests/autoit.py +++ /dev/null @@ -1,94 +0,0 @@ -import os, logging -from autotest_lib.client.common_lib import error -import kvm_utils, kvm_test_utils - - -def run_autoit(test, params, env): - """ - A wrapper for running customized tests in guests. - - 1) Log into a guest. - 2) Run script. - 3) Wait for script execution to complete. - 4) Pass/fail according to exit status of script. - - @param test: KVM test object. - @param params: Dictionary with test parameters. - @param env: Dictionary with the test environment. - """ - login_timeout = int(params.get("login_timeout", 360)) - reboot = params.get("reboot", "no") - - vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) - session = kvm_test_utils.wait_for_login(vm, timeout=login_timeout) - - if reboot == "yes": - logging.debug("Rebooting guest before test ...") - session = kvm_test_utils.reboot(vm, session, timeout=login_timeout) - - try: - logging.info("Starting script...") - - # Collect test parameters - interpreter = params.get("interpreter") - script = params.get("guest_script") - dst_rsc_path = params.get("dst_rsc_path", "script.au3") - script_params = params.get("script_params", "") - test_timeout = float(params.get("test_timeout", 600)) - - logging.debug("Starting preparing resouce files...") - # Download the script resource from a remote server, or - # prepare the script using rss? - if params.get("download") == "yes": - download_cmd = params.get("download_cmd") - rsc_server = params.get("rsc_server") - rsc_dir = os.path.basename(rsc_server) - dst_rsc_dir = params.get("dst_rsc_dir") - - # Change dir to dst_rsc_dir, and remove the guest script dir there - rm_cmd = "cd %s && (rmdir /s /q %s || del /s /q %s)" % \ - (dst_rsc_dir, rsc_dir, rsc_dir) - if session.get_command_status(rm_cmd, timeout=test_timeout) != 0: - raise error.TestFail("Remove %s failed." % rsc_dir) - logging.debug("Clean directory succeeded.") - - # then download the resource. - rsc_cmd = "cd %s && %s %s" %(dst_rsc_dir, download_cmd, rsc_server) - if session.get_command_status(rsc_cmd, timeout=test_timeout) != 0: - raise error.TestFail("Download test resource failed.") - logging.info("Download resource finished.") - else: - # Send AutoIt script to guest (this code will be replaced once we - # support sending files to Windows guests) - session.get_command_output("del script.au3", internal_timeout=0) - file = open(kvm_utils.get_path(test.bindir, script)) - for line in file.readlines(): - # Insert a '^' before each character - line = "".join("^" + c for c in line.rstrip()) - if line: - # Append line to the file - session.get_command_output("echo %s>>script.au3" % line, - internal_timeout=0) - file.close() - - command = "cmd /c %s %s %s" %(interpreter, dst_rsc_path, script_params) - - logging.info("---------------- Script output ----------------") - status = session.get_command_status(command, - print_func=logging.info, - timeout=test_timeout) - logging.info("---------------- End of script output ----------------") - - if status is None: - raise error.TestFail("Timeout expired before script execution " - "completed (or something weird happened)") - if status != 0: - raise error.TestFail("Script execution failed") - - if reboot == "yes": - logging.debug("Rebooting guest after test ...") - session = kvm_test_utils.reboot(vm, session, timeout=login_timeout) - - logging.debug("guest test PASSED.") - finally: - session.close() diff --git a/client/tests/kvm/tests/guest_test.py b/client/tests/kvm/tests/guest_test.py new file mode 100644 index 0000000..2ba3d02 --- /dev/null +++ b/client/tests/kvm/tests/guest_test.py @@ -0,0 +1,94 @@ +import os, logging +from autotest_lib.client.common_lib import error +import kvm_utils, kvm_test_utils + + +def run_guest_test(test, params, env): + """ + A wrapper for running customized tests in guests. + + 1) Log into a guest. + 2) Run script. + 3) Wait for script execution to complete. + 4) Pass/fail according to exit status of script. + + @param test: KVM test object. + @param params: Dictionary with test parameters. + @param env: Dictionary with the test environment. + """ + login_timeout = int(params.get("login_timeout", 360)) + reboot = params.get("reboot", "no") + + vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) + session = kvm_test_utils.wait_for_login(vm, timeout=login_timeout) + + if reboot == "yes": + logging.debug("Rebooting guest before test ...") + session = kvm_test_utils.reboot(vm, session, timeout=login_timeout) + + try: + logging.info("Starting script...") + + # Collect test parameters + interpreter = params.get("interpreter") + script = params.get("guest_script") + dst_rsc_path = params.get("dst_rsc_path", "script.au3") + script_params = params.get("script_params", "") + test_timeout = float(params.get("test_timeout", 600)) + + logging.debug("Starting preparing resouce files...") + # Download the script resource from a remote server, or + # prepare the script using rss? + if params.get("download") == "yes": + download_cmd = params.get("download_cmd") + rsc_server = params.get("rsc_server") + rsc_dir = os.path.basename(rsc_server) + dst_rsc_dir = params.get("dst_rsc_dir") + + # Change dir to dst_rsc_dir, and remove the guest script dir there + rm_cmd = "cd %s && (rmdir /s /q %s || del /s /q %s)" % \ + (dst_rsc_dir, rsc_dir, rsc_dir) + if session.get_command_status(rm_cmd, timeout=test_timeout) != 0: + raise error.TestFail("Remove %s failed." % rsc_dir) + logging.debug("Clean directory succeeded.") + + # then download the resource. + rsc_cmd = "cd %s && %s %s" %(dst_rsc_dir, download_cmd, rsc_server) + if session.get_command_status(rsc_cmd, timeout=test_timeout) != 0: + raise error.TestFail("Download test resource failed.") + logging.info("Download resource finished.") + else: + # Send AutoIt script to guest (this code will be replaced once we + # support sending files to Windows guests) + session.get_command_output("del script.au3", internal_timeout=0) + file = open(kvm_utils.get_path(test.bindir, script)) + for line in file.readlines(): + # Insert a '^' before each character + line = "".join("^" + c for c in line.rstrip()) + if line: + # Append line to the file + session.get_command_output("echo %s>>script.au3" % line, + internal_timeout=0) + file.close() + + command = "cmd /c %s %s %s" %(interpreter, dst_rsc_path, script_params) + + logging.info("---------------- Script output ----------------") + status = session.get_command_status(command, + print_func=logging.info, + timeout=test_timeout) + logging.info("---------------- End of script output ----------------") + + if status is None: + raise error.TestFail("Timeout expired before script execution " + "completed (or something weird happened)") + if status != 0: + raise error.TestFail("Script execution failed") + + if reboot == "yes": + logging.debug("Rebooting guest after test ...") + session = kvm_test_utils.reboot(vm, session, timeout=login_timeout) + + logging.debug("guest test PASSED.") + finally: + session.close() diff --git a/client/tests/kvm/tests_base.cfg.sample b/client/tests/kvm/tests_base.cfg.sample index 5b0da6a..105c67a 100644 --- a/client/tests/kvm/tests_base.cfg.sample +++ b/client/tests/kvm/tests_base.cfg.sample @@ -248,22 +248,33 @@ variants: used_cpus = 5 used_mem = 2560 - - autoit: install setup unattended_install.cdrom - type = autoit + - guest_test: install setup unattended_install.cdrom + type = guest_test login_timeout = 360 - interpreter = D:\AutoIt3.exe test_timeout = 600 script_params = reboot = yes variants: - - notepad: - guest_script = autoit/notepad1.au3 - - stub: - download = yes - download_cmd = "git clone" - rsc_server = "git://the.resource.server/autoit" - dst_rsc_dir = "C:\" - dst_rsc_path = "C:\autoit\stub\stub.au3" + - autoit: + interpreter = D:\AutoIt3.exe + variants: + - notepad: + guest_script = autoit/notepad1.au3 + - stub: + download = yes + download_cmd = "git clone" + rsc_server = "git://the.resource.server/autoit" + dst_rsc_dir = "C:\" + dst_rsc_path = "C:\autoit\stub\stub.au3" + - powershell: + interpreter = "powershell.exe -File" + variants: + - stub: + download = yes + download_cmd = "git clone" + rsc_server = "git://the.resource.server/powershell" + dst_rsc_dir = "C:\" + dst_rsc_path = "C:\powershell\stub\stub.ps1" - iozone_windows: unattended_install.cdrom type = iozone_windows