[PATCH] KVM-Test: Add a kvm subtest format_disk

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



 Add a kvm subtest format_disk.

 This test will simply create a file system on disk, mount it and write a file with some content to the disk. Check whether the write could be succeeded.

Signed-off-by: sshang <sshang@xxxxxxxxxx>
---
 client/tests/kvm/tests/format_disk.py  |   63 ++++++++++++++++++++++++++++++++
 client/tests/kvm/tests_base.cfg.sample |   27 ++++++++++++++
 2 files changed, 90 insertions(+), 0 deletions(-)
 create mode 100644 client/tests/kvm/tests/format_disk.py

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:
-- 
1.5.5.6

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux