From patchwork Wed Dec 22 13:27:22 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amos Kong X-Patchwork-Id: 427231 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 oBMDQxY2023715 for ; Wed, 22 Dec 2010 13:26:59 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753229Ab0LVN0i (ORCPT ); Wed, 22 Dec 2010 08:26:38 -0500 Received: from mx1.redhat.com ([209.132.183.28]:40658 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751826Ab0LVN0h (ORCPT ); Wed, 22 Dec 2010 08:26:37 -0500 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id oBMDQat5009769 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 22 Dec 2010 08:26:36 -0500 Received: from dhcp-91-173.nay.redhat.com (dhcp-91-173.nay.redhat.com [10.66.91.173]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id oBMDQYa4019224; Wed, 22 Dec 2010 08:26:35 -0500 Subject: [PATCH 2/2] KVM-test: Add image_dopy test to prepare images To: autotest@test.kernel.org From: Amos Kong Cc: lmr@redhat.com, kvm@vger.kernel.org Date: Wed, 22 Dec 2010 21:27:22 +0800 Message-ID: <20101222132722.29867.87341.stgit@dhcp-91-173.nay.redhat.com> In-Reply-To: <20101222132714.29867.325.stgit@dhcp-91-173.nay.redhat.com> References: <20101222132714.29867.325.stgit@dhcp-91-173.nay.redhat.com> User-Agent: StGit/0.15 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 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]); Wed, 22 Dec 2010 13:26:59 +0000 (UTC) diff --git a/client/tests/kvm/tests/image_copy.py b/client/tests/kvm/tests/image_copy.py new file mode 100644 index 0000000..61f0bb5 --- /dev/null +++ b/client/tests/kvm/tests/image_copy.py @@ -0,0 +1,45 @@ +import os, logging, commands +from autotest_lib.client.common_lib import error +import kvm_utils + +def run_image_copy(test, params, env): + """ + Copy guest images from nfs server. + 1) Mount the NFS directory + 2) Check the existence of source image + 3) If existence copy the image from NFS + + @param test: kvm test object + @param params: Dictionary with the test parameters + @param env: Dictionary with test environment. + """ + mount_dest_dir = params.get("dst_dir",'/mnt/images') + try: + os.makedirs(mount_dest_dir) + except OSError, err: + logging.warn("mkdir %s error:\n%s" % (mount_dest_dir, err)) + + if not os.path.exists(mount_dest_dir): + raise error.TestError("Failed to mkdir %s" % mount_dest_dir) + logging.debug("Dir %s exists." % mount_dest_dir) + + src = params.get('images_good') + mnt_cmd = "mount %s %s -o ro" % (src, mount_dest_dir) + pwd = os.path.join(os.environ['AUTODIR'],'tests/kvm/images') + image = os.path.split(params['image_name'])[1]+'.'+params['image_format'] + src_path = os.path.join(mount_dest_dir, image) + dst_path = os.path.join(pwd, image) + cmd = "cp %s %s" % (src_path, dst_path) + + if kvm_utils.mount(src, mount_dest_dir, "nfs", "ro") is not True: + raise error.TestError("Fail to mount the %s to %s" % \ + (src, mount_dest_dir)) + + # Check the existence of source image + if not os.path.exists(src_path): + raise error.TestError("Could not found %s in src directory" % src_path) + + logging.debug("Copying image %s..." % image) + s, o = commands.getstatusoutput(cmd) + if s != 0: + raise error.TestFail("Failed to copy image:%s; Reason: %s" % (cmd, o)) diff --git a/client/tests/kvm/tests_base.cfg.sample b/client/tests/kvm/tests_base.cfg.sample index 4075bfc..5c40ac3 100644 --- a/client/tests/kvm/tests_base.cfg.sample +++ b/client/tests/kvm/tests_base.cfg.sample @@ -63,6 +63,9 @@ profilers = kvm_stat login_timeout = 360 image_raw_device = no +# NFS directory of guests' images +images_good = 0.0.0.0:/autotest/images_good + # Tests variants: - install: @@ -75,6 +78,12 @@ variants: kill_vm_timeout = 60 kill_vm_timeout_on_error = 0 + - image_copy: + type = image_copy + vms = '' + parallel = no + profilers = + - setup: install type = steps fail_if_stuck_for = 300