def delete_snapshot(vm_obj, dvol): snapshots_root = zstack_sp_header.ZstackVolumeSnapshot() snapshots_root.set_utility_vm(utility_vm) snapshots_root.set_target_volume(dvol) sp_list = snapshots_root.get_snapshot_list() if sp_list: snapshots_root.delete_snapshot(random.choice(sp_list))
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_snapshot(vm_obj, dvol): snapshots_root = zstack_sp_header.ZstackVolumeSnapshot() snapshots_root.set_utility_vm(utility_vm) snapshots_root.set_target_volume(dvol) snapshots_root.create_snapshot('create_data_snapshot1')
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')