def update(self):
     if self.get_state() != image_header.EXPUNGED:
         updated_image = test_lib.lib_get_image_by_uuid(self.image.uuid)
         if updated_image:
             self.image = updated_image
         else:
             self.set_state(image_header.EXPUNGED)
     return self.image
def test():
    vm = test_stub.create_vm(vm_name='basic-test-vm',
                             image_name='image_for_sg_test')
    test_obj_dict.add_vm(vm)
    vm1 = test_stub.create_vm(vm_name='basic-test-vm1',
                              image_name='image_for_sg_test')
    test_obj_dict.add_vm(vm1)

    image_creation_option = test_util.ImageOption()
    backup_storage_list = test_lib.lib_get_backup_storage_list_by_vm(vm1.vm)
    for bs in backup_storage_list:
        if bs.type == inventory.IMAGE_STORE_BACKUP_STORAGE_TYPE:
            image_creation_option.set_backup_storage_uuid_list(
                [backup_storage_list[0].uuid])
            break
    else:
        vm.destroy()
        vm1.destroy()
        test_util.test_skip('Not find image store type backup storage.')

    #vm1.check()
    vm_root_volume_inv = test_lib.lib_get_root_volume(vm1.get_vm())
    root_image_uuid = vm_root_volume_inv.rootImageUuid
    vm_img_inv = test_lib.lib_get_image_by_uuid(root_image_uuid)
    test_util.test_dsc('create snapshot and check')
    snapshots = test_obj_dict.get_volume_snapshot(vm_root_volume_inv.uuid)
    snapshots.set_utility_vm(vm)
    snapshots.create_snapshot('create_root_snapshot1')
    snapshot1 = snapshots.get_current_snapshot()
    snapshots.create_snapshot('create_root_snapshot2')

    image_creation_option.set_root_volume_uuid(vm_root_volume_inv.uuid)
    image_creation_option.set_name('test_create_vm_images_vm1')
    #image_creation_option.set_platform('Linux')
    bs_type = backup_storage_list[0].type
    if bs_type == 'Ceph':
        origin_interval = conf_ops.change_global_config(
            'ceph', 'imageCache.cleanup.interval', '1')

    image1 = test_image.ZstackTestImage()
    image1.set_creation_option(image_creation_option)
    image1.create()
    test_obj_dict.add_image(image1)
    image1.check()
    vm2 = test_stub.create_vm(image_name='test_create_vm_images_vm1')
    test_obj_dict.add_vm(vm2)

    #do vm check before snapshot check
    vm.check()
    vm1.stop()
    snapshots.check()
    snapshots.use_snapshot(snapshot1)
    vm1.start()
    snapshots.create_snapshot('create_root_snapshot1.1')

    image_creation_option.set_name('test_create_vm_images_vm2')
    image2 = test_image.ZstackTestImage()
    image2.set_creation_option(image_creation_option)
    image2.create()
    test_obj_dict.add_image(image2)
    image2.check()
    vm3 = test_stub.create_vm(image_name='test_create_vm_images_vm2')
    test_obj_dict.add_vm(vm3)
    snapshots.check()
    vm2.check()
    vm3.check()
    test_lib.lib_robot_cleanup(test_obj_dict)
    test_util.test_pass('Create VM Image in Image Store Success')
Example #3
0
def test():
    test_util.test_dsc('Create original vm')
    vm = test_stub.create_vlan_vm()
    test_obj_dict.add_vm(vm)
    vm1 = test_stub.create_vlan_vm()
    test_obj_dict.add_vm(vm1)

    test_util.test_dsc('Create Data Volume obj.')
    disk_offering = test_lib.lib_get_disk_offering_by_name(
        os.environ.get('smallDiskOfferingName'))
    volume_creation_option = test_util.VolumeOption()
    volume_creation_option.set_name(
        'volume for create both root and data volume snapshot')
    volume_creation_option.set_disk_offering_uuid(disk_offering.uuid)
    volume = test_stub.create_volume(volume_creation_option)
    test_obj_dict.add_volume(volume)

    volume.attach(vm)
    test_util.test_dsc('Construct root volume obj.')
    vm_root_volume_inv = test_lib.lib_get_root_volume(vm.get_vm())
    #root_volume = zstack_vol_header.ZstackTestVolume()
    #root_volume.set_volume(vm_root_volume_inv)
    #root_volume.set_target_vm(vm)
    #root_volume.set_state(vol_header.ATTACHED)
    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)

    test_util.test_dsc('Stop vm before create snapshot.')
    vm.stop()

    test_util.test_dsc('create snapshot')
    snapshots_data = test_obj_dict.get_volume_snapshot(
        volume.get_volume().uuid)
    snapshots_data.set_utility_vm(vm1)
    snapshots_data.create_snapshot('create_data_snapshot1')
    snapshot1 = snapshots_data.get_current_snapshot()
    snapshots_data.create_snapshot('create_data_snapshot2')
    snapshots_data.create_snapshot('create_data_snapshot3')

    #snapshots_root = zstack_sp_header.ZstackVolumeSnapshot()
    #snapshots_root.set_target_volume(root_volume)
    #test_obj_dict.add_volume_snapshot(snapshots_root)
    snapshots_root = test_obj_dict.get_volume_snapshot(vm_root_volume_inv.uuid)
    snapshots_root.set_utility_vm(vm1)
    snapshots_root.create_snapshot('create_root_snapshot1')

    snapshots_root.create_snapshot('create_root_snapshot2')
    snapshot2 = snapshots_root.get_current_snapshot()
    snapshots_root.create_snapshot('create_root_snapshot3')
    snapshot3 = snapshots_root.get_current_snapshot()

    test_util.test_dsc('delete snapshot3 and create image tempalte from root')
    snapshots_root.delete_snapshot(snapshot3)

    image_option = test_util.ImageOption()
    image_option.set_name('creating_image_from_root_volume_after_creating_sp')
    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)

    test_util.test_dsc('create image template from root volume')
    image2 = zstack_img_header.ZstackTestImage()
    image2.set_creation_option(image_option)
    image2.create()
    test_obj_dict.add_image(image2)
    image2.check()
    image2_uuid = image2.get_image().uuid

    test_util.test_dsc('create vm2 with new created template and check')
    vm_creation_option = vm.get_creation_option()
    vm_creation_option.set_image_uuid(image2_uuid)
    vm2 = test_lib.lib_create_vm(vm_creation_option)
    test_obj_dict.add_vm(vm2)
    vm2.check()

    vm2.destroy()
    test_obj_dict.rm_vm(vm2)

    #check data snapshots
    snapshots_data.use_snapshot(snapshot1)
    snapshots_data.create_snapshot('create_snapshot1.1.1')
    snapshots_data.create_snapshot('create_snapshot1.1.2')

    test_util.test_dsc(
        'create snapshot4 and finally delete all snapshots_root')
    snapshots_root.create_snapshot('create_snapshot4')
    snapshot4 = snapshots_root.get_current_snapshot()
    snapshots_root.backup_snapshot(snapshot4)
    snapshots_root.check()
    vm.destroy()
    test_obj_dict.rm_vm(vm)

    test_util.test_dsc('create image template2 from root snapshot')
    image_option.set_root_volume_uuid(snapshot4.get_snapshot().uuid)
    snapshot4.set_image_creation_option(image_option)
    image3 = snapshot4.create_image_template()
    test_obj_dict.add_image(image3)
    image3.check()
    image3_uuid = image3.get_image().uuid

    test_util.test_dsc('create vm3 with new created template and check')
    vm_creation_option.set_image_uuid(image3_uuid)
    vm3 = test_lib.lib_create_vm(vm_creation_option)
    test_obj_dict.add_vm(vm3)
    vm3.check()

    vm3.destroy()
    test_obj_dict.rm_vm(vm3)

    #check data snapshots
    snapshots_data.use_snapshot(snapshot1)
    snapshots_data.create_snapshot('create_snapshot1.2.1')
    snapshots_data.check()

    test_lib.lib_robot_cleanup(test_obj_dict)
    test_util.test_pass(
        'Create image from root volume with creating/destroying Snapshot Success'
    )
Example #4
0
def test():
    test_util.test_dsc('Create original vm')
    vm = test_stub.create_vlan_vm()
    test_obj_dict.add_vm(vm)
    vm1 = test_stub.create_vlan_vm()
    test_obj_dict.add_vm(vm1)

    test_util.test_dsc('Construct volume obj.')
    vm_root_volume_inv = test_lib.lib_get_root_volume(vm.get_vm())
    #root_volume = zstack_vol_header.ZstackTestVolume()
    #root_volume.set_volume(vm_root_volume_inv)
    #root_volume.set_target_vm(vm)
    #root_volume.set_state(vol_header.ATTACHED)
    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)

    test_util.test_dsc('Stop vm before create snapshot.')
    vm.stop()

    test_util.test_dsc('create snapshot')
    #snapshots = zstack_sp_header.ZstackVolumeSnapshot()
    #snapshots.set_target_volume(root_volume)
    #test_obj_dict.add_volume_snapshot(snapshots)
    snapshots = test_obj_dict.get_volume_snapshot(vm_root_volume_inv.uuid)
    snapshots.set_utility_vm(vm1)
    snapshots.create_snapshot('create_root_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 and create image tempalte from root')
    snapshots.delete_snapshot(snapshot3)

    image_option = test_util.ImageOption()
    image_option.set_name('creating_image_from_root_volume_after_creating_sp')
    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)

    test_util.test_dsc('create image template from root volume')
    image2 = zstack_img_header.ZstackTestImage()
    image2.set_creation_option(image_option)
    image2.create()
    test_obj_dict.add_image(image2)
    image2.check()
    image2_uuid = image2.get_image().uuid

    test_util.test_dsc('create vm2 with new created template and check')
    vm_creation_option = vm.get_creation_option()
    vm_creation_option.set_image_uuid(image2_uuid)
    vm2 = test_lib.lib_create_vm(vm_creation_option)
    test_obj_dict.add_vm(vm2)
    vm2.check()

    vm2.destroy()
    test_obj_dict.rm_vm(vm2)

    test_util.test_dsc('create snapshot4 and finally delete all snapshots')
    snapshots.create_snapshot('create_snapshot4')
    snapshot4 = snapshots.get_current_snapshot()
    snapshot4.backup()
    snapshots.check()
    snapshots.delete()
    test_obj_dict.rm_volume_snapshot(snapshots)

    test_util.test_dsc('create image template2 from root volume')
    image3 = zstack_img_header.ZstackTestImage()
    image3.set_creation_option(image_option)
    image3.create()
    test_obj_dict.add_image(image3)
    image3.check()
    image3_uuid = image3.get_image().uuid

    test_util.test_dsc('create vm3 with new created template and check')
    vm_creation_option.set_image_uuid(image3_uuid)
    vm3 = test_lib.lib_create_vm(vm_creation_option)
    test_obj_dict.add_vm(vm3)
    vm3.check()

    vm3.destroy()
    test_obj_dict.rm_vm(vm3)

    test_lib.lib_robot_cleanup(test_obj_dict)
    test_util.test_pass(
        'Create image from root volume with creating/destroying Snapshot Success'
    )
def test():
    vm = test_stub.create_vm(vm_name = 'basic-test-vm', image_name = 'image_for_sg_test')
    test_obj_dict.add_vm(vm)
    vm1 = test_stub.create_vm(vm_name = 'basic-test-vm1', image_name = 'image_for_sg_test')
    test_obj_dict.add_vm(vm1)

    image_creation_option = test_util.ImageOption()
    backup_storage_list = test_lib.lib_get_backup_storage_list_by_vm(vm1.vm)
    for bs in backup_storage_list:
        if bs.type == inventory.IMAGE_STORE_BACKUP_STORAGE_TYPE:
            image_creation_option.set_backup_storage_uuid_list([backup_storage_list[0].uuid])
            break
    else:
        vm.destroy()
        vm1.destroy()
        test_util.test_skip('Not find image store type backup storage.')

    #vm1.check()
    vm_root_volume_inv = test_lib.lib_get_root_volume(vm1.get_vm())
    root_image_uuid = vm_root_volume_inv.rootImageUuid
    vm_img_inv = test_lib.lib_get_image_by_uuid(root_image_uuid)
    test_util.test_dsc('create snapshot and check')
    snapshots = test_obj_dict.get_volume_snapshot(vm_root_volume_inv.uuid)
    snapshots.set_utility_vm(vm)
    snapshots.create_snapshot('create_root_snapshot1')
    snapshot1 = snapshots.get_current_snapshot()
    snapshots.create_snapshot('create_root_snapshot2')

    image_creation_option.set_root_volume_uuid(vm_root_volume_inv.uuid)
    image_creation_option.set_name('test_create_vm_images_vm1')
    #image_creation_option.set_platform('Linux')
    bs_type = backup_storage_list[0].type
    if bs_type == 'Ceph':
        origin_interval = conf_ops.change_global_config('ceph', 'imageCache.cleanup.interval', '1')

    image1 = test_image.ZstackTestImage()
    image1.set_creation_option(image_creation_option)
    image1.create()
    test_obj_dict.add_image(image1)
    image1.check()
    vm2 = test_stub.create_vm(image_name = 'test_create_vm_images_vm1')
    test_obj_dict.add_vm(vm2)

    #do vm check before snapshot check
    vm.check()
    vm1.stop()
    snapshots.check()
    snapshots.use_snapshot(snapshot1)
    vm1.start()
    snapshots.create_snapshot('create_root_snapshot1.1')
    
    image_creation_option.set_name('test_create_vm_images_vm2')
    image2 = test_image.ZstackTestImage()
    image2.set_creation_option(image_creation_option)
    image2.create()
    test_obj_dict.add_image(image2)
    image2.check()
    vm3 = test_stub.create_vm(image_name = 'test_create_vm_images_vm2')
    test_obj_dict.add_vm(vm3)
    snapshots.check()
    vm2.check()
    vm3.check()
    test_lib.lib_robot_cleanup(test_obj_dict)
    test_util.test_pass('Create VM Image in Image Store Success')
def test():
    primary_storage_list = res_ops.query_resource(res_ops.PRIMARY_STORAGE)
    for ps in primary_storage_list:
        if ps.type == "AliyunNAS":
            test_util.test_skip('The test is not supported by AliyunNAS primary storage.')

    test_util.test_dsc('Create original vm')
    vm = test_stub.create_vlan_vm()
    test_obj_dict.add_vm(vm)
    vm1 = test_stub.create_vlan_vm()
    test_obj_dict.add_vm(vm1)
    
    test_util.test_dsc('Create Data Volume obj.')
    disk_offering = test_lib.lib_get_disk_offering_by_name(os.environ.get('smallDiskOfferingName'))
    volume_creation_option = test_util.VolumeOption()
    volume_creation_option.set_name('volume for create both root and data volume snapshot')
    volume_creation_option.set_disk_offering_uuid(disk_offering.uuid)
    volume = test_stub.create_volume(volume_creation_option)
    test_obj_dict.add_volume(volume)

    volume.attach(vm)
    test_util.test_dsc('Construct root volume obj.')
    vm_root_volume_inv = test_lib.lib_get_root_volume(vm.get_vm())
    #root_volume = zstack_vol_header.ZstackTestVolume()
    #root_volume.set_volume(vm_root_volume_inv)
    #root_volume.set_target_vm(vm)
    #root_volume.set_state(vol_header.ATTACHED)
    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)

    test_util.test_dsc('Stop vm before create snapshot.')
    vm.stop()

    test_util.test_dsc('create snapshot')
    snapshots_data = test_obj_dict.get_volume_snapshot(volume.get_volume().uuid)
    snapshots_data.set_utility_vm(vm1)
    snapshots_data.create_snapshot('create_data_snapshot1')
    snapshot1 = snapshots_data.get_current_snapshot()
    snapshots_data.create_snapshot('create_data_snapshot2')
    snapshots_data.create_snapshot('create_data_snapshot3')

    #snapshots_root = zstack_sp_header.ZstackVolumeSnapshot()
    #snapshots_root.set_target_volume(root_volume)
    #test_obj_dict.add_volume_snapshot(snapshots_root)
    snapshots_root = test_obj_dict.get_volume_snapshot(vm_root_volume_inv.uuid)
    snapshots_root.set_utility_vm(vm1)
    snapshots_root.create_snapshot('create_root_snapshot1')

    snapshots_root.create_snapshot('create_root_snapshot2')
    snapshot2 = snapshots_root.get_current_snapshot()
    snapshots_root.create_snapshot('create_root_snapshot3')
    snapshot3 = snapshots_root.get_current_snapshot()

    test_util.test_dsc('delete snapshot3 and create image tempalte from root')
    snapshots_root.delete_snapshot(snapshot3)

    image_option = test_util.ImageOption()
    image_option.set_name('creating_image_from_root_volume_after_creating_sp')
    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)

    test_util.test_dsc('create image template from root volume')
    image2 = zstack_img_header.ZstackTestImage()
    image2.set_creation_option(image_option)
    image2.create()
    test_obj_dict.add_image(image2)
    image2.check()
    image2_uuid = image2.get_image().uuid
    
    test_util.test_dsc('create vm2 with new created template and check')
    vm_creation_option = vm.get_creation_option()
    vm_creation_option.set_image_uuid(image2_uuid)
    vm2 = test_lib.lib_create_vm(vm_creation_option)
    test_obj_dict.add_vm(vm2)
    vm2.check()

    vm2.destroy()
    test_obj_dict.rm_vm(vm2)

    ps_uuid = vm_root_volume_inv.primaryStorageUuid
    ps = test_lib.lib_get_primary_storage_by_uuid(ps_uuid)
    if ps.type == inventory.LOCAL_STORAGE_TYPE:
        # LOCAL Storage do not support create volume and template from backuped snapshot
        test_lib.lib_robot_cleanup(test_obj_dict)
        test_util.test_pass('Create image from root volume with creating/destroying Snapshot Success')

    #check data snapshots
    snapshots_data.use_snapshot(snapshot1)
    snapshots_data.create_snapshot('create_snapshot1.1.1')
    snapshots_data.create_snapshot('create_snapshot1.1.2')

    test_util.test_dsc('create snapshot4 and finally delete all snapshots_root')
    snapshots_root.create_snapshot('create_snapshot4')
    snapshot4 = snapshots_root.get_current_snapshot()
    #snapshots_root.backup_snapshot(snapshot4)
    snapshots_root.check()
    #vm.destroy()
    #test_obj_dict.rm_vm(vm)

    test_util.test_dsc('create image template2 from root snapshot')
    image_option.set_root_volume_uuid(snapshot4.get_snapshot().uuid)
    snapshot4.set_image_creation_option(image_option)
    image3 = snapshot4.create_image_template()
    test_obj_dict.add_image(image3)
    image3.check()
    image3_uuid = image3.get_image().uuid
    
    test_util.test_dsc('create vm3 with new created template and check')
    vm_creation_option.set_image_uuid(image3_uuid)
    vm3 = test_lib.lib_create_vm(vm_creation_option)
    test_obj_dict.add_vm(vm3)
    vm3.check()

    vm3.destroy()
    test_obj_dict.rm_vm(vm3)
    
    #check data snapshots
    snapshots_data.use_snapshot(snapshot1)
    snapshots_data.create_snapshot('create_snapshot1.2.1')
    snapshots_data.check()

    test_lib.lib_robot_cleanup(test_obj_dict)
    test_util.test_pass('Create image from root volume with creating/destroying Snapshot Success')
Example #7
0
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():
    primary_storage_list = res_ops.query_resource(res_ops.PRIMARY_STORAGE)
    for ps in primary_storage_list:
        if ps.type == "AliyunNAS":
            test_util.test_skip('The test is not supported by AliyunNAS primary storage.')

    test_util.test_dsc('Create original vm')
    vm = test_stub.create_vlan_vm()
    test_obj_dict.add_vm(vm)
    vm1 = test_stub.create_vlan_vm()
    test_obj_dict.add_vm(vm1)

    test_util.test_dsc('Construct volume obj.')
    vm_root_volume_inv = test_lib.lib_get_root_volume(vm.get_vm())
    #root_volume = zstack_vol_header.ZstackTestVolume()
    #root_volume.set_volume(vm_root_volume_inv)
    #root_volume.set_state(vol_header.ATTACHED)
    root_image_uuid = vm_root_volume_inv.rootImageUuid
    vm_img_inv = test_lib.lib_get_image_by_uuid(root_image_uuid)

    test_util.test_dsc('Stop vm before create snapshot.')
    vm.stop()

    test_util.test_dsc('create snapshot and check')
    #snapshots = zstack_sp_header.ZstackVolumeSnapshot()
    #snapshots.set_target_volume(root_volume)
    #test_obj_dict.add_volume_snapshot(snapshots)
    snapshots = test_obj_dict.get_volume_snapshot(vm_root_volume_inv.uuid)
    snapshots.set_utility_vm(vm1)
    snapshots.create_snapshot('create_root_snapshot1')
    snapshots.check()

    snapshot1 = snapshots.get_current_snapshot()
    snapshots.create_snapshot('create_snapshot2')
    snapshots.create_snapshot('create_snapshot3')
    snapshots.check()
    snapshot3 = snapshots.get_current_snapshot()

    test_util.test_dsc('create image template from sp3 and check')
    
    image_option = test_util.ImageOption()
    image_option.set_name('test_snapshot_creating_image')
    image_option.set_guest_os_type(vm_img_inv.guestOsType)
    image_option.set_bits(vm_img_inv.bits)
    image_option.set_root_volume_uuid(snapshot3.get_snapshot().uuid)
    snapshot3.set_image_creation_option(image_option)
    image3 = snapshot3.create_image_template()
    test_obj_dict.add_image(image3)
    image3_uuid = image3.get_image().uuid
    image3.check()

    vm_creation_option = vm.get_creation_option()
    vm_creation_option.set_image_uuid(image3_uuid)
    vm3 = test_lib.lib_create_vm(vm_creation_option)
    test_obj_dict.add_vm(vm3)
    vm3.check()

    test_util.test_dsc('create image template from sp1 and check')
    snapshot1.set_image_creation_option(image_option)
    image1 = snapshot3.create_image_template()
    test_obj_dict.add_image(image1)
    image1_uuid = image1.get_image().uuid
    image1.check()

    vm_creation_option.set_image_uuid(image1_uuid)
    vm2 = test_lib.lib_create_vm(vm_creation_option)
    test_obj_dict.add_vm(vm2)
    vm2.check()
    
    snapshots.delete()
    test_obj_dict.rm_volume_snapshot(snapshots)
    vm2.check()
    vm3.check()

    test_lib.lib_robot_cleanup(test_obj_dict)
    test_util.test_pass('Create image from Snapshot test Success')
def test():
    test_util.test_dsc('Create original vm')
    vm = test_stub.create_vlan_vm()
    test_obj_dict.add_vm(vm)
    vm1 = test_stub.create_vlan_vm()
    test_obj_dict.add_vm(vm1)
    

    test_util.test_dsc('Construct volume obj.')
    vm_root_volume_inv = test_lib.lib_get_root_volume(vm.get_vm())
    #root_volume = zstack_vol_header.ZstackTestVolume()
    #root_volume.set_volume(vm_root_volume_inv)
    #root_volume.set_target_vm(vm)
    #root_volume.set_state(vol_header.ATTACHED)
    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)

    test_util.test_dsc('Stop vm before create snapshot.')
    vm.stop()

    test_util.test_dsc('create snapshot')
    #snapshots = zstack_sp_header.ZstackVolumeSnapshot()
    #snapshots.set_target_volume(root_volume)
    #test_obj_dict.add_volume_snapshot(snapshots)
    snapshots = test_obj_dict.get_volume_snapshot(vm_root_volume_inv.uuid)
    snapshots.set_utility_vm(vm1)
    snapshots.create_snapshot('create_root_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 and create image tempalte from root')
    snapshots.delete_snapshot(snapshot3)

    image_option = test_util.ImageOption()
    image_option.set_name('creating_image_from_root_volume_after_creating_sp')
    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)

    test_util.test_dsc('create image template from root volume')
    image2 = zstack_img_header.ZstackTestImage()
    image2.set_creation_option(image_option)
    image2.create()
    test_obj_dict.add_image(image2)
    image2.check()
    image2_uuid = image2.get_image().uuid
    
    test_util.test_dsc('create vm2 with new created template and check')
    vm_creation_option = vm.get_creation_option()
    vm_creation_option.set_image_uuid(image2_uuid)
    vm2 = test_lib.lib_create_vm(vm_creation_option)
    test_obj_dict.add_vm(vm2)
    vm2.check()

    vm2.destroy()
    test_obj_dict.rm_vm(vm2)

    test_util.test_dsc('create snapshot4 and finally delete all snapshots')
    snapshots.create_snapshot('create_snapshot4')
    snapshot4 = snapshots.get_current_snapshot()
    snapshot4.backup()
    snapshots.check()
    snapshots.delete()
    test_obj_dict.rm_volume_snapshot(snapshots)

    test_util.test_dsc('create image template2 from root volume')
    image3 = zstack_img_header.ZstackTestImage()
    image3.set_creation_option(image_option)
    image3.create()
    test_obj_dict.add_image(image3)
    image3.check()
    image3_uuid = image3.get_image().uuid
    
    test_util.test_dsc('create vm3 with new created template and check')
    vm_creation_option.set_image_uuid(image3_uuid)
    vm3 = test_lib.lib_create_vm(vm_creation_option)
    test_obj_dict.add_vm(vm3)
    vm3.check()

    vm3.destroy()
    test_obj_dict.rm_vm(vm3)
    
    test_lib.lib_robot_cleanup(test_obj_dict)
    test_util.test_pass('Create image from root volume with creating/destroying Snapshot Success')