def run(test, params, env): """ Test blockjob operation """ def setup_blockjob_raw(): """ Prepare running domain and do blockcopy """ if not vm.is_alive(): vm.start() if os.path.exists(tmp_copy_path): process.run('rm -rf %s' % tmp_copy_path) cmd = "blockcopy %s %s %s --wait --verbose --transient-job " \ "--bandwidth 1000 " % (vm_name, dev, tmp_copy_path) virsh_session = virsh.VirshSession(virsh_exec=virsh.VIRSH_EXEC, auto_close=True) virsh_session.sendline(cmd) def test_blockjob_raw(): """ Do blockjob with raw option. 1) Prepare a running guest. 2) Do blockcopy. 3) Do blockjob with raw option twice and check cur value is changing 4) Execute with --pivot and check raw option return empty """ options = params.get('option_value', '') # Confirm blockcopy not finished. if not libvirt.check_blockjob(vm_name, dev, "progress", "100"): res_1 = virsh.blockjob(vm_name, dev, options=options, debug=True, ignore_status=False) cur1 = libvirt_misc.convert_to_dict(res_1.stdout_text.strip(), pattern=r'(\S+)=(\S+)')['cur'] time.sleep(1) res_2 = virsh.blockjob(vm_name, dev, options=options, debug=True, ignore_status=False) cur2 = libvirt_misc.convert_to_dict(res_2.stdout_text.strip(), pattern=r'(\S+)=(\S+)')['cur'] LOG.debug('cur1 is %s , cur2 is %s', cur1, cur2) if int(cur1) >= int(cur2): test.fail('Two times cur value is not changed according' ' to the progress of blockcopy.') # Abort job and check abort success. if utils_misc.wait_for( lambda: libvirt.check_blockjob(vm_name, dev, "progress", "100"), 100): virsh.blockjob(vm_name, dev, options=' --pivot', debug=True, ignore_status=False) else: test.fail("Blockjob timeout in 100 sec.") # Check no output after abort. result = virsh.blockjob(vm_name, dev, options=options, debug=True, ignore_status=False) if result.stdout_text.strip(): test.fail("Not return empty after pivot, but get:%s", result.stdout_text.strip()) else: test.error( 'Blockcopy finished too fast, unable to check raw result,\ Please consider to reduce bandwith value to retest this case.') def teardown_blockjob_raw(): """ After blockcopy, clean file """ # If some steps are broken by accident, execute --abort to # stop blockcopy job virsh.blockjob(vm_name, dev, options=' --abort', debug=True, ignore_status=True) # Clean copy file process.run('rm -rf %s' % tmp_copy_path) # Process cartesian parameters vm_name = params.get("main_vm") vm = env.get_vm(vm_name) case_name = params.get('case_name', 'blockjob') dev = params.get('disk') # Create object test_obj = blockcommand_base.BlockCommand(test, vm, params) check_obj = check_functions.Checkfunction(test, vm, params) vmxml = vm_xml.VMXML.new_from_inactive_dumpxml(vm_name) bkxml = vmxml.copy() tmp_copy_path = os.path.join( os.path.dirname(libvirt_disk.get_first_disk_source(vm)), "%s_blockcopy.img" % vm_name) # MAIN TEST CODE ### run_test = eval("test_%s" % case_name) setup_test = eval("setup_%s" % case_name) teardown_test = eval("teardown_%s" % case_name) try: # Execute test setup_test() run_test() finally: teardown_test() bkxml.sync()
def run(test, params, env): """ Case for RHEL-288322 Test blockcommit operation after creating disk-only snapshot. 1) Prepare block type disk and snap chain 2) Test blockcommit operation from top to base. 3) Check result. """ def setup_commit_top_to_base(): """ Prepare specific type disk and create snapshots. """ test_obj.update_disk() test_obj.prepare_snapshot() check_obj.check_backingchain(test_obj.snap_path_list[::-1]) def test_commit_top_to_base(): """ Do blockcommit from top to base after creating external disk-only snapshot with specific disk type """ commit_options = " --top %s --pivot " % (test_obj.snap_path_list[-1]) virsh.blockcommit(vm.name, test_obj.new_dev, commit_options, ignore_status=False, debug=True) # Check result after block commit vmxml = vm_xml.VMXML.new_from_inactive_dumpxml(vm.name) check_obj.check_block_operation_result( vmxml, 'blockcommit', test_obj.new_dev, test_obj.snap_path_list[::-1] + [test_obj.src_path]) def teardown_commit_top_to_base(): """ Clean data. """ LOG.info('Start cleaning up.') for ss in test_obj.snap_name_list: virsh.snapshot_delete(vm_name, '%s --metadata' % ss, debug=True) for sp in test_obj.snap_path_list: process.run('rm -rf %s' % sp) bkxml.sync() libvirt.setup_or_cleanup_iscsi(is_setup=False) # Process cartesian parameters vm_name = params.get("main_vm") vm = env.get_vm(vm_name) case_name = params.get('case_name', '') vmxml = vm_xml.VMXML.new_from_inactive_dumpxml(vm_name) bkxml = vmxml.copy() # Create object test_obj = blockcommand_base.BlockCommand(test, vm, params) check_obj = check_functions.Checkfunction(test, vm, params) # MAIN TEST CODE ### run_test = eval("test_%s" % case_name) setup_test = eval("setup_%s" % case_name) teardown_test = eval("teardown_%s" % case_name) try: # Execute test setup_test() run_test() finally: teardown_test()
def run(test, params, env): """ Test domblkthreshold for domain which has backing chain """ def setup_domblkthreshold_inactivate_layer(): """ Prepare backingchain """ if not vm.is_alive(): vm.start() vm.wait_for_login().close() test_obj.prepare_snapshot(snap_num=1) def test_domblkthreshold_inactivate_layer(): """ Do domblkthreshold for a device which is not the active layer image """ # Get backingstore index value and set domblkthreshold bs_index = '' vmxml = vm_xml.VMXML.new_from_dumpxml(vm_name) for disk in vmxml.devices.by_device_tag('disk'): if disk.target['dev'] == primary_target: bs_index = disk.xmltreefile.find('backingStore').get('index') virsh.domblkthreshold(vm_name, '%s[%s]' % (primary_target, bs_index), domblk_threshold, debug=True, ignore_status=False) # Create some data in active layer image session = vm.wait_for_login() utils_disk.dd_data_to_vm_disk(session, '/tmp/file', bs='1M', count='100') session.close() # Check blockcommit will trigger threshold event event = r"\'block-threshold\' for domain .*%s.*: dev: %s\[%s\].*%s.*" \ % (vm_name, primary_target, bs_index, domblk_threshold) LOG.debug('Checking event pattern is :%s ', event) event_session = virsh.EventTracker.start_get_event(vm_name) virsh.blockcommit(vm.name, primary_target, commit_options, ignore_status=False, debug=True) event_output = virsh.EventTracker.finish_get_event(event_session) if not re.search(event, event_output): test.fail('Not find: %s from event output:%s' % (event, event_output)) def teardown_domblkthreshold_inactivate_layer(): """ Clean env """ test_obj.backingchain_common_teardown() process.run('rm -f %s' % test_obj.new_image_path) # Process cartesian parameters vm_name = params.get("main_vm") vm = env.get_vm(vm_name) case_name = params.get('case_name', '') domblk_threshold = params.get('domblk_threshold') commit_options = params.get('commit_options') test_obj = blockcommand_base.BlockCommand(test, vm, params) vmxml = vm_xml.VMXML.new_from_inactive_dumpxml(vm_name) bkxml = vmxml.copy() primary_target = vm.get_first_disk_devices()["target"] test_obj.new_dev = primary_target test_obj.original_disk_source = libvirt_disk.get_first_disk_source(vm) run_test = eval("test_%s" % case_name) setup_test = eval("setup_%s" % case_name) teardown_test = eval("teardown_%s" % case_name) try: # Execute test setup_test() run_test() finally: teardown_test() bkxml.sync()
def run(test, params, env): """ Test blockcopy with different options. 1) Prepare an running guest. 2) Create snap. 3) Do blockcopy. 4) Check status by 'qemu-img info'. """ def setup_blockcopy_extended_l2(): """ Prepare running domain with extended_l2=on type image. """ # prepare image image_path = test_obj.tmp_dir + '/new_image' libvirt.create_local_disk("file", path=image_path, size='500M', disk_format=disk_format, extra=disk_extras) check_obj.check_image_info(image_path, check_item='extended l2', expected_value='true') test_obj.new_image_path = image_path # start get old parts session = vm.wait_for_login() test_obj.old_parts = utils_disk.get_parts_list(session) session.close() # attach new disk if encryption_disk: secret_disk_dict = eval(params.get("secret_disk_dict", '{}')) test_obj.prepare_secret_disk(image_path, secret_disk_dict) if not vm.is_alive(): vm.start() else: virsh.attach_disk(vm.name, source=image_path, target=device, extra=attach_disk_extra, debug=True, ignore_status=False) test_obj.new_dev = device # clean copy file if os.path.exists(tmp_copy_path): process.run('rm -f %s' % tmp_copy_path) def test_blockcopy_extended_l2(): """ Do blockcopy after creating snapshot with extended_l2 in disk image """ # create snap chain and check snap path extended_l2 status test_obj.prepare_snapshot(snap_num=1) check_obj.check_image_info(test_obj.snap_path_list[0], check_item='extended l2', expected_value='true') # Do blockcopy virsh.blockcopy(vm_name, device, tmp_copy_path, options=blockcopy_options, ignore_status=False, debug=True) # Check domain exist blockcopy file and extended_l2 status if len(vmxml.get_disk_source(vm_name)) < 2: test.fail('Domain disk num is less than 2, may attach failed') else: image_file = vmxml.get_disk_source(vm_name)[1].find('source').get( 'file') if image_file != tmp_copy_path: test.fail( 'Blockcopy path is not in domain disk ,' ' blockcopy image path is %s ,actual image path ' 'is :%s', tmp_copy_path, image_file) check_obj.check_image_info(tmp_copy_path, check_item='extended l2', expected_value='true') # Check domain write file session = vm.wait_for_login() new_parts = utils_disk.get_parts_list(session) added_parts = list(set(new_parts).difference(set(test_obj.old_parts))) utils_disk.linux_disk_check(session, added_parts[0]) session.close() def teardown_blockcopy_extended_l2(): """ Clean env. """ if encryption_disk: libvirt_secret.clean_up_secrets() test_obj.backingchain_common_teardown() # detach disk virsh.detach_disk(vm_name, target=device, wait_for_event=True, debug=True) process.run('rm -f %s' % test_obj.new_image_path) def setup_blockcopy_synchronous_writes(): """ Start domain and clean exist copy file """ if not vm.is_alive(): vm.start() if os.path.exists(tmp_copy_path): process.run('rm -f %s' % tmp_copy_path) def test_blockcopy_synchronous_writes(): """ Test blockcopy with --synchronous-writes option. """ ret = virsh.blockcopy(vm_name, device, tmp_copy_path, options=blockcopy_options, ignore_status=False, debug=True) if not ret.stdout_text.count("Now in mirroring phase"): test.fail("Not in mirroring phase") test_obj.new_image_path = tmp_copy_path # Check exist mirror tag after blockcopy. vmxml = vm_xml.VMXML.new_from_dumpxml(vm.name) disk_list = vmxml.get_disk_all()[device] if not disk_list.find('mirror'): test.fail('No mirror tag in current domain xml :%s' % vmxml) else: # Check file in mirror should be new copy file mirror_file = disk_list.find('mirror').get('file') if mirror_file != tmp_copy_path: test.fail('Current mirror tag file:%s is not same as:%s' % (mirror_file, tmp_copy_path)) # Check file in mirror >source > file should be new copy file mirror_source_file = disk_list.find('mirror').\ find('source').get('file') if mirror_source_file != tmp_copy_path: test.fail('Current source tag file:%s is not same as:%s' % (mirror_source_file, tmp_copy_path)) # Check domain write file session = vm.wait_for_login() utils_disk.dd_data_to_vm_disk(session, device) session.close() # Abort job and check disk source changed. virsh.blockjob(vm_name, device, options=' --pivot', debug=True, ignore_status=False) current_source = libvirt_disk.get_first_disk_source(vm) if current_source != tmp_copy_path: test.fail("Current source: %s is not same as original blockcopy" " path:%s" % (current_source, tmp_copy_path)) # Check domain write file after session = vm.wait_for_login() utils_disk.dd_data_to_vm_disk(session, device) session.close() def teardown_blockcopy_synchronous_writes(): """ Clean env """ if os.path.exists(test_obj.new_image_path): process.run('rm -f %s' % test_obj.new_image_path) libvirt_version.is_libvirt_feature_supported(params) # Process cartesian parameters vm_name = params.get("main_vm") vm = env.get_vm(vm_name) case_name = params.get('case_name', '') device = params.get('target_disk') disk_extras = params.get('extras_options') blockcopy_options = params.get('blockcopy_option') attach_disk_extra = params.get("attach_disk_options") encryption_disk = params.get('enable_encrypt_disk', 'no') == "yes" disk_format = params.get('disk_format', 'qcow2') # Create object test_obj = blockcommand_base.BlockCommand(test, vm, params) check_obj = check_functions.Checkfunction(test, vm, params) # Get vm xml vmxml = vm_xml.VMXML.new_from_inactive_dumpxml(vm_name) bkxml = vmxml.copy() test_obj.original_disk_source = libvirt_disk.get_first_disk_source(vm) tmp_copy_path = os.path.join( os.path.dirname(libvirt_disk.get_first_disk_source(vm)), "%s_blockcopy.img" % vm_name) # MAIN TEST CODE ### run_test = eval("test_%s" % case_name) setup_test = eval("setup_%s" % case_name) teardown_test = eval("teardown_%s" % case_name) try: # Execute test setup_test() run_test() finally: teardown_test() bkxml.sync()
def run(test, params, env): """ Test blockresize for domain which has backing chain element. """ def setup_raw_disk_blockresize(): """ Prepare raw disk and create snapshots. """ if not vm.is_alive(): vm.start() vm.wait_for_login().close() # Create raw type image image_path = test_obj.tmp_dir + '/blockresize_test' libvirt.create_local_disk("file", path=image_path, size='500K', disk_format="raw") test_obj.new_image_path = image_path # attach new disk virsh.attach_disk(vm.name, source=image_path, target=device, extra=extra, debug=True) test_obj.new_dev = device # create snap chain test_obj.prepare_snapshot() def test_raw_disk_blockresize(): """ Test blockresize for raw type device which has backing chain element. """ new_size = params.get('expected_block_size') result = virsh.blockresize(vm_name, test_obj.snap_path_list[-1], new_size, debug=True) libvirt.check_exit_status(result) check_obj.check_image_info(test_obj.snap_path_list[-1], 'vsize', new_size) def teardown_raw_disk_blockresize(): """ Clean env and resize with origin size. """ # clean new disk file test_obj.backingchain_common_teardown() # detach disk virsh.detach_disk(vm_name, target=test_obj.new_dev, wait_for_event=True, debug=True) # clean image file process.run('rm -f %s' % test_obj.new_image_path) # Process cartesian parameters vm_name = params.get("main_vm") vm = env.get_vm(vm_name) case_name = params.get('case_name', '') device = params.get('new_disk') extra = params.get('attach_disk_extra_options') # Create object test_obj = blockcommand_base.BlockCommand(test, vm, params) check_obj = check_functions.Checkfunction(test, vm, params) # Get vm xml vmxml = vm_xml.VMXML.new_from_inactive_dumpxml(vm_name) bkxml = vmxml.copy() test_obj.original_disk_source = libvirt_disk.get_first_disk_source(vm) # MAIN TEST CODE ### run_test = eval("test_%s" % case_name) setup_test = eval("setup_%s" % case_name) teardown_test = eval("teardown_%s" % case_name) try: # Execute test setup_test() run_test() finally: teardown_test() bkxml.sync()