From patchwork Wed Jan 6 03:32:00 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yolkfull Chow X-Patchwork-Id: 71227 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.2) with ESMTP id o063W9Gg018639 for ; Wed, 6 Jan 2010 03:32:09 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754687Ab0AFDcG (ORCPT ); Tue, 5 Jan 2010 22:32:06 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1754675Ab0AFDcG (ORCPT ); Tue, 5 Jan 2010 22:32:06 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42677 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754592Ab0AFDcD (ORCPT ); Tue, 5 Jan 2010 22:32:03 -0500 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 o063W2gg006394 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 5 Jan 2010 22:32:02 -0500 Received: from localhost.localdomain (dhcp-65-181.nay.redhat.com [10.66.65.181]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o063Vxf3029364; Tue, 5 Jan 2010 22:32:00 -0500 From: Yolkfull Chow To: autotest@test.kernel.org Cc: kvm@vger.kernel.org, Yolkfull Chow Subject: [Autotest PATCH] KVM-test: Add a subtest image_copy Date: Wed, 6 Jan 2010 11:32:00 +0800 Message-Id: <1262748720-11385-1-git-send-email-yzhou@redhat.com> 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 diff --git a/client/tests/kvm/kvm_utils.py b/client/tests/kvm/kvm_utils.py index 2bbbe22..3944b2b 100644 --- a/client/tests/kvm/kvm_utils.py +++ b/client/tests/kvm/kvm_utils.py @@ -924,3 +924,67 @@ def create_report(report_dir, results_dir): reporter = os.path.join(report_dir, 'html_report.py') html_file = os.path.join(results_dir, 'results.html') os.system('%s -r %s -f %s -R' % (reporter, results_dir, html_file)) + + +def is_dir_mounted(source, dest, type, perm): + """ + Check whether `source' is mounted on `dest' with right permission. + + @source: mount source + @dest: mount point + @type: file system type + """ + match_string = "%s %s %s %s" % (source, dest, type, perm) + try: + f = open("/etc/mtab", "r") + mounted = f.read() + f.close() + except IOError: + mounted = commands.getoutput("mount") + if match_string in mounted: + return True + return False + + +def umount(mount_point): + """ + Umount `mount_point'. + + @mount_point: mount point + """ + cmd = "umount %s" % mount_point + s, o = commands.getstatusoutput(cmd) + if s != 0: + logging.error("Fail to umount: %s" % o) + return False + return True + + +def mount(src, mount_point, type, perm = "rw"): + """ + Mount the src into mount_point of the host. + + @src: mount source + @mount_point: mount point + @type: file system type + @perm: mount permission + """ + if is_dir_mounted(src, mount_point, type, perm): + return True + + umount(mount_point) + + cmd = "mount -t %s %s %s -o %s" % (type, src, mount_point, perm) + logging.debug("Issue mount command: %s" % cmd) + s, o = commands.getstatusoutput(cmd) + if s != 0: + logging.error("Fail to mount: %s " % o) + return False + + if is_dir_mounted(src, mount_point, type, perm): + logging.info("Successfully mounted %s" % src) + return True + else: + logging.error("Mount verification failed; currently mounted: %s" % + file('/etc/mtab').read()) + return False diff --git a/client/tests/kvm/tests/image_copy.py b/client/tests/kvm/tests/image_copy.py new file mode 100644 index 0000000..800fb90 --- /dev/null +++ b/client/tests/kvm/tests/image_copy.py @@ -0,0 +1,42 @@ +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') + if not os.path.exists(mount_dest_dir): + os.mkdir(mount_dest_dir) + + src_dir = params.get('nfs_images_dir') + image_dir = os.path.join(os.environ['AUTODIR'],'tests/kvm/images') + if not os.path.exists(image_dir): + image_dir = os.path.dirname(params.get("image_name")) + + 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(image_dir, image) + + if not kvm_utils.mount(src_dir, mount_dest_dir, "nfs", "ro"): + raise error.TestError("Fail to mount the %s to %s" % + (src_dir, 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.info("Copying image '%s'..." % image) + cmd = "cp %s %s" % (src_path, dst_path) + s, o = commands.getstatusoutput(cmd) + if s != 0: + raise error.TestFail("Failed to copy image %s: %s" % (cmd, o)) diff --git a/client/tests/kvm/tests_base.cfg.sample b/client/tests/kvm/tests_base.cfg.sample index b8f25f4..bdeac19 100644 --- a/client/tests/kvm/tests_base.cfg.sample +++ b/client/tests/kvm/tests_base.cfg.sample @@ -61,6 +61,12 @@ variants: floppy = "images/floppy.img" extra_params += " -boot d" + - image_copy: + type = image_copy + vms = '' + # Here specify the NFS directory that contains all images + nfs_images_dir = + - setup: install unattended_install type = steps fail_if_stuck_for = 300