* [PATCH] KVM-test: Add a qemu-img commit test
@ 2010-12-21 19:43 Lucas Meneghel Rodrigues
2010-12-22 4:05 ` tangchen
0 siblings, 1 reply; 2+ messages in thread
From: Lucas Meneghel Rodrigues @ 2010-12-21 19:43 UTC (permalink / raw)
To: autotest; +Cc: kvm, Lucas Meneghel Rodrigues, Tang Chen
I happen to see that the "qemu-img commit" subcommand test in
qemu_img.py is empty, and it is "pass" by default.
I'm not very sure why it has not been implemented yet. Anyway, I think
this patch would be helpful.
Please comment!
This case is used to test "qemu-img commit" command.
1) Create a backing file of the qemu harddisk specified by image_name.
2) Start a VM using the backing file as its harddisk.
3) Touch a file "commit_testfile" in the backing_file, and shutdown the
VM.
4) Make sure touching the file does not affect the original harddisk.
5) Commit the change to the original harddisk by executing "qemu-img
commit" command.
6) Start the VM using the original harddisk.
7) Check if the file "commit_testfile" exists.
Signed-off-by: Tang Chen <tangchen@cn.fujitsu.com>
---
client/tests/kvm/tests/qemu_img.py | 120 +++++++++++++++++++++++++++++++++++-
1 files changed, 117 insertions(+), 3 deletions(-)
diff --git a/client/tests/kvm/tests/qemu_img.py b/client/tests/kvm/tests/qemu_img.py
index d3f7ff1..39b7427 100644
--- a/client/tests/kvm/tests/qemu_img.py
+++ b/client/tests/kvm/tests/qemu_img.py
@@ -1,6 +1,6 @@
-import re, os, logging, commands
+import re, os, logging, commands, string
from autotest_lib.client.common_lib import utils, error
-import kvm_vm, kvm_utils
+import kvm_vm, kvm_utils, kvm_test_utils, kvm_preprocessing
def run_qemu_img(test, params, env):
@@ -243,10 +243,124 @@ def run_qemu_img(test, params, env):
def commit_test(cmd):
"""
Subcommand 'qemu-img commit' test.
+ 1) Create a backing file of the qemu harddisk specified by image_name.
+ 2) Start a VM using the backing file as its harddisk.
+ 3) Touch a file "commit_testfile" in the backing_file, and shutdown the
+ VM.
+ 4) Make sure touching the file does not affect the original harddisk.
+ 5) Commit the change to the original harddisk by executing
+ "qemu-img commit" command.
+ 6) Start the VM using the original harddisk.
+ 7) Check if the file "commit_testfile" exists.
@param cmd: qemu-img base command.
"""
- pass
+ cmd += " commit"
+
+ logging.info("Commit testing started!")
+ image_name = params.get("image_name", "image")
+ image_format = params.get("image_format", "qcow2")
+ backing_file_name = "%s_bak" % (image_name)
+
+ 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!")
+
+ # 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 a new VM, using backing file as its harddisk
+ vm_name = params.get('main_vm')
+ kvm_preprocessing.preprocess_vm(test, params, env, vm_name)
+ vm = kvm_utils.env_get_vm(env, vm_name)
+ vm.create()
+ timeout = int(params.get("login_timeout", 360))
+ session = kvm_test_utils.wait_for_login(vm, timeout=timeout)
+
+ # Do some changes to the backing_file harddisk
+ try:
+ output = session.cmd("touch /commit_testfile")
+ logging.info("Output of touch /commit_testfile: %s", output)
+ output = session.cmd("ls / | grep commit_testfile")
+ logging.info("Output of ls / | grep commit_testfile: %s",
+ output)
+ except Exception, e:
+ raise error.TestFail("Could not create commit_testfile in the "
+ "backing file %s", e)
+ vm.destroy()
+
+ # Make sure there is no effect on the original harddisk
+ # First, set the harddisk back to the original one
+ logging.info("Current image_name is: %s", params.get('image_name'))
+ params['image_name'] = image_name
+ logging.info("Param image_name reverted to: %s",
+ params.get('image_name'))
+
+ # Second, Start a new VM, using image_name as its harddisk
+ # Here, the commit_testfile should not exist
+ vm_name = params.get('main_vm')
+ kvm_preprocessing.preprocess_vm(test, params, env, vm_name)
+ vm = kvm_utils.env_get_vm(env, vm_name)
+ vm.create()
+ timeout = int(params.get("login_timeout", 360))
+ session = kvm_test_utils.wait_for_login(vm, timeout=timeout)
+ try:
+ output = session.cmd("[ ! -e /commit_testfile ] && echo $?")
+ logging.info("Output of [ ! -e /commit_testfile ] && echo $?: "
+ "%s", output)
+ except:
+ output = session.cmd("rm -f /commit_testfile")
+ raise error.TestFail("The commit_testfile exists on the "
+ "original file")
+ vm.destroy()
+
+ # Excecute the commit command
+ logging.info("Commiting image")
+ cmitcmd = "%s -f %s %s.%s" % (cmd, image_format, backing_file_name,
+ image_format)
+ try:
+ utils.system(cmitcmd)
+ except error.CmdError, e:
+ raise error.TestFail("Could not commit the backing file")
+
+ # Start a new VM, using image_name as its harddisk
+ vm_name = params.get('main_vm')
+ kvm_preprocessing.preprocess_vm(test, params, env, vm_name)
+ vm = kvm_utils.env_get_vm(env, vm_name)
+ vm.create()
+ timeout = int(params.get("login_timeout", 360))
+ session = kvm_test_utils.wait_for_login(vm, timeout=timeout)
+ try:
+ output = session.cmd("[ -e /commit_testfile ] && echo $?")
+ logging.info("Output of [ -e /commit_testfile ] && echo $?: %s",
+ output)
+ session.cmd("rm -f /commit_testfile")
+ except:
+ raise error.TestFail("Could not find commit_testfile after a "
+ "commit")
+ vm.destroy()
+
+ finally:
+ # Remove the backing file
+ if os.path.isfile(backing_file):
+ os.remove(backing_file)
def _rebase(cmd, img_name, base_img, backing_fmt, mode="unsafe"):
--
1.7.2.3
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] KVM-test: Add a qemu-img commit test
2010-12-21 19:43 [PATCH] KVM-test: Add a qemu-img commit test Lucas Meneghel Rodrigues
@ 2010-12-22 4:05 ` tangchen
0 siblings, 0 replies; 2+ messages in thread
From: tangchen @ 2010-12-22 4:05 UTC (permalink / raw)
To: Lucas Meneghel Rodrigues; +Cc: autotest, kvm
Hi,
Thanks, Lucas.
I have tested the patch you re-sent and it works well :)
Cheers!
On 12/22/2010 03:43 AM, Lucas Meneghel Rodrigues wrote:
> I happen to see that the "qemu-img commit" subcommand test in
> qemu_img.py is empty, and it is "pass" by default.
> I'm not very sure why it has not been implemented yet. Anyway, I think
> this patch would be helpful.
> Please comment!
>
> This case is used to test "qemu-img commit" command.
> 1) Create a backing file of the qemu harddisk specified by image_name.
> 2) Start a VM using the backing file as its harddisk.
> 3) Touch a file "commit_testfile" in the backing_file, and shutdown the
> VM.
> 4) Make sure touching the file does not affect the original harddisk.
> 5) Commit the change to the original harddisk by executing "qemu-img
> commit" command.
> 6) Start the VM using the original harddisk.
> 7) Check if the file "commit_testfile" exists.
>
> Signed-off-by: Tang Chen<tangchen@cn.fujitsu.com>
> ---
> client/tests/kvm/tests/qemu_img.py | 120 +++++++++++++++++++++++++++++++++++-
> 1 files changed, 117 insertions(+), 3 deletions(-)
>
> diff --git a/client/tests/kvm/tests/qemu_img.py b/client/tests/kvm/tests/qemu_img.py
> index d3f7ff1..39b7427 100644
> --- a/client/tests/kvm/tests/qemu_img.py
> +++ b/client/tests/kvm/tests/qemu_img.py
> @@ -1,6 +1,6 @@
> -import re, os, logging, commands
> +import re, os, logging, commands, string
> from autotest_lib.client.common_lib import utils, error
> -import kvm_vm, kvm_utils
> +import kvm_vm, kvm_utils, kvm_test_utils, kvm_preprocessing
>
>
> def run_qemu_img(test, params, env):
> @@ -243,10 +243,124 @@ def run_qemu_img(test, params, env):
> def commit_test(cmd):
> """
> Subcommand 'qemu-img commit' test.
> + 1) Create a backing file of the qemu harddisk specified by image_name.
> + 2) Start a VM using the backing file as its harddisk.
> + 3) Touch a file "commit_testfile" in the backing_file, and shutdown the
> + VM.
> + 4) Make sure touching the file does not affect the original harddisk.
> + 5) Commit the change to the original harddisk by executing
> + "qemu-img commit" command.
> + 6) Start the VM using the original harddisk.
> + 7) Check if the file "commit_testfile" exists.
>
> @param cmd: qemu-img base command.
> """
> - pass
> + cmd += " commit"
> +
> + logging.info("Commit testing started!")
> + image_name = params.get("image_name", "image")
> + image_format = params.get("image_format", "qcow2")
> + backing_file_name = "%s_bak" % (image_name)
> +
> + 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!")
> +
> + # 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 a new VM, using backing file as its harddisk
> + vm_name = params.get('main_vm')
> + kvm_preprocessing.preprocess_vm(test, params, env, vm_name)
> + vm = kvm_utils.env_get_vm(env, vm_name)
> + vm.create()
> + timeout = int(params.get("login_timeout", 360))
> + session = kvm_test_utils.wait_for_login(vm, timeout=timeout)
> +
> + # Do some changes to the backing_file harddisk
> + try:
> + output = session.cmd("touch /commit_testfile")
> + logging.info("Output of touch /commit_testfile: %s", output)
> + output = session.cmd("ls / | grep commit_testfile")
> + logging.info("Output of ls / | grep commit_testfile: %s",
> + output)
> + except Exception, e:
> + raise error.TestFail("Could not create commit_testfile in the "
> + "backing file %s", e)
> + vm.destroy()
> +
> + # Make sure there is no effect on the original harddisk
> + # First, set the harddisk back to the original one
> + logging.info("Current image_name is: %s", params.get('image_name'))
> + params['image_name'] = image_name
> + logging.info("Param image_name reverted to: %s",
> + params.get('image_name'))
> +
> + # Second, Start a new VM, using image_name as its harddisk
> + # Here, the commit_testfile should not exist
> + vm_name = params.get('main_vm')
> + kvm_preprocessing.preprocess_vm(test, params, env, vm_name)
> + vm = kvm_utils.env_get_vm(env, vm_name)
> + vm.create()
> + timeout = int(params.get("login_timeout", 360))
> + session = kvm_test_utils.wait_for_login(vm, timeout=timeout)
> + try:
> + output = session.cmd("[ ! -e /commit_testfile ]&& echo $?")
> + logging.info("Output of [ ! -e /commit_testfile ]&& echo $?: "
> + "%s", output)
> + except:
> + output = session.cmd("rm -f /commit_testfile")
> + raise error.TestFail("The commit_testfile exists on the "
> + "original file")
> + vm.destroy()
> +
> + # Excecute the commit command
> + logging.info("Commiting image")
> + cmitcmd = "%s -f %s %s.%s" % (cmd, image_format, backing_file_name,
> + image_format)
> + try:
> + utils.system(cmitcmd)
> + except error.CmdError, e:
> + raise error.TestFail("Could not commit the backing file")
> +
> + # Start a new VM, using image_name as its harddisk
> + vm_name = params.get('main_vm')
> + kvm_preprocessing.preprocess_vm(test, params, env, vm_name)
> + vm = kvm_utils.env_get_vm(env, vm_name)
> + vm.create()
> + timeout = int(params.get("login_timeout", 360))
> + session = kvm_test_utils.wait_for_login(vm, timeout=timeout)
> + try:
> + output = session.cmd("[ -e /commit_testfile ]&& echo $?")
> + logging.info("Output of [ -e /commit_testfile ]&& echo $?: %s",
> + output)
> + session.cmd("rm -f /commit_testfile")
> + except:
> + raise error.TestFail("Could not find commit_testfile after a "
> + "commit")
> + vm.destroy()
> +
> + finally:
> + # Remove the backing file
> + if os.path.isfile(backing_file):
> + os.remove(backing_file)
>
>
> def _rebase(cmd, img_name, base_img, backing_fmt, mode="unsafe"):
>
--
Best Regards,
Tang chen
--------------------------------------------------
Tang Chen
Development Dept.I
Nanjing Fujitsu Nanda Software Tech. Co., Ltd.(FNST)
No.6 Wenzhu Road, Nanjing, 210012, China
TEL: +86+25-86630566-8513
FUJITSU INTERNAL: 7998-8513
FAX: +86+25-83317685
EMail: tangchen@cn.fujitsu.com
--------------------------------------------------
This communication is for use by the intended recipient(s) only and may contain information that is privileged, confidential and exempt from disclosure under applicable law. If you are not an intended recipient of this communication, you are hereby notified that any dissemination, distribution or copying hereof is strictly prohibited. If you have received this communication in error, please notify me by reply e-mail, permanently delete this communication from your system, and destroy any hard copies you may have printed
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2010-12-22 4:02 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-12-21 19:43 [PATCH] KVM-test: Add a qemu-img commit test Lucas Meneghel Rodrigues
2010-12-22 4:05 ` tangchen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox