From patchwork Wed Dec 29 14:35:48 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lucas Meneghel Rodrigues X-Patchwork-Id: 439541 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 oBUMBEjp000490 for ; Thu, 30 Dec 2010 22:11:29 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752526Ab0L2Of4 (ORCPT ); Wed, 29 Dec 2010 09:35:56 -0500 Received: from mx1.redhat.com ([209.132.183.28]:57546 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752841Ab0L2Of4 (ORCPT ); Wed, 29 Dec 2010 09:35:56 -0500 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id oBTEZtZr012216 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 29 Dec 2010 09:35:55 -0500 Received: from freedom.redhat.com (vpn-8-145.rdu.redhat.com [10.11.8.145]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id oBTEZnA0009850; Wed, 29 Dec 2010 09:35:53 -0500 From: Lucas Meneghel Rodrigues To: autotest@test.kernel.org Cc: kvm@vger.kernel.org, Amos Kong Subject: [PATCH 2/2] KVM-test: Add image_copy subtest to prepare images Date: Wed, 29 Dec 2010 12:35:48 -0200 Message-Id: <1293633348-7188-3-git-send-email-lmr@redhat.com> In-Reply-To: <1293633348-7188-1-git-send-email-lmr@redhat.com> References: <1293633348-7188-1-git-send-email-lmr@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 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]); Thu, 30 Dec 2010 22:11:29 +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..87bafea --- /dev/null +++ b/client/tests/kvm/tests/image_copy.py @@ -0,0 +1,46 @@ +import os, logging, commands +from autotest_lib.client.common_lib import error +from autotest_lib.client.bin import utils +import kvm_utils + + +def run_image_copy(test, params, env): + """ + Copy guest images from nfs server. + 1) Mount the NFS share directory + 2) Check the existence of source image + 3) If it exists, 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): + try: + os.makedirs(mount_dest_dir) + except OSError, err: + logging.warning('mkdir %s error:\n%s', mount_dest_dir, err) + + if not os.path.exists(mount_dest_dir): + raise error.TestError('Failed to create NFS share dir %s' % + mount_dest_dir) + + src = params.get('images_good') + mnt_cmd = 'mount %s %s -o ro' % (src, mount_dest_dir) + image = '%s.%s' % (os.path.split(params['image_name'])[1], + params['image_format']) + src_path = os.path.join(mount_dest_dir, image) + dst_path = '%s.%s' % (params['image_name'], params['image_format']) + cmd = 'cp %s %s' % (src_path, dst_path) + + if not kvm_utils.mount(src, mount_dest_dir, 'nfs', 'ro'): + raise error.TestError('Could not mount NFS share %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 find %s in NFS share' % src_path) + + logging.debug('Copying image %s...' % image) + utils.system(cmd) diff --git a/client/tests/kvm/tests_base.cfg.sample b/client/tests/kvm/tests_base.cfg.sample index d3275c8..1a260b4 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