From: yacui <[email protected]>

comments:
KVM readonly_floppy test:
1) pre_command on the host to generate the floppy media
   : "dd if=images/fd1.img bs=512 count=2880
   && dd if=images/fd2.img bs=512 count=2880"
2) Boot and login into a guest;
3) If the OS is linux, load the floppy module, or if
   it is a Windows,wait 20s until the floppies are ready to be used
4) Make filesystem against the floppy and reads the output of the
   command,check if there is 'Read-only'(for linux) or
   'protected'(for windows) keyword,if not,fail the test;
5) Close session to the VM

Signed-off-by: yacui <[email protected]>
---
 client/tests/kvm/tests/readonly_floppy.py |   65 +++++++++++++++++++++++++++++
 client/tests/kvm/virtlab_tests.cfg        |   13 ++++++
 2 files changed, 78 insertions(+), 0 deletions(-)
 create mode 100644 client/tests/kvm/tests/readonly_floppy.py

diff --git a/client/tests/kvm/tests/readonly_floppy.py 
b/client/tests/kvm/tests/readonly_floppy.py
new file mode 100644
index 0000000..9274c5b
--- /dev/null
+++ b/client/tests/kvm/tests/readonly_floppy.py
@@ -0,0 +1,65 @@
+import logging, time, re
+from autotest_lib.client.common_lib import error
+import kvm_subprocess, kvm_test_utils, kvm_utils
+
+def run_readonly_floppy(test, params, env):
+    """ 
+    KVM readonly_floppy test:
+    1) pre_command on the host to generate the floppy media
+       : "dd if=images/fd1.img bs=512 count=2880
+       && dd if=images/fd2.img bs=512 count=2880"
+    2) Boot and login into a guest;
+    3) If the OS is linux, load the floppy module, or if
+       it is a Windows,wait 20s until the floppies are ready to be used
+    4) Make filesystem against the floppy and reads the output of the
+       command,check if there is 'Read-only'(for linux) or
+       'protected'(for windows) keyword,if not,fail the test;
+    5) Close session to the VM
+
+    @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"))
+    timeout = float(params.get("login_timeout", 240))
+    session = kvm_test_utils.wait_for_login(vm, 0, timeout, 0, 2)
+
+    sleep = params.get("sleep")
+    #if it is a windows OS,wait for 20 seconds until the floppies
+    #are ready for testing 
+    if sleep:
+        logging.info("Windows system being tested,sleep for 20"
+        " seconds until floppies are ready to be use")
+        time.sleep(20)
+
+    try:
+    #if it is a linux OS,load the floppy module
+        if not sleep:
+            logging.info("Loading the floppy module...")
+            status = session.get_command_status("modprobe floppy")
+            if status:
+                raise error.TestError("Unable to load the floppy module")
+
+        # Format floppy disk to test if it is readonly
+        floppy_count = len(params.get("floppy").split())
+        format_cmd_list = [params.get("format_floppy0_cmd"),
+                           params.get("format_floppy1_cmd")]
+
+        for floppy_index in range(floppy_count):
+            s, o = session.get_command_status_output(
+             format_cmd_list[floppy_index],timeout=10)
+            if s == 0:
+                raise error.TestError("Floppy disk %s is not readonly and" 
+                       " it's formatted successfully" %floppy_index )
+            found = re.search('(Read-only)|(protected)',o)
+            print o
+            if not found:
+                raise error.TestError("Floppy disk %s cannot be formatted"
+                 " for reasons other than readonly" %floppy_index )
+            else:
+                logging.info("Floppy disk %s is Read-only and cannot be"
+                              " formatted" %floppy_index)
+
+    finally:
+        session.close()
+
diff --git a/client/tests/kvm/virtlab_tests.cfg 
b/client/tests/kvm/virtlab_tests.cfg
index 727d0ae..26fb937 100644
--- a/client/tests/kvm/virtlab_tests.cfg
+++ b/client/tests/kvm/virtlab_tests.cfg
@@ -517,6 +517,12 @@ variants:
         floppy = "images/test_floppy.img"
         pre_command = "dd if=/dev/zero of=images/test_floppy.img bs=512 
count=2880"
 
+    - readonly_floppy:
+        type = readonly_floppy
+        floppy = "images/fd1.img images/fd2.img"
+        pre_command = "dd if=/dev/urandom of=images/fd1.img bs=512 count=2880 
&& dd if=/dev/urandom of=images/fd2.img bs=512 count=2880" 
+        floppy_readonly = "True True"
+
     - usb:
         type = usb
         kill_vm = yes
@@ -1706,6 +1712,9 @@ variants:
             mount_dir = /mnt/
             diff_file_cmd = diff
             copy_cmd = cp
+        readonly_floppy:
+            format_floppy0_cmd = mkfs -t ext3 /dev/fd0
+            format_floppy1_cmd = mkfs -t ext3 /dev/fd1
         unattended_install:
             #pre_command += "scripts/private_br.sh tftp;"
             # If you want to use floppy to hold kickstarts,
@@ -2163,6 +2172,10 @@ variants:
             diff_file_cmd = fc
             test_floppy_cmd = chkdsk A:
             copy_cmd = copy
+        readonly_floppy:
+            sleep = True
+            format_floppy0_cmd = echo n|format A: /Q /V:test_floppy
+            format_floppy1_cmd = echo n|format B: /Q /V:test_floppy
         iozone_windows:
             cdrom_cd1 = windows/winutils.iso
             iozone_cmd = "D:\iozone\iozone -a"
-- 
1.7.1

_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

Reply via email to