Skip to content

Commit

Permalink
Merge pull request #6200 from meinaLi/inc_backup
Browse files Browse the repository at this point in the history
Inc_backup: add datastore related test scenarios
  • Loading branch information
chunfuwen authored Mar 5, 2025
2 parents b6a8882 + 1491e96 commit b06add5
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
original_disk_size = "100M"
backup_data_size = "1M"
backup_rounds = 4
variants:
- without_datastore:
- with_datastore:
only blockcommit.top_to_base,blockpull.mid_to_top,blockcopy.reuse_external
with_data_file = "yes"
func_supported_since_libvirt_ver = (10, 10, 0)
data_file_option = " -o data_file=%s"
variants:
- scratch_to_file:
scratch_type = "file"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
start_vm = "no"
required_checkpoints = 1
status_error = "no"
variants:
- without_datastore:
- with_datastore:
only checkpoint-create
with_data_file = "yes"
func_supported_since_libvirt_ver = (10, 10, 0)
data_file_option = " -o data_file=%s"
variants checkpoint_cmd:
- checkpoint-create:
variants:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
start_vm = "no"
original_disk_size = "100M"
backup_data_size = "1M"
variants:
- without_datastore:
- with_datastore:
only scratch_luks_encrypted
with_data_file = "yes"
func_supported_since_libvirt_ver = (10, 10, 0)
data_file_option = " -o data_file=%s"
variants:
- nbd_unix:
nbd_protocol = "unix"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
test_disk_size = "100M"
backup_data_size = "1M"
total_test_disk = 3
variants:
- without_datastore:
- with_datastore:
with_data_file = "yes"
func_supported_since_libvirt_ver = (10, 10, 0)
data_file_option = " -o data_file=%s"
variants:
- custom_export_name:
set_export_name = "yes"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ def create_shutoff_snapshot(original_img, snapshot_img):
blockcopy_reuse = params.get("blockcopy_reuse")
backup_error = "yes" == params.get("backup_error")
tmp_dir = data_dir.get_tmp_dir()
with_data_file = "yes" == params.get("with_data_file", "no")
libvirt_version.is_libvirt_feature_supported(params)

try:
vm_name = params.get("main_vm")
Expand All @@ -217,8 +219,12 @@ def create_shutoff_snapshot(original_img, snapshot_img):
if original_disk_type == "local":
image_name = "%s_image.qcow2" % original_disk_target
disk_path = os.path.join(tmp_dir, image_name)
data_file = os.path.join(tmp_dir, "datastore")
if with_data_file:
data_file_option = params.get("data_file_option", "") % data_file
extra_cmd = "" if not with_data_file else data_file_option
libvirt.create_local_disk("file", disk_path, original_disk_size,
"qcow2")
"qcow2", extra=extra_cmd)
disk_params = {"device_type": "disk",
"type_name": "file",
"driver_type": "qcow2",
Expand All @@ -233,6 +239,11 @@ def create_shutoff_snapshot(original_img, snapshot_img):
virsh.attach_device(vm.name, disk_xml,
flagstr="--config", debug=True)
vm.start()
guest_xml = virsh.dumpxml(vm_name).stdout_text
logging.debug("The current guest xml is:%s" % guest_xml)
if with_data_file:
if data_file not in guest_xml:
test.fail("The datastore file xml can't be generated automatically in guest!")
session = vm.wait_for_login()
new_disks_in_vm = list(utils_disk.get_linux_disks(session).keys())
session.close()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ def prepare_checkpoints(disk="vdb", num=1, cp_prefix="test_checkpoint_"):
tmp_dir = data_dir.get_tmp_dir()
current_checkpoints = []
virsh_dargs = {'debug': True, 'ignore_status': False}
with_data_file = "yes" == params.get("with_data_file", "no")
libvirt_version.is_libvirt_feature_supported(params)

try:
vm_name = params.get("main_vm")
Expand All @@ -75,8 +77,12 @@ def prepare_checkpoints(disk="vdb", num=1, cp_prefix="test_checkpoint_"):
disk_path = ""
image_name = "{}_image.qcow2".format(test_disk_target)
disk_path = os.path.join(tmp_dir, image_name)
data_file = os.path.join(tmp_dir, "datastore")
if with_data_file:
data_file_option = params.get("data_file_option", "") % data_file
extra_cmd = "" if not with_data_file else data_file_option
libvirt.create_local_disk("file", disk_path, test_disk_size,
"qcow2")
"qcow2", extra=extra_cmd)
disk_params = {"device_type": "disk",
"type_name": "file",
"driver_type": "qcow2",
Expand All @@ -86,6 +92,11 @@ def prepare_checkpoints(disk="vdb", num=1, cp_prefix="test_checkpoint_"):
virsh.attach_device(vm.name, disk_xml,
flagstr="--config", **virsh_dargs)
vm.start()
guest_xml = virsh.dumpxml(vm_name).stdout_text
logging.debug("The current guest xml is:%s" % guest_xml)
if with_data_file:
if data_file not in guest_xml:
test.fail("The datastore file xml can't be generated automatically in guest!")
session = vm.wait_for_login()
new_disks_in_vm = list(utils_disk.get_linux_disks(session).keys())
session.close()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ def run(test, params, env):
usage_threshold = params.get("usage_threshold", "100")
tmp_dir = data_dir.get_tmp_dir()
local_hostname = params.get("loal_hostname", "localhost")
with_data_file = "yes" == params.get("with_data_file", "no")
libvirt_version.is_libvirt_feature_supported(params)
# Backup config
scratch_type = params.get("scratch_type", "file")
reuse_scratch_file = "yes" == params.get("reuse_scratch_file")
Expand Down Expand Up @@ -115,8 +117,12 @@ def is_event_captured(virsh_session, re_pattern):
disk_path = ""
image_name = "{}_image.qcow2".format(original_disk_target)
disk_path = os.path.join(tmp_dir, image_name)
data_file = os.path.join(tmp_dir, "datastore")
if with_data_file:
data_file_option = params.get("data_file_option", "") % data_file
extra_cmd = "" if not with_data_file else data_file_option
libvirt.create_local_disk("file", disk_path, original_disk_size,
"qcow2")
"qcow2", extra=extra_cmd)
disk_params = {"device_type": "disk",
"type_name": "file",
"driver_type": "qcow2",
Expand All @@ -127,6 +133,11 @@ def is_event_captured(virsh_session, re_pattern):
virsh.attach_device(vm.name, disk_xml,
flagstr="--config", debug=True)
vm.start()
guest_xml = virsh.dumpxml(vm_name).stdout_text
logging.debug("The current guest xml is:%s" % guest_xml)
if with_data_file:
if data_file not in guest_xml:
test.fail("The datastore file xml can't be generated automatically in guest!")
session = vm.wait_for_login()
new_disks_in_vm = list(utils_disk.get_linux_disks(session).keys())
session.close()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ def get_disks_need_backup(disk_dict):
total_test_disk = int(params.get("total_test_disk", 3))
tmp_dir = data_dir.get_tmp_dir()
backup_error = "yes" == params.get("backup_error")
with_data_file = "yes" == params.get("with_data_file", "no")
libvirt_version.is_libvirt_feature_supported(params)

# Backup setting
scratch_type = params.get("scratch_type", "file")
Expand Down Expand Up @@ -108,9 +110,13 @@ def prepare_disk_img(test_disk):
"""
image_name = "{}_image.qcow2".format(test_disk)
image_path = os.path.join(tmp_dir, image_name)
data_file = os.path.join(tmp_dir, test_disk)
if with_data_file:
data_file_option = params.get("data_file_option", "") % data_file
extra_cmd = "" if not with_data_file else data_file_option
libvirt.create_local_disk("file", image_path, test_disk_size,
"qcow2")
return image_path
"qcow2", extra=extra_cmd)
return image_path, data_file

def prepare_disk_xml(test_disk, image_path):
"""
Expand Down Expand Up @@ -209,14 +215,19 @@ def prepare_checkpoint_xml(backup_disks, all_vm_disks):
enable_incremental_backup = True
backup_params["backup_incremental"] = checkpoint_list[-1]
# Prepare disk image
image_path = prepare_disk_img(test_disk)
image_path, data_file = prepare_disk_img(test_disk)
# Prepare disk xml to be hotplugged
test_disk_xml = prepare_disk_xml(test_disk, image_path)
# Hotplug disk
virsh.attach_device(vm_name, test_disk_xml, debug=True,
ignore_status=False)
test_disk_dict[test_disk]['path'] = image_path
test_disk_dict[test_disk]['is_attached'] = True
guest_xml = virsh.dumpxml(vm_name).stdout_text
logging.debug("The current guest xml is:%s" % guest_xml)
if with_data_file:
if data_file not in guest_xml:
test.fail("The datastore file xml can't be generated automatically in guest!")
# Now we use attached disk as backup disks
backup_disks = get_disks_need_backup(test_disk_dict)
vmxml = vm_xml.VMXML.new_from_dumpxml(vm_name)
Expand Down

0 comments on commit b06add5

Please sign in to comment.