未验证 提交 1e2f73d9 编写于 作者: X Xu Tian 提交者: GitHub

Merge pull request #2091 from aliang123/1802028

Snapshot on multi_disks under transaction mode
......@@ -94,6 +94,16 @@ def verify_file_md5(vm, root_dir, filename, timeout=720):
session.close()
def blockdev_snapshot_qmp_cmd(source, target, **extra_options):
options = [
"node",
"overlay"]
arguments = copy_out_dict_if_exists(extra_options, options)
arguments["node"] = source
arguments["overlay"] = target
return "blockdev-snapshot", arguments
def blockdev_mirror_qmp_cmd(source, target, **extra_options):
random_id = utils_misc.generate_random_string(4)
job_id = "%s_%s" % (source, random_id)
......@@ -184,6 +194,14 @@ def blockdev_create(vm, **options):
job_utils.job_dismiss(vm, options["job-id"], timeout)
@fail_on
def blockdev_snapshot(vm, source, target, **extra_options):
cmd, arguments = blockdev_snapshot_qmp_cmd(source, target, **extra_options)
timeout = int(extra_options.pop("timeout", 600))
vm.monitor.cmd(cmd, arguments)
job_utils.wait_until_block_job_completed(vm, timeout)
@fail_on
def blockdev_mirror(vm, source, target, **extra_options):
cmd, arguments = blockdev_mirror_qmp_cmd(source, target, **extra_options)
......@@ -228,6 +246,20 @@ def blockdev_backup(vm, source, target, **extra_options):
job_utils.wait_until_block_job_completed(vm, job_id, timeout)
@fail_on
def blockdev_batch_snapshot(vm, source_lst, target_lst, **extra_options):
actions = []
timeout = int(extra_options.pop("timeout", 600))
jobs_id = []
for idx, src in enumerate(source_lst):
snapshot_cmd, arguments = blockdev_snapshot_qmp_cmd(
src, target_lst[idx], **extra_options)
actions.append({"type": snapshot_cmd, "data": arguments})
arguments = {"actions": actions}
vm.monitor.cmd("transaction", arguments)
list(map(lambda x: job_utils.wait_until_block_job_completed(vm, x, timeout), jobs_id))
@fail_on
def blockdev_batch_backup(vm, source_lst, target_lst,
bitmap_lst, **extra_options):
......
import logging
from virttest import data_dir
from virttest import utils_disk
from virttest import error_context
from provider import backup_utils
from provider.virt_storage.storage_admin import sp_admin
from provider.blockdev_snapshot_base import BlockDevSnapshotTest
class BlockdevSnapshotMultiDisksTest(BlockDevSnapshotTest):
def __init__(self, test, params, env):
self.source_disks = params["source_disks"].split()
self.target_disks = params["target_disks"].split()
self.snapshot_tag_list = params["snapshot_tag"].split()
self.base_tag_list = params["base_tag"].split()
super(BlockdevSnapshotMultiDisksTest, self).__init__(test, params, env)
def prepare_clone_vm(self):
vm_params = self.main_vm.params.copy()
for snapshot_tag, base_tag in zip(self.snapshot_tag_list,
self.base_tag_list):
images = self.main_vm.params["images"].replace(
self.base_tag, self.snapshot_tag)
vm_params["images"] = images
return self.main_vm.clone(params=vm_params)
def configure_data_disk(self):
os_type = self.params["os_type"]
for snapshot_tag in self.snapshot_tag_list:
disk_params = self.params.object_params(snapshot_tag)
disk_size = disk_params["image_size"]
session = self.main_vm.wait_for_login()
try:
if os_type != "windows":
disk_id = self.get_linux_disk_path(session, disk_size)
assert disk_id, "Disk not found in guest!"
mount_point = utils_disk.configure_empty_linux_disk(
session, disk_id, disk_size)[0]
self.disks_info.append([
r"/dev/%s1" %
disk_id, mount_point])
else:
disk_id = utils_disk.get_windows_disks_index(
session, disk_size)
driver_letter = utils_disk.configure_empty_windows_disk(
session, disk_id, disk_size)[0]
mount_point = r"%s:\\" % driver_letter
self.disks_info.append([disk_id, mount_point])
finally:
session.close()
def prepare_snapshot_file(self):
for snapshot_tag in self.snapshot_tag_list:
if self.is_blockdev_mode():
params = self.params.copy()
params.setdefault("target_path", data_dir.get_data_dir())
image = sp_admin.volume_define_by_params(snapshot_tag, params)
image.hotplug(self.main_vm)
else:
if self.params.get("mode") == "existing":
snapshot_image = self.get_image_by_tag(snapshot_tag)
snapshot_image.create()
@error_context.context_aware
def create_snapshot(self):
error_context.context("do snaoshot on multi_disks",
logging.info)
assert len(
self.target_disks) == len(
self.source_disks), "No enough target disks define in cfg!"
source_lst = list(map(lambda x: "drive_%s" % x, self.source_disks))
target_lst = list(map(lambda x: "drive_%s" % x, self.target_disks))
arguments = {}
if len(source_lst) > 1:
error_context.context(
"snapshot %s to %s " % (source_lst, target_lst))
backup_utils.blockdev_batch_snapshot(
self.main_vm, source_lst, target_lst, **arguments)
else:
error_context.context(
"snapshot %s to %s" %
(source_lst[0], target_lst[0]))
backup_utils.blockdev_snapshot(
self.main_vm,
source_lst[0],
target_lst[0])
def verify_snapshot(self):
if self.main_vm.is_alive():
self.main_vm.destroy()
for snapshot_tag, base_tag in zip(self.snapshot_tag_list,
self.base_tag_list):
if self.is_blockdev_mode():
snapshot_image = self.get_image_by_tag(snapshot_tag)
base_image = self.get_image_by_tag(base_tag)
snapshot_image.base_tag = base_tag
snapshot_image.base_format = base_image.get_format()
base_image_filename = base_image.image_filename
snapshot_image.base_image_filename = base_image_filename
snapshot_image.rebase(snapshot_image.params)
self.clone_vm.create()
self.clone_vm.verify_alive()
if self.base_tag != "image1":
self.mount_data_disks()
self.verify_data_file()
def post_test(self):
try:
self.clone_vm.destroy()
for snapshot_tag in self.snapshot_tag_list:
snapshot_image = self.get_image_by_tag(snapshot_tag)
snapshot_image.remove()
except Exception as error:
logging.error(str(error))
def run(test, params, env):
"""
Backup VM disk test when VM reboot
1) start VM with two data disks
2) create target disks with qmp command
3) format data disks in guest
4) do snapshot to target disks in transaction mode
5) dd file on data disks
6) shutdown VM
7) boot VM with target disks
:param test: 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"]})
snapshot_multi_disks = BlockdevSnapshotMultiDisksTest(test, params, env)
snapshot_multi_disks.run_test()
- blockdev_snapshot_multi_disks:
type = blockdev_snapshot_multi_disks
virt_test_type = qemu
start_vm = yes
storage_type_default = "directory"
storage_pool = default
images += " data1 data2"
image_size_data1 = 500M
image_name_data1 = "images/data1"
image_size_sn1 = 500M
image_name_sn1 = "sn1"
image_format_sn1 = qcow2
force_create_image = yes
force_remove_image = yes
image_size_data2 = 400M
image_name_data2 = "images/data2"
image_size_sn2 = 400M
image_name_sn2 = "sn2"
image_format_sn2 = qcow2
force_remove_image_image1 = no
force_create_image_image1 = no
source_disks = data1 data2
target_disks = sn1 sn2
rebase_mode = unsafe
snapshot_tag = sn1 sn2
base_tag = data1 data2
image_format_sn1 = qcow2
image_name_sn1 = images/sn1
image_name_sn2 = images/sn2
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册