[PATCH 1/2] virt tests: add dd_test

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

 



This patch adds dd_test which tries simple read/write from/to an attached
disk. The purpose is to test readonly vs. readwrite subsystem.

The dd_test.py is highly parametrizable so it can be used in other
tests by changing parameters.

It also adds another image parameter "image_readonly" (bool) which is
required for this test.

Signed-off-by: Lukas Doktor <ldoktor@xxxxxxxxxx>
---
 client/virt/kvm_vm.py           |    6 ++-
 client/virt/subtests.cfg.sample |   35 +++++++++++++
 client/virt/tests/dd_test.py    |  105 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 144 insertions(+), 2 deletions(-)
 create mode 100644 client/virt/tests/dd_test.py

diff --git a/client/virt/kvm_vm.py b/client/virt/kvm_vm.py
index 80ea453..cbc0494 100644
--- a/client/virt/kvm_vm.py
+++ b/client/virt/kvm_vm.py
@@ -310,7 +310,7 @@ class VM(virt_vm.BaseVM):
                       boot=False, blkdebug=None, bus=None, port=None,
                       bootindex=None, removable=None, min_io_size=None,
                       opt_io_size=None, physical_block_size=None,
-                      logical_block_size=None):
+                      logical_block_size=None, readonly=False):
             name = None
             dev = ""
             if format == "ahci":
@@ -362,6 +362,7 @@ class VM(virt_vm.BaseVM):
             cmd += _add_option("snapshot", snapshot, bool)
             cmd += _add_option("boot", boot, bool)
             cmd += _add_option("id", name)
+            cmd += _add_option("readonly", readonly, bool)
             return cmd + dev
 
         def add_nic(help, vlan, model=None, mac=None, device_id=None, netdev_id=None,
@@ -758,7 +759,8 @@ class VM(virt_vm.BaseVM):
                     image_params.get("min_io_size"),
                     image_params.get("opt_io_size"),
                     image_params.get("physical_block_size"),
-                    image_params.get("logical_block_size"))
+                    image_params.get("logical_block_size"),
+                    image_params.get("image_readonly"))
 
         redirs = []
         for redir_name in params.objects("redirs"):
diff --git a/client/virt/subtests.cfg.sample b/client/virt/subtests.cfg.sample
index 2192840..ec9fbc3 100644
--- a/client/virt/subtests.cfg.sample
+++ b/client/virt/subtests.cfg.sample
@@ -398,6 +398,41 @@ variants:
                 create_image_stg = yes
                 image_size_stg = 10M
 
+    - dd_test: install setup image_copy unattended_install.cdrom
+        type = dd_test
+        images += " stg1"
+        image_name_stg1 = "sgt1"
+        image_size_stg1 = 1M
+        image_snapshot_stg1 = no
+        drive_index_stg1 = 3
+        dd_count = 1
+        # last input and output disk
+        dd_if_select = -1
+        dd_of_select = -1
+        variants:
+            - readwrite:
+                dd_stat = 0
+                variants:
+                    - zero2disk:
+                        dd_if = ZERO
+                        dd_of = /dev/[shv]d?
+                    - disk2null:
+                        dd_if = /dev/[shv]d?
+                        dd_of = NULL
+            - readonly:
+                # ide, ahci don't support readonly disks
+                no ide, ahci
+                image_readonly_stg1 = yes
+                variants:
+                    - zero2disk:
+                        dd_if = ZERO
+                        dd_of = /dev/[shv]d?
+                        dd_stat = 1
+                    - disk2null:
+                        dd_if = /dev/[shv]d?
+                        dd_of = NULL
+                        dd_stat = 0
+
 
     - virsh_migrate: install setup image_copy unattended_install.cdrom
         type = virsh_migrate
diff --git a/client/virt/tests/dd_test.py b/client/virt/tests/dd_test.py
new file mode 100644
index 0000000..48d32b5
--- /dev/null
+++ b/client/virt/tests/dd_test.py
@@ -0,0 +1,105 @@
+"""
+Configurable on-guest dd test.
+@author: Lukas Doktor <ldoktor@xxxxxxxxxx>
+@copyright: 2012 Red Hat, Inc.
+"""
+import logging
+from autotest_lib.client.common_lib import error
+from autotest_lib.client.virt.aexpect import ShellCmdError
+from autotest_lib.client.virt.aexpect import ShellTimeoutError
+
+
+def run_dd_test(test, params, env):
+    """
+    Executes dd with defined parameters and checks the return number and output
+    """
+    def _get_file(filename, select):
+        """ Picks the actual file based on select value """
+        if filename == "NULL":
+            return "/dev/null"
+        elif filename == "ZERO":
+            return "/dev/zero"
+        elif filename == "RANDOM":
+            return "/dev/random"
+        elif filename == "URANDOM":
+            return "/dev/urandom"
+        else:
+            # get all matching filenames
+            try:
+                disks = sorted(session.cmd("ls -1d %s" % filename).split('\n'))
+            except ShellCmdError:   # No matching file (creating new?)
+                disks = [filename]
+            if disks[-1] == '':
+                disks = disks[:-1]
+            try:
+                return disks[select]
+            except IndexError:
+                err = ("Incorrect cfg: dd_select out of the range (disks=%s,"
+                       " select=%s)" % (disks, select))
+                logging.error(err)
+                raise error.TestError(err)
+
+    vm = env.get_vm(params['main_vm'])
+    timeout = int(params.get("login_timeout", 360))
+    session = vm.wait_for_login(timeout=timeout)
+
+    dd_if = params.get("dd_if")
+    dd_if_select = int(params.get("dd_if_select", '-1'))
+    dd_of = params.get("dd_of")
+    dd_of_select = int(params.get("dd_of_select", '-1'))
+    dd_bs = params.get("dd_bs")
+    dd_count = params.get("dd_count")
+    dd_iflag = params.get("dd_iflag")
+    dd_oflag = params.get("dd_oflag")
+    dd_skip = params.get("dd_skip")
+    dd_seek = params.get("dd_seek")
+
+    dd_timeout = int(params.get("dd_timeout", 60))
+
+    dd_output = params.get("dd_output", "")
+    dd_stat = int(params.get("dd_stat", 0))
+
+    dd_cmd = "dd"
+    if dd_if:
+        dd_if = _get_file(dd_if, dd_if_select)
+        dd_cmd += " if=%s" % dd_if
+    if dd_of:
+        dd_of = _get_file(dd_of, dd_of_select)
+        dd_cmd += " of=%s" % dd_of
+    if dd_bs:
+        dd_cmd += " bs=%s" % dd_bs
+    if dd_count:
+        dd_cmd += " count=%s" % dd_count
+    if dd_iflag:
+        dd_cmd += " iflag=%s" % dd_iflag
+    if dd_oflag:
+        dd_cmd += " oflag=%s" % dd_oflag
+    if dd_skip:
+        dd_cmd += " skip=%s" % dd_skip
+    if dd_seek:
+        dd_cmd += " seek=%s" % dd_seek
+    logging.info("Using '%s' cmd", dd_cmd)
+
+    try:
+        (stat, out) = session.cmd_status_output(dd_cmd, timeout=dd_timeout)
+    except ShellTimeoutError:
+        err = ("dd command timed-out (cmd='%s', timeout=%d)"
+                                                    % (dd_cmd, dd_timeout))
+        logging.error(err)
+        raise error.TestFail(err)
+    except ShellCmdError, details:
+        stat = details.status
+        out = details.output
+
+    logging.debug("Returned dd_status: %s\nReturned output:\n%s", stat, out)
+    if stat != dd_stat:
+        err = ("Return code doesn't match (expected=%s, actual=%s)\n"
+               "Output:\n%s" % (dd_stat, stat, out))
+        logging.error(err)
+        raise error.TestFail(err)
+    if dd_output not in out:
+        err = ("Output doesn't match:\nExpected:\n%s\nActual:\n%s"
+                                                        % (dd_output, out))
+        raise error.TestFail(err)
+    logging.info("dd test succeeded.")
+    return
-- 
1.7.7.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