From patchwork Mon Jan 3 18:27:15 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Goldish X-Patchwork-Id: 448651 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 p03IRBb4024206 for ; Mon, 3 Jan 2011 18:27:15 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750766Ab1ACS1F (ORCPT ); Mon, 3 Jan 2011 13:27:05 -0500 Received: from mx1.redhat.com ([209.132.183.28]:40143 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752186Ab1ACS1B (ORCPT ); Mon, 3 Jan 2011 13:27:01 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id p03IR0Xt008109 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 3 Jan 2011 13:27:01 -0500 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p03IR0iP021866; Mon, 3 Jan 2011 13:27:00 -0500 Received: from moof.tlv.redhat.com (dhcp-1-185.tlv.redhat.com [10.35.1.185]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id p03IQeWg027298; Mon, 3 Jan 2011 13:26:59 -0500 From: Michael Goldish To: autotest@test.kernel.org, kvm@vger.kernel.org Cc: Michael Goldish Subject: [KVM-AUTOTEST PATCH 14/17] KVM test: simplify migration_with_reboot and migration_with_file_transfer Date: Mon, 3 Jan 2011 20:27:15 +0200 Message-Id: <1294079238-21239-14-git-send-email-mgoldish@redhat.com> In-Reply-To: <1294079238-21239-1-git-send-email-mgoldish@redhat.com> References: <1294079238-21239-1-git-send-email-mgoldish@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 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, 03 Jan 2011 18:27:16 +0000 (UTC) diff --git a/client/tests/kvm/tests/migration_with_file_transfer.py b/client/tests/kvm/tests/migration_with_file_transfer.py index f641451..27c1fe1 100644 --- a/client/tests/kvm/tests/migration_with_file_transfer.py +++ b/client/tests/kvm/tests/migration_with_file_transfer.py @@ -21,21 +21,12 @@ def run_migration_with_file_transfer(test, params, env): """ vm = env.get_vm(params["main_vm"]) vm.verify_alive() - timeout = int(params.get("login_timeout", 360)) - session = vm.wait_for_login(timeout=timeout) + login_timeout = int(params.get("login_timeout", 360)) + session = vm.wait_for_login(timeout=login_timeout) mig_timeout = float(params.get("mig_timeout", "3600")) mig_protocol = params.get("migration_protocol", "tcp") - # params of transfer test - username = vm.params.get("username", "") - password = vm.params.get("password", "") - client = vm.params.get("file_transfer_client") - address = vm.get_address(0) - port = vm.get_port(int(params.get("file_transfer_port"))) - log_filename = ("migration-transfer-%s-to-%s-%s.log" % - (vm.name, address, - kvm_utils.generate_random_string(4))) host_path = "/tmp/file-%s" % kvm_utils.generate_random_string(6) host_path_returned = "%s-returned" % host_path guest_path = params.get("guest_path", "/tmp/file") @@ -46,33 +37,26 @@ def run_migration_with_file_transfer(test, params, env): utils.run("dd if=/dev/urandom of=%s bs=1M count=%s" % (host_path, file_size)) + def run_and_migrate(bg): + bg.start() + try: + while bg.is_alive(): + logging.info("File transfer not ended, starting a round of " + "migration...") + vm.migrate(mig_timeout, mig_protocol) + finally: + bg.join() + logging.info("Transferring file from host to guest") - bg = kvm_utils.Thread(kvm_utils.copy_files_to, - (address, client, username, password, port, - host_path, guest_path, log_filename, - transfer_timeout)) - bg.start() - try: - while bg.is_alive(): - logging.info("File transfer not ended, starting a round of " - "migration...") - vm = kvm_test_utils.migrate(vm, env, mig_timeout, mig_protocol) - finally: - bg.join() + bg = kvm_utils.Thread(vm.copy_files_to, + (host_path, guest_path, 0, transfer_timeout)) + run_and_migrate(bg) logging.info("Transferring file back from guest to host") - bg = kvm_utils.Thread(kvm_utils.copy_files_from, - (address, client, username, password, port, - host_path_returned, guest_path, log_filename, + bg = kvm_utils.Thread(vm.copy_files_from, + (guest_path, host_path_returned, 0, transfer_timeout)) - bg.start() - try: - while bg.is_alive(): - logging.info("File transfer not ended, starting a round of " - "migration...") - vm = kvm_test_utils.migrate(vm, env, mig_timeout, mig_protocol) - finally: - bg.join() + run_and_migrate(bg) # Make sure the returned file is indentical to the original one orig_hash = client_utils.hash_file(host_path) @@ -81,7 +65,6 @@ def run_migration_with_file_transfer(test, params, env): raise error.TestFail("Returned file hash (%s) differs from " "original one (%s)" % (returned_hash, orig_hash)) - finally: session.close() if os.path.isfile(host_path): diff --git a/client/tests/kvm/tests/migration_with_reboot.py b/client/tests/kvm/tests/migration_with_reboot.py index c96a4d7..a365239 100644 --- a/client/tests/kvm/tests/migration_with_reboot.py +++ b/client/tests/kvm/tests/migration_with_reboot.py @@ -19,65 +19,23 @@ def run_migration_with_reboot(test, params, env): @param params: Dictionary with test parameters. @param env: Dictionary with the test environment. """ - def reboot_test(client, session, address, reboot_command, port, username, - password, prompt, linesep, log_filename, timeout): - """ - A version of reboot test which is safe to be called in the background as - it doesn't need a VM object. - """ - # Send a reboot command to the guest's shell - session.sendline(reboot_command) - logging.info("Reboot command sent. Waiting for guest to go down...") - - # Wait for the session to become unresponsive and close it - if not kvm_utils.wait_for(lambda: not session.is_responsive(timeout=30), - 120, 0, 1): - raise error.TestFail("Guest refuses to go down") - session.close() - - # Try logging into the guest until timeout expires - logging.info("Guest is down. Waiting for it to go up again, timeout " - "%ds", timeout) - session = kvm_utils.wait_for_login(client, address, port, username, - password, prompt, linesep, - log_filename, timeout) - logging.info("Guest is up again") - session.close() - vm = env.get_vm(params["main_vm"]) vm.verify_alive() - timeout = int(params.get("login_timeout", 360)) - session = vm.wait_for_login(timeout=timeout) - - # params of reboot - username = vm.params.get("username", "") - password = vm.params.get("password", "") - prompt = vm.params.get("shell_prompt", "[\#\$]") - linesep = eval("'%s'" % vm.params.get("shell_linesep", r"\n")) - client = vm.params.get("shell_client") - address = vm.get_address(0) - port = vm.get_port(int(params.get("shell_port"))) - log_filename = ("migration-reboot-%s-%s.log" % - (vm.name, kvm_utils.generate_random_string(4))) - reboot_command = vm.params.get("reboot_command") + login_timeout = int(params.get("login_timeout", 360)) + session = vm.wait_for_login(timeout=login_timeout) mig_timeout = float(params.get("mig_timeout", "3600")) mig_protocol = params.get("migration_protocol", "tcp") - mig_cancel = bool(params.get("mig_cancel")) + mig_cancel_delay = int(params.get("mig_cancel") == "yes") * 2 try: # Reboot the VM in the background - bg = kvm_utils.Thread(reboot_test, (client, session, address, - reboot_command, port, username, - password, prompt, linesep, - log_filename, timeout)) + bg = kvm_utils.Thread(kvm_test_utils.reboot, (vm, session)) bg.start() - try: while bg.is_alive(): - vm = kvm_test_utils.migrate(vm, env, mig_timeout, mig_protocol) + vm.migrate(mig_timeout, mig_protocol, mig_cancel_delay) finally: - bg.join() - + session = bg.join() finally: session.close()