提交 a7b577cd 编写于 作者: X Xu Tian

add blockdev inc backup test

Signed-off-by: NXu Tian <xutian@redhat.com>
上级 3ea64f2f
import logging
from functools import partial
from avocado.utils import memory
from virttest import utils_misc
from provider import backup_utils
from provider import blockdev_base
class BlockdevIncreamentalBackupTest(blockdev_base.BlockdevBaseTest):
def __init__(self, test, params, env):
super(BlockdevIncreamentalBackupTest, self).__init__(test, params, env)
self.source_images = []
self.full_backups = []
self.inc_backups = []
self.bitmaps = []
self.rebase_targets = []
for tag in params.objects('source_images'):
image_params = params.object_params(tag)
image_chain = image_params.objects("image_chain")
self.source_images.append("drive_%s" % tag)
self.full_backups.append("drive_%s" % image_chain[0])
self.inc_backups.append("drive_%s" % image_chain[1])
self.bitmaps.append("bitmap_%s" % tag)
inc_img_tag = image_chain[-1]
inc_img_params = params.object_params(inc_img_tag)
inc_img_params['image_chain'] = image_params['image_chain']
inc_img = self.source_disk_define_by_params(
inc_img_params, inc_img_tag)
target_func = partial(inc_img.rebase, params=inc_img_params)
self.rebase_targets.append(target_func)
def get_granularity(self):
granularity = self.params.get('granularity')
if granularity == 'random':
blacklist = self.params.objects('granularity_blacklist')
granularity = backup_utils.generate_log2_value(
512, 2147483648, 1, blacklist)
return granularity
def do_full_backup(self):
extra_options = {"sync": "full", "auto_disable_bitmap": False}
if self.params.get('auto_dismiss') == 'no':
extra_options['auto_dismiss'] = False
extra_options['auto_finalize'] = False
granularity = self.get_granularity()
if granularity is not None:
extra_options['granularity'] = granularity
logging.info("bitmap granularity is '%s' " % granularity)
backup_utils.blockdev_batch_backup(
self.main_vm,
self.source_images,
self.full_backups,
self.bitmaps,
**extra_options)
def generate_inc_files(self):
for tag in self.params.objects("source_images"):
self.generate_data_file(tag)
def do_increamental_backup(self):
extra_options = {'sync': 'incremental', 'auto_disable_bitmap': False}
if self.params.get("completion_mode") == 'grouped':
extra_options['completion_mode'] = 'grouped'
if self.params.get('negative_test') == 'yes':
try:
backup_utils.blockdev_batch_backup(
self.main_vm,
self.source_images,
self.inc_backups,
self.bitmaps,
**extra_options)
except AssertionError:
return
self.test.fail('expect incremental backup job(s) failed')
else:
backup_utils.blockdev_batch_backup(
self.main_vm,
self.source_images,
self.inc_backups,
self.bitmaps,
**extra_options)
def rebase_target_disk(self):
return utils_misc.parallel(self.rebase_targets)
def prepare_clone_vm(self):
self.main_vm.destroy()
images = self.params["images"]
clone_params = self.main_vm.params.copy()
for tag in self.params.objects("source_images"):
img_params = self.params.object_params(tag)
image_chain = img_params.objects('image_chain')
images = images.replace(tag, image_chain[-1])
clone_params["images"] = images
clone_vm = self.main_vm.clone(params=clone_params)
clone_vm.create()
clone_vm.verify_alive()
self.clone_vm = clone_vm
def do_test(self):
self.do_full_backup()
self.generate_inc_files()
self.do_increamental_backup()
if self.params.get("negative_test") == "yes":
return
self.main_vm.destroy()
self.rebase_target_disk()
memory.drop_caches()
self.verify_target_disk()
def verify_target_disk(self):
self.prepare_clone_vm()
try:
self.verify_data_files()
finally:
self.clone_vm.destroy()
def run(test, params, env):
"""
Blockdev increamental backup test
test steps:
1. boot VM with one or two data disks
2. make filesystem in data disks
3. create file and save it md5sum in data disks
4. add target disks for backup to VM via qmp commands
5. do full backup
6. create new files and save it md5sum in data disks
7. do increamental backup
8. destroy VM and rebase increamental backup image
9. start VM with image in step8
10. verify files in data disks not change
:param test: test object
:param params: test configuration dict
:param env: env object
"""
inc_test = BlockdevIncreamentalBackupTest(test, params, env)
inc_test.run_test()
- blockdev_inc_backup:
type = blockdev_inc_backup_test
virt_test_type = qemu
images += " data"
image_chain_data = "base inc"
force_remove_image_image1 = no
force_create_image_image1 = no
force_create_image_data = yes
force_remove_image_data = yes
start_vm = no
storage_pools = default
storage_pool = default
storage_type_default = "directory"
image_size_data = 2G
image_size_base = 2G
image_size_inc = 2G
image_format_data = qcow2
image_format_base = qcow2
image_format_inc = qcow2
image_name_data = data
image_name_base = base
image_name_inc = inc
source_images = "data"
rebase_mode = unsafe
only Linux
qemu_force_use_drive_expression = no
variants:
- @one_data_disk:
variants:
- granularity_512:
granularity = 512
- granularity_8K:
granularity = 8192
- granularity_16M:
granularity = 16777216
- granularity_64M:
granularity = 67108864
- granularity_2G:
granularity = 2147483648
- granularity_random:
granularity = random
granularity_blacklist = "512 8192 16777216 67108864 2147483648"
- @granularity_default:
- multi_data_disks:
images += " data2"
image_chain_data2 = "base2 inc2"
force_create_image_data2 = yes
force_remove_image_data2 = yes
image_size_data2 = 3G
image_size_base2 = 3G
image_size_inc2 = 3G
image_format_data2 = qcow2
image_format_base2 = qcow2
image_format_inc2 = qcow2
image_name_data2 = data2
image_name_base2 = base2
image_name_inc2 = inc2
source_images += " data2"
variants:
- @default_complete:
- grouped_complete:
completion_mode = grouped
variants:
- @postive_test:
- negative_test:
# ensure created tmpfile big that incremental backup image
# and tmpfile size less than image size
image_size_inc2 = 1G
tempfile_size_data2 = 1280M
create_tempfile_timeout = 900
only auto_complete
variants:
- @auto_complete:
- manual_complete:
auto_dismiss = no
auto_finalize = no
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册