def test(): global test_obj_dict, VOL_OPS, VM_STATE_OPS, utility_vm, backup ps = res_ops.query_resource(res_ops.PRIMARY_STORAGE)[0] vm_name = "test_vm" utility_vm_name = "utility_vm" cond = res_ops.gen_query_conditions("system", '=', "false") cond = res_ops.gen_query_conditions("mediaType", '=', "RootVolumeTemplate", cond) cond = res_ops.gen_query_conditions("platform", '=', "Linux", cond) img_name = res_ops.query_resource(res_ops.IMAGE, cond)[0].name cond = res_ops.gen_query_conditions("category", '=', "Private") l3_name = res_ops.query_resource(res_ops.L3_NETWORK, cond)[0].name disk_offering = test_lib.lib_get_disk_offering_by_name( os.environ.get('smallDiskOfferingName')) disk_offering_uuids = [disk_offering.uuid] vm = test_stub.create_vm(vm_name, img_name, l3_name, disk_offering_uuids=disk_offering_uuids) utility_vm = test_stub.create_vm(utility_vm_name, img_name, l3_name) dvol = zstack_volume_header.ZstackTestVolume() dvol.set_volume(test_lib.lib_get_data_volumes(vm.get_vm())[0]) dvol.set_state(volume_header.ATTACHED) dvol.set_target_vm(vm) while True: OPS = VOL_OPS + VM_STATE_OPS if not backup_list: OPS.remove("VM_TEST_BACKUP_IMAGE") dvol = zstack_volume_header.ZstackTestVolume() dvol.set_volume(test_lib.lib_get_data_volumes(vm.get_vm())[0]) dvol.set_state(volume_header.ATTACHED) dvol.set_target_vm(vm) vm_op_test(vm, dvol, random.choice(OPS)) if vm.state == "Stopped": if backup_list: vm_op_test(vm, dvol, "VM_TEST_REVERT_BACKUP") vm.start() if test_lib.lib_is_vm_l3_has_vr(vm.vm): test_lib.TestHarness = test_lib.TestHarnessVR time.sleep(60) cmd = "dd if=/dev/urandom of=/dev/vdb bs=512k count=1" test_lib.lib_execute_command_in_vm(vm.vm, cmd) vm.suspend() vm_op_test(vm, dvol, "DVOL_BACKUP") compare(ps, vm, dvol, backup) vm.resume()
def test(): test_util.test_dsc('Create test vm and check') vm = test_stub.create_vlan_vm() test_obj_dict.add_vm(vm) vm.stop() r_volume = zstack_volume_header.ZstackTestVolume() r_volume.set_volume(test_lib.lib_get_root_volume(vm.get_vm())) r_volume.set_state(volume_header.ATTACHED) test_util.test_dsc('Create volume template and check') bs_list = test_lib.lib_get_backup_storage_list_by_vm(vm.get_vm()) vol_tmpt = r_volume.create_template([bs_list[0].uuid], 'new_data_template') test_obj_dict.add_image(vol_tmpt) test_util.test_dsc('Try to use data vol_tempt to Create VM. ') vm_option = vm.get_creation_option() vm_option.set_image_uuid(vol_tmpt.get_image().uuid) vm2 = zstack_vm_header.ZstackTestVm() vm2.set_creation_option(vm_option) try: vm2.create() except: test_util.test_logger('Expected exception, when creating VM by using Data Volume Template as root image') else: test_util.test_fail('VM can use data volume template to create VM') vol_tmpt.delete() test_obj_dict.rm_image(vol_tmpt) vm.destroy() test_util.test_pass('Create VM from Data Volume Template Test Success')
def create_data_volume(self, name=None, ps_uuid=None): ''' @return: zstack_test_volume() object ''' import zstackwoodpecker.zstack_test.zstack_test_volume as \ zstack_volume_header if self.state == sp_header.DELETED: test_util.test_fail( 'Should not be called, as snapshot volume:%s has been deleted. Snapshot can not\ be created to a new data volume' % self.target_volume.get_volume().uuid) if not name: name = 'data volume created by sp: %s' % self.snapshot.uuid snapshot_uuid = self.get_snapshot().uuid volume_inv = vol_ops.create_volume_from_snapshot(snapshot_uuid, \ name, ps_uuid) super(ZstackTestSnapshot, self).create_data_volume() volume_obj = zstack_volume_header.ZstackTestVolume() volume_obj.set_volume(volume_inv) volume_obj.set_state(volume_header.DETACHED) #ROOT Volume won't create checking point. So skip. if self.get_volume_type() != volume_header.ROOT_VOLUME: volume_obj.set_original_checking_points(self.get_checking_points()) return volume_obj
def create_snapshot(vm_obj): vol_obj = zstack_volume_header.ZstackTestVolume() vol_obj.set_volume(test_lib.lib_get_root_volume(vm_obj.get_vm())) snapshots_root = zstack_sp_header.ZstackVolumeSnapshot() snapshots_root.set_utility_vm(vm_obj) snapshots_root.set_target_volume(vol_obj) snapshots_root.create_snapshot('create_data_snapshot1') snapshots_root.check() sp1 = snapshots_root.get_current_snapshot()
def create_volume(volume_creation_option=None): if not volume_creation_option: disk_offering = test_lib.lib_get_disk_offering_by_name(os.environ.get('diskOfferingName-s')) volume_creation_option = test_util.VolumeOption() volume_creation_option.set_disk_offering_uuid(disk_offering.uuid) volume_creation_option.set_name('vr_test_volume') volume = zstack_volume_header.ZstackTestVolume() volume.set_creation_option(volume_creation_option) volume.create() return volume
def create_data_volume(self, ps_uuid, name = None, host_uuid = None): import zstackwoodpecker.header.volume as volume_header import zstackwoodpecker.zstack_test.zstack_test_volume \ as zstack_volume_header volume_inv = vol_ops.create_volume_from_template(self.get_image().uuid,\ ps_uuid, name, host_uuid) volume = zstack_volume_header.ZstackTestVolume() volume.set_volume(volume_inv) volume.set_state(volume_header.DETACHED) volume.set_original_checking_points(self.get_original_checking_points()) super(ZstackTestImage, self).create_data_volume() return volume
def create_volume(volume_creation_option=None, session_uuid = None): if not volume_creation_option: disk_offering_uuid = res_ops.query_resource(res_ops.DISK_OFFERING)[0].uuid volume_creation_option = test_util.VolumeOption() volume_creation_option.set_disk_offering_uuid(disk_offering_uuid) volume_creation_option.set_name('vr_test_volume') volume_creation_option.set_session_uuid(session_uuid) volume = zstack_volume_header.ZstackTestVolume() volume.set_creation_option(volume_creation_option) volume.create() return volume
def create_volume(volume_creation_option = None, session_uuid = None): if not volume_creation_option: disk_offering = test_lib.lib_get_disk_offering_by_name(os.environ.get('smallDiskOfferingName')) volume_creation_option = test_util.VolumeOption() volume_creation_option.set_disk_offering_uuid(disk_offering.uuid) volume_creation_option.set_name('test_volume') if session_uuid: volume_creation_option.set_session_uuid(session_uuid) volume = test_volume.ZstackTestVolume() volume.set_creation_option(volume_creation_option) volume.create() return volume
def create_volume(volume_creation_option=None, session_uuid=None): if not volume_creation_option: disk_offering = test_lib.lib_get_disk_offering_by_name( os.getenv('smallDiskOfferingName')) host_uuid = res_ops.get_resource(res_ops.HOST)[0].uuid cond = res_ops.gen_query_conditions('type', '=', 'LocalStorage') ps_uuid = res_ops.query_resource(res_ops.PRIMARY_STORAGE, cond)[0].uuid system_tags = ["localStorage::hostUuid::%s" % host_uuid] volume_creation_option = test_util.VolumeOption() volume_creation_option.set_disk_offering_uuid(disk_offering.uuid) volume_creation_option.set_name('test_volume') volume_creation_option.set_primary_storage_uuid(ps_uuid) volume_creation_option.set_system_tags(system_tags) volume_creation_option.set_session_uuid(session_uuid) volume = zstack_volume_header.ZstackTestVolume() volume.set_creation_option(volume_creation_option) volume.create() return volume
def test(): test_util.test_dsc('Create test vm and check') vm = test_stub.create_vlan_vm() test_obj_dict.add_vm(vm) vm.stop() r_volume = zstack_volume_header.ZstackTestVolume() r_volume.set_volume(test_lib.lib_get_root_volume(vm.get_vm())) r_volume.set_state(volume_header.ATTACHED) test_util.test_dsc('Create volume template and check') bs_list = test_lib.lib_get_backup_storage_list_by_vm(vm.get_vm()) vol_tmpt = r_volume.create_template([bs_list[0].uuid], 'new_data_template') test_obj_dict.add_image(vol_tmpt) vol_tmpt.check() test_util.test_dsc('Create volume from template and check') ps_uuid = vm.get_vm().allVolumes[0].primaryStorageUuid volume = vol_tmpt.create_data_volume(ps_uuid, 'new_volume_from_template1') test_obj_dict.add_volume(volume) volume2 = vol_tmpt.create_data_volume(ps_uuid, 'new_volume_from_template2') test_obj_dict.add_volume(volume2) volume2.check() volume.attach(vm) vm.start() volume2.attach(vm) vm.check() volume.check() volume2.check() volume.detach() volume.delete() test_obj_dict.rm_volume(volume) volume2.detach() volume2.delete() test_obj_dict.rm_volume(volume2) vol_tmpt.delete() test_obj_dict.rm_image(vol_tmpt) vm.destroy() test_util.test_pass('Create Data Volume Template from Data Volume Success')
def test(): global test_obj_dict, VOL_OPS, VM_STATE_OPS, utility_vm, backup flavor = case_flavor[os.environ.get('CASE_FLAVOR')] DVOL_OP = flavor['vm_op'] STATE_OP = flavor['state_op'] ps = res_ops.query_resource(res_ops.PRIMARY_STORAGE)[0] if ps.type == inventory.CEPH_PRIMARY_STORAGE_TYPE or ps.type == "AliyunNAS": test_util.test_skip( "VolumeBackup does not support Ceph and AliyunNAS for now") vm_name = "test_vm" utility_vm_name = "utility_vm" cond = res_ops.gen_query_conditions("system", '=', "false") cond = res_ops.gen_query_conditions("mediaType", '=', "RootVolumeTemplate", cond) cond = res_ops.gen_query_conditions("platform", '=', "Linux", cond) img_name = res_ops.query_resource(res_ops.IMAGE, cond)[0].name cond = res_ops.gen_query_conditions("category", '=', "Private") l3_name = res_ops.query_resource(res_ops.L3_NETWORK, cond)[0].name disk_offering = test_lib.lib_get_disk_offering_by_name( os.environ.get('smallDiskOfferingName')) disk_offering_uuids = [disk_offering.uuid] vm = test_stub.create_vm(vm_name, img_name, l3_name, disk_offering_uuids=disk_offering_uuids) vm.check() test_obj_dict.add_vm(vm) utility_vm = test_stub.create_vm(utility_vm_name, img_name, l3_name) vm.check() test_obj_dict.add_vm(utility_vm) dvol = zstack_volume_header.ZstackTestVolume() dvol.set_volume(test_lib.lib_get_data_volumes(vm.get_vm())[0]) dvol.set_state(volume_header.ATTACHED) dvol.set_target_vm(vm) test_obj_dict.add_volume(dvol) if "VM_TEST_BACKUP_IMAGE" in DVOL_OP or "VM_TEST_REVERT_BACKUP" in DVOL_OP: vm_op_test(vm, dvol, "DVOL_BACKUP") if "DVOL_DEL_SNAPSHOT" in DVOL_OP: vm_op_test(vm, dvol, "DVOL_TEST_SNAPSHOT") for i in DVOL_OP: vm_op_test(vm, dvol, random.choice(STATE_OP)) if not backup_list and "VM_TEST_BACKUP_IMAGE" == i: i = "VM_TEST_NONE" vm_op_test(vm, dvol, i) if vm.state == "Stopped": vm.start() vm.check() if test_lib.lib_is_vm_l3_has_vr(vm.vm): test_lib.TestHarness = test_lib.TestHarnessVR cmd = "dd if=/dev/urandom of=/dev/vdb bs=512k count=1" test_lib.lib_execute_command_in_vm(vm.vm, cmd) vm.suspend() vm_op_test(vm, dvol, "DVOL_BACKUP") compare(ps, vm, dvol, backup) vm.resume() print_path(Path) test_lib.lib_error_cleanup(test_obj_dict)
def test(): global session_to global session_mc session_to = con_ops.change_global_config('identity', 'session.timeout', '720000') session_mc = con_ops.change_global_config('identity', 'session.maxConcurrent', '10000') test_util.test_dsc('Create test vm as utility vm') vm = test_stub.create_vlan_vm() test_obj_dict.add_vm(vm) #use root volume to skip add_checking_point test_util.test_dsc('Use root volume for snapshot testing') root_volume_inv = test_lib.lib_get_root_volume(vm.get_vm()) root_volume = zstack_volume_header.ZstackTestVolume() root_volume.set_volume(root_volume_inv) root_volume.set_state(volume_header.ATTACHED) root_volume.set_target_vm(vm) test_obj_dict.add_volume(root_volume) vm.check() snapshots = test_obj_dict.get_volume_snapshot( root_volume.get_volume().uuid) snapshots.set_utility_vm(vm) ori_num = 100 index = 1 while index < 101: thread = threading.Thread(target=create_snapshot, args=( snapshots, index, )) thread.start() index += 1 while threading.activeCount() > 1: time.sleep(0.1) #snapshot.check() doesn't work for root volume #snapshots.check() #check if snapshot exists in install_path ps = test_lib.lib_get_primary_storage_by_vm(vm.get_vm()) if ps.type == inventory.NFS_PRIMARY_STORAGE_TYPE or ps.type == inventory.LOCAL_STORAGE_TYPE: host = test_lib.lib_get_vm_host(vm.get_vm()) for snapshot in snapshots.get_snapshot_list(): snapshot_inv = snapshot.get_snapshot() sp_ps_install_path = snapshot_inv.primaryStorageInstallPath if test_lib.lib_check_file_exist(host, sp_ps_install_path): test_util.test_logger( 'Check result: snapshot %s is found in host %s in path %s' % (snapshot_inv.name, host.managementIp, sp_ps_install_path)) else: test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_fail( 'Check result: snapshot %s is not found in host %s in path %s' % (snapshot_inv.name, host.managementIp, sp_ps_install_path)) else: test_util.test_logger( 'Skip check file install path for %s primary storage' % (ps.type)) cond = res_ops.gen_query_conditions('volumeUuid', '=', root_volume.get_volume().uuid) sps_num = res_ops.query_resource_count(res_ops.VOLUME_SNAPSHOT, cond) if sps_num != ori_num: test_util.test_fail( 'Create %d snapshots, but only %d snapshots were successfully created' % (ori_num, sps_num)) try: test_lib.lib_robot_cleanup(test_obj_dict) except: test_lib.test_logger('Delete VM may timeout') test_util.test_pass('Test create 100 snapshots simultaneously success')
def test(): test_util.test_dsc('Create original vm') vm = test_stub.create_vlan_vm() test_obj_dict.add_vm(vm) vm.stop() vm1 = test_stub.create_vlan_vm() test_obj_dict.add_vm(vm1) vm1.check() test_util.test_dsc('create snapshot for root volume') vm_root_volume_inv = test_lib.lib_get_root_volume(vm.get_vm()) snapshots_root = test_obj_dict.get_volume_snapshot(vm_root_volume_inv.uuid) snapshots_root.set_utility_vm(vm1) test_obj_dict.add_volume_snapshot(snapshots_root) snapshots_root.create_snapshot('create_root_snapshot1') test_util.test_dsc('create image template from root volume') root_volume_uuid = vm_root_volume_inv.uuid root_image_uuid = vm_root_volume_inv.rootImageUuid vm_img_inv = test_lib.lib_get_image_by_uuid(root_image_uuid) image_option = test_util.ImageOption() image_option.set_name('creating_image_from_root_volume') image_option.set_guest_os_type(vm_img_inv.guestOsType) image_option.set_bits(vm_img_inv.bits) image_option.set_root_volume_uuid(root_volume_uuid) backup_storage_list = test_lib.lib_get_backup_storage_list_by_vm(vm.get_vm()) bs_uuid_list = [] for bs in backup_storage_list: bs_uuid_list.append(bs.uuid) image_option.set_backup_storage_uuid_list(bs_uuid_list) image = zstack_img_header.ZstackTestImage() image.set_creation_option(image_option) image.create() if test_lib.lib_get_delete_policy('image') != zstack_header.DELETE_DIRECT: test_obj_dict.add_image(image) image.delete() test_util.test_dsc('Construct volume obj.') r_volume = zstack_volume_header.ZstackTestVolume() r_volume.set_volume(test_lib.lib_get_root_volume(vm.get_vm())) r_volume.set_state(vol_header.ATTACHED) test_util.test_dsc('Create volume template') bs_list = test_lib.lib_get_backup_storage_list_by_vm(vm.get_vm()) vol_tmpt = r_volume.create_template([bs_list[0].uuid], 'new_data_template_by_root_volume') if test_lib.lib_get_delete_policy('image') != zstack_header.DELETE_DIRECT: test_obj_dict.add_image(vol_tmpt) #destroy vm host_uuid = test_lib.lib_get_vm_host(vm.get_vm()).uuid vm.destroy() test_util.test_dsc('Create volume from template') ps_uuid = vm.get_vm().allVolumes[0].primaryStorageUuid ps = test_lib.lib_get_primary_storage_by_uuid(ps_uuid) if ps.type == inventory.LOCAL_STORAGE_TYPE: volume = vol_tmpt.create_data_volume(ps_uuid, 'new_data_volume_from_template1', host_uuid) else: volume = vol_tmpt.create_data_volume(ps_uuid, 'new_data_volume_from_template1') test_obj_dict.add_volume(volume) vol_tmpt.delete() test_util.test_dsc('create snapshot') snapshots = zstack_sp_header.ZstackVolumeSnapshot() snapshots.set_target_volume(volume) snapshots.set_utility_vm(vm1) test_obj_dict.add_volume_snapshot(snapshots) snapshots.create_snapshot('create_snapshot1') snapshot1 = snapshots.get_current_snapshot() snapshots.create_snapshot('create_snapshot2') snapshot2 = snapshots.get_current_snapshot() snapshots.create_snapshot('create_snapshot3') snapshot3 = snapshots.get_current_snapshot() test_util.test_dsc('delete snapshot3') snapshots.delete_snapshot(snapshot3) snapshots.check() test_obj_dict.rm_volume_snapshot(snapshots) test_lib.lib_robot_cleanup(test_obj_dict) test_util.test_pass('Create snapshot from a volume, which is created from data volume template, which is create from a root volume Success')
def test(): global session_uuid global session_to global session_mc thread_threshold = os.environ.get('ZSTACK_THREAD_THRESHOLD') if not thread_threshold: thread_threshold = 1000 else: thread_threshold = int(thread_threshold) volume_num = os.environ.get('ZSTACK_TEST_NUM') if not volume_num: volume_num = 0 else: volume_num = int(volume_num) #change account session timeout. session_to = con_ops.change_global_config('identity', 'session.timeout', '720000', session_uuid) session_mc = con_ops.change_global_config('identity', 'session.maxConcurrent', '10000', session_uuid) session_uuid = acc_ops.login_as_admin() vm_num = res_ops.query_resource_count(res_ops.VM_INSTANCE, [], session_uuid) if vm_num < thread_threshold: test_util.test_fail( 'This test needs: %d VM instances for volume attaching and detaching operations. But there are only %d VMs instances. Please use this case: test_crt_basic_vm_with_max_threads.py to create required VMs.' % (thread_threshold, volume_num)) vms = res_ops.query_resource_with_num(res_ops.VM_INSTANCE, [], \ session_uuid, start = 0, limit = thread_threshold) test_util.test_logger('ZSTACK_THREAD_THRESHOLD is %d' % thread_threshold) test_util.test_logger('ZSTACK_TEST_NUM is %d' % volume_num) org_num = volume_num disk_offering_name = os.environ.get('smallDiskOfferingName') disk_offering_uuid = test_lib.lib_get_disk_offering_by_name( disk_offering_name).uuid volume_option = test_util.VolumeOption() volume_option.set_disk_offering_uuid(disk_offering_uuid) volume_option.set_session_uuid(session_uuid) random_name = random.random() volume_name = 'perf_volume_%s' % str(random_name) volume_option.set_name(volume_name) vm_num = 0 while volume_num > 0: check_thread_exception() volume = test_vol_header.ZstackTestVolume() volume.set_creation_option(volume_option) volume_num -= 1 if vm_num > (thread_threshold - 1): vm_num = 0 thread = threading.Thread(target=create_volume, args=( volume, vms[vm_num].uuid, )) vm_num += 1 while threading.active_count() > thread_threshold: time.sleep(0.) thread.start() while threading.active_count() > 1: time.sleep(0.01) cond = res_ops.gen_query_conditions('name', '=', volume_name) volumes_num = res_ops.query_resource_count(res_ops.VOLUME, cond, session_uuid) con_ops.change_global_config('identity', 'session.timeout', session_to, session_uuid) con_ops.change_global_config('identity', 'session.maxConcurrent', session_mc, session_uuid) acc_ops.logout(session_uuid) if volumes_num == org_num: test_util.test_pass('Create %d Volumes Test Success' % org_num) else: test_util.test_fail( 'Create %d Volumes Test Failed. Only find %d Volumes.' % (org_num, volumes_num))