Hi Lucas,

Please find the below patch to test the block stream test case.
This patch addresses the below item:
https://github.com/autotest/autotest/issues/403



Signed-off-by: Satheesh Rajendran <sathn...@linux.vnet.ibm.com>

 create mode 100644 client/tests/kvm/tests/block_stream.py

diff --git a/client/tests/kvm/tests/block_stream.py 
b/client/tests/kvm/tests/block_stream.py
new file mode 100644
index 0000000..0150c12
--- /dev/null
+++ b/client/tests/kvm/tests/block_stream.py
@@ -0,0 +1,148 @@
+import re, os, logging, commands, string, time
+from autotest.client.shared import utils, error
+from autotest.client.virt import kvm_monitor, virt_utils, virt_vm, aexpect, 
virt_env_process
+
+def run_block_stream(test, params, env):
+    """
+    Test block streaming functionality.
+
+    1) Create a image_bak.img with the backing file image.img
+    2) Start the image_bak.img in qemu command line.
+    3) Request for block-stream ide0-hd0/virtio0
+    4) Wait till the block job finishs
+    5) Check for backing file in image_bak.img
+    6) TODO: Check for the size of the image_bak.img should not exceeds the 
image.img
+    7) TODO(extra): Block job completion can be check in QMP
+    """
+    image_format = params.get("image_format")
+    image_name = params.get("image_name", "image")
+    drive_format = params.get("drive_format")
+    backing_file_name = "%s_bak" % (image_name)
+    
+    def check_block_jobs_info():
+        """
+        Verify the status of block-jobs reported by monitor command info 
block-jobs.
+        @return: parsed output of info block-jobs
+        """
+        fail = 0
+        
+        try:
+            output = vm.monitor.info("block-jobs")
+        except kvm_monitor.MonitorError, e:
+            logging.error(e)
+            fail += 1
+            return None, None 
+        return (re.match("\w+", str(output)), re.findall("\d+", str(output)))
+  
+    try:
+        # Remove the existing backing file
+        backing_file = "%s.%s" % (backing_file_name, image_format)
+        if os.path.isfile(backing_file):
+            os.remove(backing_file)
+
+        # Create the new backing file
+        create_cmd = "qemu-img create -b %s.%s -f %s %s.%s" % (image_name,
+                                                               image_format,
+                                                               image_format,
+                                                             backing_file_name,
+                                                               image_format)
+        try:
+            utils.system(create_cmd)
+        except error.CmdError, e:
+            raise error.TestFail("Could not create a backing file!")
+        logging.info("backing_file created!")
+         
+        info_cmd = "qemu-img info %s.%s" % (image_name,image_format)
+        try:
+           results = utils.system_output(info_cmd)
+        except error.CmdError, e:
+           raise error.TestFail("Could not find the image file!")
+
+        logging.info("Infocmd output of basefile: %s" ,results)
+
+        # Set the qemu harddisk to the backing file
+        logging.info("Original image_name is: %s", params.get('image_name'))
+        params['image_name'] = backing_file_name
+        logging.info("Param image_name changed to: %s",
+                     params.get('image_name'))
+
+        # Start virtual machine, using backing file as its harddisk
+        vm_name = params.get('main_vm')
+        virt_env_process.preprocess_vm(test, params, env, vm_name)
+        vm = env.get_vm(vm_name)
+        vm.create()
+        timeout = int(params.get("login_timeout", 360))
+        session = vm.wait_for_login(timeout=timeout)
+            
+        info_cmd = "qemu-img info %s.%s" % (backing_file_name,image_format)
+        try:
+           results = utils.system_output(info_cmd)
+        except error.CmdError, e:
+           raise error.TestFail("Could not find the image file!")
+
+        logging.info("Infocmd output of backing file before block streaming: 
%s" ,results)
+        
+        if not re.search("backing file:", str(results)):
+           raise error.TestFail(" Backing file is not available in the 
backdrive image")
+
+        #####
+        #start streaming in qemu-cmd line
+        #####
+        if 'ide' in drive_format:
+            try:
+               vm.monitor.cmd("block-stream ide0-hd0")
+            except kvm_monitor.MonitorError, e:
+               logging.error(e)
+        elif 'virtio' in drive_format:
+            try:
+               vm.monitor.cmd("block-stream virtio0")
+            except kvm_monitor.MonitorError, e:
+               logging.error(e)
+        else:
+            raise error.TestFail("The drive format is not supported")
+
+        while True:
+            blkjobout, blkjobstatus = check_block_jobs_info()
+            if 'Streaming' in blkjobout.group(0):
+                logging.info("[(Completed bytes): %s (Total bytes): %s (Speed 
in bytes/s): %s]", blkjobstatus[-3], blkjobstatus[-2], blkjobstatus[-1])
+                time.sleep(10)
+                continue
+            if 'No' in blkjobout.group(0):
+                logging.info("Block job completed")
+                break
+
+        info_cmd = "qemu-img info %s.%s" % (backing_file_name,image_format)
+        try:
+           results = utils.system_output(info_cmd)
+        except error.CmdError, e:
+           raise error.TestFail("Could not find the image file!")
+          
+        logging.info("Infocmd output of backing file after block streaming: 
%s" ,results)  
+         
+        if re.search("backing file:", str(results)):
+           raise error.TestFail(" Backing file is still available in the 
backdrive image")
+        # 
+        #TODO
+        #. The file size should be more/less equal to the "baking file" size 
+        #
+        
+        #shutdown the virtual machine
+        vm.destroy()
+        
+        # relogin with the backup-harddrive
+        vm.create()
+        timeout = int(params.get("login_timeout", 360))
+        session = vm.wait_for_login(timeout=timeout)
+        try:
+           output = session.cmd("touch /testfile")
+           logging.info("Output of touch /testfile: %s", output)
+        except error.CmdError, e:
+           raise error.TestFail("Could not create a file in the 
backup-harddrive!")
+       
+        #Finally shutdown the virtual machine 
+        vm.destroy()
+        logging.info("END")    
+    finally:
+        # Remove the backing file
+        if os.path.isfile(backing_file):
+            os.remove(backing_file)
diff --git a/client/virt/subtests.cfg.sample b/client/virt/subtests.cfg.sample
index ebfbff5..7c1c715 100644
--- a/client/virt/subtests.cfg.sample
+++ b/client/virt/subtests.cfg.sample
@@ -783,6 +783,9 @@ variants:
         type = stop_continue
         kill_vm_on_error = yes
 
+    - block_stream:
+        type = block_stream
+
     - nfs_corrupt:
         only Linux
         type = nfs_corrupt
-- 
1.7.5.4


Regards,
-Satheesh.

_______________________________________________
Autotest mailing list
Autotest@test.kernel.org
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

Reply via email to