From patchwork Thu Mar 4 07:12:32 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: sshang X-Patchwork-Id: 83542 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 o2477Ypk021188 for ; Thu, 4 Mar 2010 07:07:35 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753276Ab0CDHH0 (ORCPT ); Thu, 4 Mar 2010 02:07:26 -0500 Received: from mx1.redhat.com ([209.132.183.28]:14776 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753138Ab0CDHH0 (ORCPT ); Thu, 4 Mar 2010 02:07:26 -0500 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o2477O71024282 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 4 Mar 2010 02:07:24 -0500 Received: from localhost.localdomain ([10.66.91.194]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o2477LRZ013803; Thu, 4 Mar 2010 02:07:22 -0500 From: sshang To: lmr@redhat.com Cc: autotest@test.kernel.org, kvm@vger.kernel.org, sshang Subject: [PATCH] KVM-Test: Add a kvm subtest format_disk Date: Thu, 4 Mar 2010 15:12:32 +0800 Message-Id: <1267686752-26558-1-git-send-email-sshang@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.21 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]); Thu, 04 Mar 2010 07:07:35 +0000 (UTC) diff --git a/client/tests/kvm/tests/format_disk.py b/client/tests/kvm/tests/format_disk.py new file mode 100644 index 0000000..7e340ad --- /dev/null +++ b/client/tests/kvm/tests/format_disk.py @@ -0,0 +1,63 @@ +import logging +from autotest_lib.client.common_lib import error +import kvm_test_utils, kvm_utils + +def run_format_disk(test, params, env): + """ + Format guest disk: + 1) Boot guest with second disk + 2) Log into guest + 3) Sent sequence commands which format disk1 and mount it to guest + 4) Write some random str into one file within guest disk1 and read it, make sure all right. + + @param test: kvm test object + @param params: Dictionary with the test parameters + @param env: Dictionary with test environment. + """ + vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) + session = kvm_test_utils.wait_for_login(vm, + timeout=int(params.get("login_timeout", 360))) + + # Create a partition on disk + create_partition_cmd = params.get("create_partition_cmd") + if create_partition_cmd: + s, o = session.get_command_status_output(create_partition_cmd) + if s != 0: + raise error.TestFail, "Failed to create partition with error: %s" % o + logging.info("Output of command of create partition on disk: %s" % o) + + # Format the disk + format_cmd = params.get("format_cmd") + if format_cmd: + s, o = session.get_command_status_output(format_cmd, timeout=1200) + if s != 0: + raise error.TestFail, "Failed to format with error: %s" % o + logging.info("Output of format disk command: %s" % o) + + # Mount the disk + mount_cmd = params.get("mount_cmd") + if mount_cmd: + s, o = session.get_command_status_output(mount_cmd) + if s != 0: + raise error.TestFail, "Failed to mount with error: %s" % o + logging.info("Output of mount disk command: %s" % o) + + # Write some random string to test file + testfile_name = params.get("testfile_name") + ranstr = kvm_utils.generate_random_string(100) + + writefile_cmd = params.get("writefile_cmd") + wfilecmd = writefile_cmd + " " + ranstr + " >" + testfile_name + s, o = session.get_command_status_output(wfilecmd) + if s != 0: + raise error.TestFail("Write to file error: %s" % o) + + # Read in the file to see whether content is changed + readfile_cmd = params.get("readfile_cmd") + rfilecmd = readfile_cmd + " " + testfile_name + s, o = session.get_command_status_output(rfilecmd) + if s != 0: + raise error.TestFail("Read file error: %s" % o) + if o.strip() != ranstr: + raise error.TestFail("The content writen to file is changed") + session.close() diff --git a/client/tests/kvm/tests_base.cfg.sample b/client/tests/kvm/tests_base.cfg.sample index 040d0c3..20897f9 100644 --- a/client/tests/kvm/tests_base.cfg.sample +++ b/client/tests/kvm/tests_base.cfg.sample @@ -300,6 +300,17 @@ variants: shutdown_method = shell kill_vm = yes kill_vm_gracefully = no + + - format_disk: + type = format_disk + images += " disk1" + boot_drive_disk1 = yes + image_boot_disk1 = no + image_name_disk1 = storage + image_size_disk1 = 10G + force_create_image_disk1 = yes + writefile_cmd = echo + kill_vm = yes # Do not define test variants below shutdown @@ -329,6 +340,11 @@ variants: file_transfer_port = 22 mem_chk_cmd = dmidecode -t 17 | awk -F: '/Size/ {print $2}' cpu_chk_cmd = grep -c processor /proc/cpuinfo + format_disk: + format_cmd = cd /dev && ls | egrep [shv]db | xargs mkfs.ext3 + mount_cmd = cd /dev && ls | egrep [shv]db | xargs -I dev mount -t ext3 dev /media + testfile_name = /media/txt.txt + readfile_cmd = cat variants: - Fedora: @@ -531,6 +547,9 @@ variants: steps=RHEL-3.9-i386.steps unattended_install: unattended_file = unattended/RHEL-3-series.ks + format_disk: + format_cmd = cd /dev && echo hdb | xargs mkfs.ext3 + mount_cmd = test -d /media || mkdir /media && cd /dev && mount -t ext3 hdb /media - 3.9.x86_64: no setup autotest linux_s3 @@ -543,6 +562,9 @@ variants: steps=RHEL-3.9-x86_64.steps unattended_install: unattended_file = unattended/RHEL-3-series.ks + format_disk: + format_cmd = cd /dev && echo hdb | xargs mkfs.ext3 + mount_cmd = test -d /media || mkdir /media && cd /dev && mount -t ext3 hdb /media - 4.7.i386: no setup autotest @@ -693,6 +715,11 @@ variants: pci_test_cmd = echo select disk 1 > dt && echo online >> dt && echo detail disk >> dt && echo exit >> dt && diskpart /s dt physical_resources_check: catch_uuid_cmd = + format_disk: + create_partition_cmd = "echo select disk 1 > cmd && echo create partition primary >> cmd && echo select partition 1 >> cmd && echo assign >> cmd && echo exit >> cmd && diskpart /s cmd" + format_cmd = format E: /FS:NTFS /V:local /Q /y + testfile_name = E:\\txt.txt + readfile_cmd = type variants: - Win2000: