diff --git a/qemu/tests/cfg/qemu_disk_img.cfg b/qemu/tests/cfg/qemu_disk_img.cfg index b96a448700a2b02ca342ca423a597d78aafab3eb..53564d5701c95999d95cc677dae78cffd553ce31 100644 --- a/qemu/tests/cfg/qemu_disk_img.cfg +++ b/qemu/tests/cfg/qemu_disk_img.cfg @@ -36,3 +36,10 @@ image_format_sn1 = "qcow2" convert_name_sn1 = "images/sn1_to_qcow2" convert_format_sn1 = "qcow2" + - commit: + type = qemu_disk_img_commit + guest_file_name = /tmp/test.img + image_commit = "sn1" + image_chain += " sn1" + image_name_sn1 = "images/sn1" + image_format_sn1 = "qcow2" diff --git a/qemu/tests/qemu_disk_img_commit.py b/qemu/tests/qemu_disk_img_commit.py new file mode 100644 index 0000000000000000000000000000000000000000..969e1ab1d16db4c5b22f05ab70b4f55bdb813a9f --- /dev/null +++ b/qemu/tests/qemu_disk_img_commit.py @@ -0,0 +1,54 @@ +import logging +from autotest.client.shared import error +from qemu.tests import qemu_disk_img + + +class CommitTest(qemu_disk_img.QemuImgTest): + + def __init__(self, test, params, env): + self.tag = params.get("image_commit", "image1") + t_params = params.object_params(self.tag) + super(CommitTest, self).__init__(test, t_params, env, self.tag) + + @error.context_aware + def commit(self, t_params={}): + """ + commit snapshot to backing file; + """ + error.context("commit snapshot to backingfile", logging.info) + params = self.params.object_params(self.tag) + params.update(t_params) + cache_mode = params.get("cache_mode") + return super(CommitTest, self).commit(params, cache_mode) + +def run_qemu_disk_img_commit(test, params, env): + """ + 'qemu-img' commit functions test: + + @param test: Qemu test object + @param params: Dictionary with the test parameters + @param env: Dictionary with test environment. + """ + + base_image = params.get("images", "image1").split()[0] + params.update( + {"image_name_%s" % base_image: params["image_name"], + "image_format_%s" % base_image: params["image_format"]}) + t_file = params["guest_file_name"] + commit_test = CommitTest(test, params, env) + n_params = commit_test.create_snapshot() + commit_test.start_vm(n_params) + + # save file md5sum before commit + ret = commit_test.save_file(t_file) + if not ret: + raise error.TestError("Fail to save tmp file") + commit_test.destroy_vm() + commit_test.commit() + commit_test.start_vm(params) + + # check md5sum after commit + ret = commit_test.check_file(t_file) + if not ret: + raise error.TestError("image content changed after commit") + commit_test.clean()