Skip to content

Commit

Permalink
Merge pull request autotest#3484 from nanli1/add_support_for_blockcom…
Browse files Browse the repository at this point in the history
…mit_relative_path_case

add support for blockcommit relative path case
  • Loading branch information
Yingshun authored Aug 22, 2022
2 parents 7322ff5 + ffe1f3c commit fe971b5
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions virttest/utils_libvirt/libvirt_disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def create_reuse_external_snapshots(vm, pre_set_root_dir=None, skip_first_one=Fa


def make_syslink_path_backing_files(pre_set_root_dir, volume_path_list, origin_image_format="qcow2",
created_image_format="qcow2", syslink_back_chain_lenghth=4):
created_image_format="qcow2", syslink_back_chain_lenghth=4, qemu_rebase=False):
"""
Create backing chain files of syslink path for one image
Expand All @@ -281,6 +281,7 @@ def make_syslink_path_backing_files(pre_set_root_dir, volume_path_list, origin_i
:param origin_image_format: original image format
:param created_image_format: created image format
:param syslink_back_chain_lenghth: syslink back chain length
:param qemu_rebase: execute qemu-img rebase to create backing file if True
:return: absolute path of top active file and syslink back chain files list
"""
root_dir = pre_set_root_dir
Expand All @@ -300,43 +301,52 @@ def make_syslink_path_backing_files(pre_set_root_dir, volume_path_list, origin_i
backing_key = syslink_folder_list[index-1]
backing_files_dict[key] = "../%s/%s.img" % (backing_key, backing_key)
backing_file_path = _execute_create_backend_file(backing_files_dict, pre_set_root_dir,
origin_image_format, created_image_format)
origin_image_format, created_image_format, qemu_rebase=qemu_rebase)
return os.path.join(backing_file_path, "%s.img" % syslink_folder_list[-1]), list(backing_files_dict.values())


def _execute_create_backend_file(backing_files_dict, pre_set_root_dir, origin_image_format, created_image_format):
def _execute_create_backend_file(backing_files_dict, pre_set_root_dir,
origin_image_format, created_image_format,
qemu_rebase=False):
"""
Execute create backing chain files
:param backing_files_dict: backing chain files
:param pre_set_root_dir: preset root dir
:param origin_image_format: original image format
:param created_image_format: created image format
:param qemu_rebase: execute qemu-img rebase to create backing file if True
:return: backing file path
"""
root_dir = pre_set_root_dir
disk_format = origin_image_format
for key, value in list(backing_files_dict.items()):
backing_file_path = os.path.join(root_dir, key)
cmd = ("cd %s && qemu-img create -f %s -o backing_file=%s,backing_fmt=%s %s.img"
% (backing_file_path, created_image_format, value, disk_format, key))
if qemu_rebase:
cmd = ("cd %s && qemu-img rebase -f %s -u -b %s -F %s %s"
% (backing_file_path, created_image_format, value, disk_format, key + ".img"))
else:
cmd = ("cd %s && qemu-img create -f %s -o backing_file=%s,backing_fmt=%s %s.img" % (
backing_file_path, created_image_format, value, disk_format, key))

process.run(cmd, shell=True, ignore_status=False)
disk_format = created_image_format
return backing_file_path


def do_blockcommit_repeatedly(vm, device_target, options, repeated_counts):
def do_blockcommit_repeatedly(vm, device_target, options, repeated_counts, **dargs):
"""
Do blockcommit repeatedly
:param vm: VM instance
:param device_target: device target
:param options: blockcommit options
:param repeated_counts: repeated counts for executing blockcommit
:param dargs: standardized virsh function API keywords
"""
for count in range(repeated_counts):
virsh.blockcommit(vm.name, device_target,
options, ignore_status=False, debug=True)
options, ignore_status=False, debug=True, **dargs)


def make_external_disk_snapshots(vm, device_target, postfix_n, snapshot_take):
Expand Down

0 comments on commit fe971b5

Please sign in to comment.