diff mbox

KVM-test: Add a ENOSPC subtest

Message ID 20110112114548.15348.15923.stgit@localhost6.localdomain6 (mailing list archive)
State New, archived
Headers show

Commit Message

Amos Kong Jan. 12, 2011, 11:45 a.m. UTC
None
diff mbox

Patch

diff --git a/client/tests/kvm/scripts/check_image.py b/client/tests/kvm/scripts/check_image.py
old mode 100644
new mode 100755
diff --git a/client/tests/kvm/tests/enospc.py b/client/tests/kvm/tests/enospc.py
new file mode 100644
index 0000000..28b5988
--- /dev/null
+++ b/client/tests/kvm/tests/enospc.py
@@ -0,0 +1,56 @@ 
+import logging, commands, time, os
+from autotest_lib.client.common_lib import error
+import kvm_test_utils
+
+
+def run_enospc(test, params, env):
+    """
+    ENOSPC test
+
+    1) Create a virtual disk on lvm
+    2) Boot up guest with two disks
+    3) Continually write data to second disk
+    4) Check images and extend second disk when no space
+    5) Continue paused guest
+    6) Repeat step 3~5 several times
+
+    @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 = int(params.get("login_timeout", 360))
+    session_serial = kvm_test_utils.wait_for_login(vm, timeout=timeout,
+                                                   serial=True)
+    devname = params.get("devname", "/dev/hdb")
+    if params.get("drive_format") == "virtio":
+        devname = "/dev/vdb"
+    cmd = params.get("background_cmd")
+    session_serial.sendline(cmd % devname)
+
+    i = 0
+    pause_n = 0
+    while i < int(params.get("repeat_time", 40)):
+        status = vm.monitor.cmd("info status")
+        logging.debug("VM status: %s" % status)
+        if "paused" in status:
+            pause_n += 1
+            script_path = os.path.join(test.bindir, "scripts/check_image.py")
+            s, o = commands.getstatusoutput('python %s' % script_path)
+            if s != 0:
+                logging.debug(o)
+                vm.monitor.cmd("cont")
+                #raise error.TestFail("Image check failed!")
+            cmd = "lvextend -L +200M /dev/vgtest/lvtest"
+            logging.info("Guest paused, extend lvm size, cmd: %s" % cmd)
+            commands.getoutput(cmd)
+            logging.info("Continue guest")
+            vm.monitor.cmd("cont")
+        time.sleep(10)
+        i += 1
+
+    logging.info("Guest paused %s times" % pause_n)
+    if pause_n == 0:
+        raise error.TestFail("Guest doesn't become paused")
+
+    logging.info("The final VM status: %s" % vm.monitor.cmd("info status"))
diff --git a/client/tests/kvm/tests_base.cfg.sample b/client/tests/kvm/tests_base.cfg.sample
index c5d9ca3..17e0e43 100644
--- a/client/tests/kvm/tests_base.cfg.sample
+++ b/client/tests/kvm/tests_base.cfg.sample
@@ -591,6 +591,20 @@  variants:
             - fmt_raw:
                 image_format_stg = raw
 
+    - enospc:
+        type = enospc
+        images += " stg"
+        drive_werror = stop
+        drive_cache = none
+        image_name_stg = enospc
+        image_format_stg = qcow2
+        image_boot_stg = no
+        image_snapshot_stg = no
+        background_cmd = "nohup dd if=/dev/zero of=%s bs=1024 &"
+        pre_command += "qemu-img create -f raw /tmp/enospc.raw 10G && losetup /dev/loop0 /tmp/enospc.raw && pvcreate /dev/loop0 && vgcreate vgtest /dev/loop0 && lvcreate -L200M -n lvtest vgtest && qemu-img create -f qcow2 /dev/vgtest/lvtest 10G && ln -s /dev/vgtest/lvtest /tmp/kvm_autotest_root/images/enospc.qcow2;"
+        post_command += "lvremove -f vgtest; losetup -d /dev/loop0; rm -rf /tmp/enospc.raw /tmp/kvm_autotest_root/images/enospc.qcow2;"
+        kill_vm = yes
+
     - qmp_basic: install setup unattended_install.cdrom
         type = qmp_basic