コード例 #1
0
 def delete_image(self):
     cond_image = res_ops.gen_query_conditions('name', '=', 'test-image-longjob')
     longjob_image = res_ops.query_resource(res_ops.IMAGE, cond_image)[0]
     try:
         img_ops.delete_image(longjob_image.uuid, backup_storage_uuid_list=[self.target_bs.uuid])
     except:
         pass
コード例 #2
0
def error_cleanup():
    global image
    iam2_ops.clean_iam2_enviroment()
    if image:
        try:
            img_ops.delete_image(image.uuid)
        except:
            img_ops.expunge_image(image.uuid)
コード例 #3
0
def error_cleanup():
    global image_uuid, backup_storage_inventory_uuid
    if not image_uuid:
        img_ops.delete_image(image_uuid)
        img_ops.expunge_image(image_uuid)
    if not backup_storage_inventory_uuid:
        bs_ops.delete_backup_storage(backup_storage_inventory_uuid)
    test_lib.lib_error_cleanup(test_obj_dict)
コード例 #4
0
def error_cleanup():
    global image_uuid, backup_storage_inventory_uuid
    if not image_uuid:
        img_ops.delete_image(image_uuid)
        img_ops.expunge_image(image_uuid)
    if not backup_storage_inventory_uuid: 
        bs_ops.delete_backup_storage(backup_storage_inventory_uuid)
    test_lib.lib_error_cleanup(test_obj_dict)
コード例 #5
0
def error_cleanup():
    global disaster_bs_uuid
    global image_uuid
    global vm
    vm_ops.destroy_vm(vm.uuid)
    img_ops.delete_image(image_uuid)
    if disaster_bs_uuid != None:
        bs_ops.delete_backup_storage(disaster_bs_uuid)
コード例 #6
0
def error_cleanup():
    global disaster_bs_uuid
    global image_uuid
    global vm
    vm_ops.destroy_vm(vm.uuid)
    img_ops.delete_image(image_uuid)
    if disaster_bs_uuid != None:
        bs_ops.delete_backup_storage(disaster_bs_uuid)
コード例 #7
0
def error_cleanup():
    global image
    iam2_ops.clean_iam2_enviroment()
    if image:
        try:
            img_ops.delete_image(image.uuid)
        except:
            img_ops.expunge_image(image.uuid)
コード例 #8
0
def error_cleanup():
    global disaster_bs_uuid
    global data_volume_uuid
    global image_uuid
    vol_ops.delete_volume(data_volume_uuid)
    img_ops.delete_image(image_uuid)
    if disaster_bs_uuid != None:
        bs_ops.delete_backup_storage(disaster_bs_uuid)
コード例 #9
0
def error_cleanup():
    global disaster_bs_uuid
    global data_volume_uuid
    global image_uuid
    vol_ops.delete_volume(data_volume_uuid)
    img_ops.delete_image(image_uuid)
    if disaster_bs_uuid != None:
        bs_ops.delete_backup_storage(disaster_bs_uuid)
def error_cleanup():
    global vm, vm2, image_uuid
    if not image_uuid:
        img_ops.delete_image(image_uuid)
        img_ops.expunge_image(image_uuid)
    if vm:
        vm.destroy()
        vm.expunge()
def test():
    global vm, vm2, image_uuid
    test_util.test_dsc('create VM with setting password')

    for root_password in root_password_list:
        test_util.test_dsc("root_password: \"%s\"" %(root_password))
        vm = test_stub.create_vm(vm_name = 'c7-vm-no-sys-tag', image_name = "imageName_i_c7_no_tag")

        backup_storage_list = test_lib.lib_get_backup_storage_list_by_vm(vm.vm)
        for bs in backup_storage_list:
            if bs.type == inventory.IMAGE_STORE_BACKUP_STORAGE_TYPE:
                break
            if bs.type == inventory.SFTP_BACKUP_STORAGE_TYPE:
                break
            if bs.type == inventory.CEPH_BACKUP_STORAGE_TYPE:
                break
        else:
            vm.destroy()
            test_util.test_skip('Not find image store type backup storage.')

        vm.check()

        #add tag to vm
        tag_ops.create_system_tag('VmInstanceVO', vm.get_vm().uuid, "qemuga")

        vm_ops.change_vm_password(vm.get_vm().uuid, "root", root_password)

        #create image by the vm with tag
        vm_root_volume_inv = test_lib.lib_get_root_volume(vm.get_vm())
        root_volume_uuid = vm_root_volume_inv.uuid

        image_option1 = test_util.ImageOption()
        image_option1.set_root_volume_uuid(root_volume_uuid)
        image_option1.set_name('add_tag_vm_to_image')
        image_option1.set_format('qcow2')
        image_option1.set_backup_storage_uuid_list([bs.uuid])

        vm.stop()
        image = img_ops.create_root_volume_template(image_option1)

        #create vm by new image
        vm2 = test_stub.create_vm(vm_name = 'c7-vm-add-tag-from-previous-vm', image_name = "add_tag_vm_to_image")
        if not test_lib.lib_check_login_in_vm(vm2.get_vm(), "root", root_password):
            test_util.test_fail("create vm with user:%s password: %s failed", "root", root_password)

        vm_ops.change_vm_password(vm2.get_vm().uuid, "root", root_password)

        image_uuid = image.uuid
        if not image_uuid:
            img_ops.delete_image(image_uuid)
            img_ops.expunge_image(image_uuid)
            

    test_util.test_pass('add system tag on a no system tag image test passed')
コード例 #12
0
def test():
    vm1 = test_stub.create_vr_vm('vm_imagecache', 'imageName_net',
                                 'l3VlanNetwork3')
    test_obj_dict.add_vm(vm1)
    vm1.check()
    vm1.stop()
    image_creation_option = test_util.ImageOption()
    backup_storage_list = test_lib.lib_get_backup_storage_list_by_vm(
        vm1.get_vm())
    image_creation_option.set_backup_storage_uuid_list(
        [backup_storage_list[0].uuid])
    image_creation_option.set_root_volume_uuid(vm1.get_vm().rootVolumeUuid)
    image_creation_option.set_name('test_create_image_template_imagecache')

    image = test_image.ZstackTestImage()
    image.set_creation_option(image_creation_option)
    image.create()
    test_obj_dict.add_image(image)
    image.check()
    vm2 = test_stub.create_vm('vm_imagecache2',
                              'test_create_image_template_imagecache',
                              os.environ.get('l3VlanNetwork3'))
    test_obj_dict.add_vm(vm2)

    host = test_lib.lib_find_host_by_vm(vm2.get_vm())
    ps = test_lib.lib_get_primary_storage_by_vm(vm2.get_vm())
    image = test_lib.lib_get_image_by_name(
        'test_create_image_template_imagecache')
    img_ops.sync_image_size(image.uuid)
    image = test_lib.lib_get_image_by_name(
        'test_create_image_template_imagecache')
    img_ops.delete_image(image.uuid)

    if ps.type == inventory.LOCAL_STORAGE_TYPE or ps.type == inventory.NFS_PRIMARY_STORAGE_TYPE or ps.type == 'SharedMountPoint':
        image_cache_path = "%s/imagecache/template/%s/" % (ps.mountPath,
                                                           image.uuid)
        imagecache_file_size = int(
            test_lib.lib_get_file_size(host, image_cache_path))
        image_actual_size = int(image.actualSize)
        if imagecache_file_size < image.actualSize * 0.99 or imagecache_file_size > image.actualSize * 1.01:
            test_util.test_fail(
                'image cache size (%s) not match image actual size(%s)' %
                (imagecache_file_size, image_actual_size))
    else:
        test_util.test_skip(
            "Skip test when primary storage is not local or NFS")
#    elif ps.type == inventory.CEPH_PRIMARY_STORAGE_TYPE:

    test_lib.lib_error_cleanup(test_obj_dict)
    test_util.test_pass('imagecache cleanup Pass.')
def test():
    import uuid
    account_name = uuid.uuid1().get_hex()
    account_pass = uuid.uuid1().get_hex()
    account_pass = hashlib.sha512(account_name).hexdigest()
    test_account = acc_ops.create_normal_account(account_name, account_pass)
    global vm
    bs_cond = res_ops.gen_query_conditions("status", '=', "Connected")
    bss = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE,
                                        bs_cond,
                                        None,
                                        fields=['uuid'])
    if not bss:
        test_util.test_skip("not find available backup storage. Skip test")

    test_util.test_dsc('Test change vm image with quota limited')
    test_account_uuid = test_account.uuid
    #set normal account's storage capacity as 4G
    acc_ops.update_quota(test_account.uuid, "volume.capacity", "4294967296")
    test_account_session = acc_ops.login_by_account(account_name, account_pass)
    test_stub.share_admin_resource([test_account_uuid])

    vm = test_stub.create_vm(session_uuid=test_account_session)
    vm.check()
    image_option = test_util.ImageOption()
    image_option.set_name('8G')
    image_option.set_format('qcow2')
    image_option.set_url(
        "http://172.20.1.15:7480/diskimages/CentOS-7-x86_64-Cloudinit-8G-official.qcow2"
    )
    image_option.set_backup_storage_uuid_list([bss[0].uuid])
    new_image = zstack_image_header.ZstackTestImage()
    new_image.set_creation_option(image_option)
    new_image.add_root_volume_template()

    test_stub.share_admin_resource([test_account_uuid])
    vm.stop(session_uuid=test_account_session)
    image_uuid = test_lib.lib_get_image_by_name("8G").uuid
    try:
        vm_ops.change_vm_image(vm.get_vm().uuid,
                               image_uuid,
                               session_uuid=test_account_session)
    except:
        acc_ops.delete_account(test_account_uuid)
        img_ops.delete_image(test_lib.lib_get_image_by_name('8G').uuid)
        test_util.test_pass(
            'Change Vm Image With Limited Storage Quota Test Success ')
    test_util.test_fail('Overstep the limit of storage capacity')
コード例 #14
0
def test():
    global image_obj
    curr_deploy_conf = exp_ops.export_zstack_deployment_config(
        test_lib.deploy_config)

    vm_creation_option = test_util.VmOption()
    image_name = os.environ.get('imageName_net')
    image_inv = test_lib.lib_get_image_by_name(image_name)
    image_uuid = image_inv.uuid

    image_crt_opt = test_util.ImageOption()
    image_crt_opt.set_name(image_inv.name)
    image_crt_opt.set_url(image_inv.url)
    image_crt_opt.set_format(image_inv.format)
    image_crt_opt.set_system(image_inv.system)
    image_crt_opt.set_mediaType(image_inv.mediaType)
    image_crt_opt.set_guest_os_type(image_inv.type)
    bss = image_inv.backupStorageRefs
    bss_uuids = []
    for bs in bss:
        bss_uuids.append(bs.backupStorageUuid)

    image_crt_opt.set_backup_storage_uuid_list(bss_uuids)
    image_obj.set_creation_option(image_crt_opt)

    conditions = res_ops.gen_query_conditions('type', '=', 'UserVm')
    instance_offering_uuid = res_ops.query_resource(res_ops.INSTANCE_OFFERING,
                                                    conditions)[0].uuid
    vm_creation_option.set_image_uuid(image_uuid)
    vm_creation_option.set_instance_offering_uuid(instance_offering_uuid)
    vm_creation_option.set_name('multizones_basic_vm')
    vm1 = test_lib.lib_create_vm(vm_creation_option)
    test_obj_dict.add_vm(vm1)

    test_util.test_dsc('delete image')
    img_ops.delete_image(image_uuid)
    #in bug, when destroy vm after delete related image, destroy vm will fail
    test_util.test_dsc('destroy vm')
    vm1.destroy()
    test_obj_dict.rm_vm(vm1)
    test_util.test_dsc('add image back')
    image_obj.add_root_volume_template()

    test_lib.lib_robot_cleanup(test_obj_dict)
    test_util.test_pass('Delete Image Test Success')
コード例 #15
0
def test():
    global image_obj
    curr_deploy_conf = exp_ops.export_zstack_deployment_config(test_lib.deploy_config)

    vm_creation_option = test_util.VmOption()
    image_name = os.environ.get('imageName_s')
    image_inv = test_lib.lib_get_image_by_name(image_name)
    image_uuid = image_inv.uuid

    image_crt_opt = test_util.ImageOption()
    image_crt_opt.set_name(image_inv.name)
    image_crt_opt.set_url(image_inv.url)
    image_crt_opt.set_format(image_inv.format)
    image_crt_opt.set_system(image_inv.system)
    image_crt_opt.set_mediaType(image_inv.mediaType)
    image_crt_opt.set_guest_os_type(image_inv.type)
    bss = image_inv.backupStorageRefs
    bss_uuids = []
    for bs in bss:
        bss_uuids.append(bs.backupStorageUuid)

    image_crt_opt.set_backup_storage_uuid_list(bss_uuids)
    image_obj.set_creation_option(image_crt_opt)

    conditions = res_ops.gen_query_conditions('type', '=', 'UserVm')
    instance_offering_uuid = res_ops.query_resource(res_ops.INSTANCE_OFFERING, conditions)[0].uuid
    vm_creation_option.set_image_uuid(image_uuid)
    vm_creation_option.set_instance_offering_uuid(instance_offering_uuid)
    vm_creation_option.set_name('multizones_basic_vm')
    vm1 = test_lib.lib_create_vm(vm_creation_option)
    test_obj_dict.add_vm(vm1)

    test_util.test_dsc('delete image')
    img_ops.delete_image(image_uuid)
    #in bug, when destroy vm after delete related image, destroy vm will fail
    test_util.test_dsc('destroy vm')
    vm1.destroy()
    test_obj_dict.rm_vm(vm1)
    test_util.test_dsc('add image back')
    image_obj.add_root_volume_template()
    
    test_lib.lib_robot_cleanup(test_obj_dict)
    test_util.test_pass('Delete Image Test Success')
def error_cleanup():
    global vcenter_uuid1
    global vcenter_uuid2
    global mevoco2_ip
    global img_uuid
    global delete_policy1
    global delete_policy2

    test_lib.lib_set_delete_policy('image', delete_policy1)
    if img_uuid:
        img_ops.delete_image(img_uuid)
        img_ops.expunge_image(img_uuid)

    if vcenter_uuid1:
        vct_ops.delete_vcenter(vcenter_uuid1)

    if vcenter_uuid2:
        os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip
        test_lib.lib_set_delete_policy('image', delete_policy2)
        vct_ops.delete_vcenter(vcenter_uuid2)
コード例 #17
0
def error_cleanup():
    global vcenter_uuid1
    global vcenter_uuid2
    global mevoco2_ip
    global img_uuid
    global delete_policy1
    global delete_policy2

    test_lib.lib_set_delete_policy('image', delete_policy1)
    if img_uuid:
        img_ops.delete_image(img_uuid)
        img_ops.expunge_image(img_uuid)

    if vcenter_uuid1:
        vct_ops.delete_vcenter(vcenter_uuid1)

    if vcenter_uuid2:
        os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip
        test_lib.lib_set_delete_policy('image', delete_policy2)
        vct_ops.delete_vcenter(vcenter_uuid2)
def test():
   import uuid
   account_name = uuid.uuid1().get_hex()
   account_pass = uuid.uuid1().get_hex()
   account_pass = hashlib.sha512(account_name).hexdigest()
   test_account = acc_ops.create_normal_account(account_name,account_pass)
   global vm
   bs_cond = res_ops.gen_query_conditions("status", '=', "Connected")
   bss = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, bs_cond, None, fields=['uuid'])
   if not bss:
      test_util.test_skip("not find available backup storage. Skip test")

   test_util.test_dsc('Test change vm image with quota limited')
   test_account_uuid = test_account.uuid
   #set normal account's storage capacity as 4G
   acc_ops.update_quota(test_account.uuid,"volume.capacity","4294967296")
   test_account_session = acc_ops.login_by_account(account_name,account_pass)
   test_stub.share_admin_resource([test_account_uuid])

   vm = test_stub.create_vm(session_uuid = test_account_session)
   vm.check()
   image_option = test_util.ImageOption()
   image_option.set_name('8G')
   image_option.set_format('qcow2')
   image_option.set_url(os.environ.get('imageServer')+"/diskimages/CentOS-7-x86_64-Cloudinit-8G-official.qcow2")
   image_option.set_backup_storage_uuid_list([bss[0].uuid])
   new_image = zstack_image_header.ZstackTestImage()
   new_image.set_creation_option(image_option)
   new_image.add_root_volume_template()

   test_stub.share_admin_resource([test_account_uuid])
   vm.stop(session_uuid = test_account_session)
   image_uuid = test_lib.lib_get_image_by_name("8G").uuid
   try:
      vm_ops.change_vm_image(vm.get_vm().uuid,image_uuid,session_uuid = test_account_session)
   except:
      acc_ops.delete_account(test_account_uuid)
      img_ops.delete_image(test_lib.lib_get_image_by_name('8G').uuid)
      test_util.test_pass('Change Vm Image With Limited Storage Quota Test Success ')
   test_util.test_fail('Overstep the limit of storage capacity')
コード例 #19
0
def test():
    vm1 = test_stub.create_vr_vm('vm_imagecache', 'imageName_net', 'l3VlanNetwork3')
    test_obj_dict.add_vm(vm1)
    vm1.check()
    vm1.stop()
    image_creation_option = test_util.ImageOption()
    backup_storage_list = test_lib.lib_get_backup_storage_list_by_vm(vm1.get_vm())
    image_creation_option.set_backup_storage_uuid_list([backup_storage_list[0].uuid])
    image_creation_option.set_root_volume_uuid(vm1.get_vm().rootVolumeUuid)
    image_creation_option.set_name('test_create_image_template_imagecache')

    image = test_image.ZstackTestImage()
    image.set_creation_option(image_creation_option)
    image.create()
    test_obj_dict.add_image(image)
    image.check()
    vm2 = test_stub.create_vm('vm_imagecache2', 'test_create_image_template_imagecache', os.environ.get('l3VlanNetwork3'))
    test_obj_dict.add_vm(vm2)

    host = test_lib.lib_find_host_by_vm(vm2.get_vm())
    ps = test_lib.lib_get_primary_storage_by_vm(vm2.get_vm())
    image = test_lib.lib_get_image_by_name('test_create_image_template_imagecache')
    img_ops.sync_image_size(image.uuid)
    image = test_lib.lib_get_image_by_name('test_create_image_template_imagecache')
    img_ops.delete_image(image.uuid)

    if ps.type == inventory.LOCAL_STORAGE_TYPE or ps.type == inventory.NFS_PRIMARY_STORAGE_TYPE or ps.type == 'SharedMountPoint':
        image_cache_path = "%s/imagecache/template/%s/" % (ps.mountPath, image.uuid)
        imagecache_file_size = int(test_lib.lib_get_file_size(host, image_cache_path))
        image_actual_size = int(image.actualSize)
        if imagecache_file_size < image.actualSize*0.99 or imagecache_file_size > image.actualSize*1.01:
            test_util.test_fail('image cache size (%s) not match image actual size(%s)' % (imagecache_file_size, image_actual_size))
    else:
        test_util.test_skip("Skip test when primary storage is not local or NFS")
#    elif ps.type == inventory.CEPH_PRIMARY_STORAGE_TYPE:

    test_lib.lib_error_cleanup(test_obj_dict)
    test_util.test_pass('imagecache cleanup Pass.')
コード例 #20
0
def test():
    global disaster_bs_uuid
    global image_uuid
    global vm
    disasterBsUrls = os.environ.get('disasterBsUrls')
    name = 'disaster_bs'
    description = 'backup storage for disaster'
    url = '/zstack_bs'
    sshport = 22
    hostname = disasterBsUrls.split('@')[1]
    username = disasterBsUrls.split(':')[0]
    password = disasterBsUrls.split('@')[0].split(':')[1]
    test_util.test_logger('Disaster bs server hostname is %s, username is %s, password is %s' %(hostname, username, password))
    #AddDisasterImageStoreBackupStorage
    disaster_backup_storage = bs_ops.add_disaster_image_store_bs(url, hostname, username, password, sshport, name, description)
    disaster_bs_uuid = disaster_backup_storage.uuid
    #AttachBackupStorageToZone
    zone_uuid = res_ops.query_resource(res_ops.ZONE)[0].uuid
    bs_ops.attach_backup_storage(disaster_bs_uuid, zone_uuid)
    #Create vm
    primary_storage_uuid = res_ops.query_resource(res_ops.PRIMARY_STORAGE)[0].uuid
    disk_offering_uuid = res_ops.query_resource(res_ops.DISK_OFFERING)[0].uuid
    host_ip = res_ops.query_resource(res_ops.HOST)[0].managementIp
    cond = res_ops.gen_query_conditions('name', '=', os.environ.get('imageStoreBackupStorageName'))
    local_bs_uuid = res_ops.query_resource(res_ops.BACKUP_STORAGE, cond)[0].uuid

    cond = res_ops.gen_query_conditions('system', '=', False)
    l3network_uuid = res_ops.query_resource(res_ops.L3_NETWORK, cond)[0].uuid
    cond = res_ops.gen_query_conditions('type', '=', 'UserVm')
    instance_offering_uuid = res_ops.query_resource(res_ops.INSTANCE_OFFERING, cond)[0].uuid
    cond = res_ops.gen_query_conditions('backupStorage.uuid', '=', local_bs_uuid)
    cond = res_ops.gen_query_conditions('name', '=', 'other', cond)
    image_uuid = res_ops.query_resource(res_ops.IMAGE, cond)[0].uuid
    vm_option = test_util.VmOption()
    vm_option.set_instance_offering_uuid(instance_offering_uuid)
    vm_option.set_name('vm_for_data_protect_test')
    vm_option.set_l3_uuids([l3network_uuid])
    vm_option.set_image_uuid(image_uuid)
    vm = vm_ops.create_vm(vm_option)
    #CreateRootVolumeTemplateFromRootVolume
    root_volume_uuid = vm.rootVolumeUuid 
    image_option = test_util.ImageOption()
    image_option.set_root_volume_uuid(root_volume_uuid)
    image_option.set_name('create_root_image_to_image_store')
    image_option.set_backup_storage_uuid_list([disaster_bs_uuid])
    image = img_ops.create_root_volume_template(image_option)
    disaster_bs_image_uuid = image.uuid
    #Check if the system tag of the image in disaster bs is 'remote'
    cond = res_ops.gen_query_conditions('resourceUuid', '=', disaster_bs_image_uuid)
    system_tag = res_ops.query_resource(res_ops.SYSTEM_TAG, cond)[0]
    if system_tag.tag != "remote":
        test_util.test_fail("Here isn't 'remote' system tag for image in data protect bs")
    #Check if the image's media_type correct
    cond = res_ops.gen_query_conditions('uuid', '=', disaster_bs_image_uuid)
    media_type = res_ops.query_resource(res_ops.IMAGE, cond)[0].mediaType
    if media_type != 'RootVolumeTemplate':
        test_util.test_fail('Wrong image type, the expect is "RootVolumeTemplate", the real is "%s"' %media_type) 
    #Check recovery root volume
    recovery_image = img_ops.recovery_image_from_image_store_backup_storage(local_bs_uuid, disaster_bs_uuid, disaster_bs_image_uuid) 
    #Check the process status when recoverying image
    cond = res_ops.gen_query_conditions('resourceUuid', '=', local_bs_uuid)
    system_tag = res_ops.query_resource(res_ops.SYSTEM_TAG, cond)[0].tag
    status = system_tag.split('::')[7]
    if status not in ['running', 'success']:
        test_util.test_fail('Error status for recovery image, status: %s' %status)
    #Check if recovery root volume success
    if recovery_image.backupStorageRefs[0].backupStorageUuid != local_bs_uuid:
        test_util.test_fail('Recovery image failed, image uuid is %s' %recovery_image.uuid)
    if recovery_image.mediaType != 'RootVolumeTemplate':
        test_util.test_fail('Wrong image type after recovery, the expect is "RootVolumeTemplate", the real is "%s"' %recovery_image.mediaType)
    image_uuid = recovery_image.uuid

    try:
        #Try to recovery the same image again, it's negative test
        recovery_image = img_ops.recovery_image_from_image_store_backup_storage(local_bs_uuid, disaster_bs_uuid, disaster_bs_image_uuid)
        img_ops.delete_image(recovery_image.uuid)
    except Exception,e:
        if unicode(e).encode("utf-8").find('包含') != -1:
            test_util.test_pass('Try to recovery the same image again and get the error info expectly: %s' %unicode(e).encode("utf-8"))
コード例 #21
0
    if system_tag.tag != "remote":
        test_util.test_fail("Here isn't 'remote' system tag for image in data protect bs")
    #Check if GetImagesFromImageStoreBackupStorage works well
    #disaster_bs_image_lst = img_ops.get_images_from_image_store_backup_storage(disaster_bs_uuid)
    #if disaster_bs_image_lst.infos == []:
    #    test_util.test_fail('GetImagesFromImageStoreBackupStorage unable to list the images in disaster bs')
    #Try to sync the same image again, it's negative test
    try:
        image_uuid = img_ops.sync_image_from_image_store_backup_storage(disaster_bs_uuid, local_bs_uuid, image_uuid_local)
    except Exception,e:
        if unicode(e).encode("utf-8").find('包含') != -1:
            test_util.test_logger('Try to sync the image which had exist in disaster bs get the error info expectly: %s' %unicode(e).encode("utf-8"))
    else:
        test_util.test_fail('Try to sync the image which had exist in local bs success unexpectly')
    #Delete local image and recovery from disaster bs
    img_ops.delete_image(image_uuid_local)
    img_ops.expunge_image(image_uuid_local)
    recovery_image = img_ops.recovery_image_from_image_store_backup_storage(local_bs_uuid, disaster_bs_uuid, disaster_bs_image_uuid, 'other')
    image_uuid_recovery = recovery_image.uuid
    #Check the process status when recoverying image
    cond = res_ops.gen_query_conditions('resourceUuid', '=', local_bs_uuid)
    system_tag = res_ops.query_resource(res_ops.SYSTEM_TAG, cond)[0].tag
    status = system_tag.split('::')[7]
    if status not in ['running', 'success']:
        test_util.test_fail('Error status for recovery image, status: %s' %status)
    #Check if recovery image success
    if recovery_image.backupStorageRefs[0].backupStorageUuid != local_bs_uuid:
        test_util.test_fail('Recovery image failed, image uuid is %s' %recovery_image.uuid)
    if recovery_image.mediaType != 'RootVolumeTemplate':
        test_util.test_fail('Wrong image media type after recovery, the expect is "RootVolumeTemplate", the real is "%s"' %media_type)
 
コード例 #22
0
    if recovery_image.backupStorageRefs[0].backupStorageUuid != local_bs_uuid:
        test_util.test_fail('Recovery image failed, image uuid is %s' %recovery_image.uuid)
    if recovery_image.mediaType != 'RootVolumeTemplate':
        test_util.test_fail('Wrong image type after recovery, the expect is "RootVolumeTemplate", the real is "%s"' %recovery_image.mediaType)
    image_uuid = recovery_image.uuid

    try:
        #Try to recovery the same image again, it's negative test
        recovery_image = img_ops.recovery_image_from_image_store_backup_storage(local_bs_uuid, disaster_bs_uuid, disaster_bs_image_uuid)
        img_ops.delete_image(recovery_image.uuid)
    except Exception,e:
        if unicode(e).encode("utf-8").find('包含') != -1:
            test_util.test_pass('Try to recovery the same image again and get the error info expectly: %s' %unicode(e).encode("utf-8"))
    finally:
        vm_ops.destroy_vm(vm.uuid)
        img_ops.delete_image(image_uuid)
    test_util.test_fail('Try to recovery the same image second time success unexpectly')

#Will be called only if exception happens in test().
def error_cleanup():
    global disaster_bs_uuid
    global image_uuid
    global vm
    vm_ops.destroy_vm(vm.uuid)
    img_ops.delete_image(image_uuid)
    if disaster_bs_uuid != None:
        bs_ops.delete_backup_storage(disaster_bs_uuid)
    
#recover envrionment wehether the test pass or not
def env_recover():
    global disaster_bs_uuid
コード例 #23
0
def test():
    global image1
    global test_obj_dict

    #run condition
    hosts = res_ops.query_resource(res_ops.HOST)
    if len(hosts) <= 1:
        test_util.test_skip(
            "skip for host_num is not satisfy condition host_num>1")

    bs_cond = res_ops.gen_query_conditions("status", '=', "Connected")
    bss = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE,
                                        bs_cond,
                                        None,
                                        fields=['uuid'])

    image_name1 = 'image1_a'
    image_option = test_util.ImageOption()
    image_option.set_format('qcow2')
    image_option.set_name(image_name1)
    # image_option.set_system_tags('qemuga')
    image_option.set_mediaType('RootVolumeTemplate')
    image_option.set_url(os.environ.get('imageUrl_s'))
    image_option.set_backup_storage_uuid_list([bss[0].uuid])
    image_option.set_timeout(3600 * 1000)

    image1 = zstack_image_header.ZstackTestImage()
    image1.set_creation_option(image_option)
    image1.add_root_volume_template()
    image1.check()
    test_obj_dict.add_image(image1)

    image_name = os.environ.get('imageName_net')
    l3_name = os.environ.get('l3VlanNetworkName1')
    vm1 = test_stub.create_vm(image_name1, image_name, l3_name)
    test_obj_dict.add_vm(vm1)

    #create data volume
    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('volume1')
    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.check()
    volume.attach(vm1)
    volume.detach()
    # dvol ops test
    test_stub.dvol_ops_test(volume.volume, vm1, "DVOL_TEST_ALL")
    volume.attach(vm1)

    #create data volume from template
    image_option2 = test_util.ImageOption()
    image_option2.set_data_volume_uuid(volume.volume.uuid)
    image_option2.set_name('data_template')
    image_option2.set_backup_storage_uuid_list([bss[0].uuid])
    vol_image = img_ops.create_data_volume_template(image_option2)
    #export vol template
    if bss[0].type in [inventory.IMAGE_STORE_BACKUP_STORAGE_TYPE]:
        img_ops.export_image_from_backup_storage(vol_image.uuid, bss[0].uuid)
    target_host = test_lib.lib_find_host_by_vm(vm1.vm)
    volume2 = vol_ops.create_volume_from_template(
        vol_image.uuid,
        volume.volume.primaryStorageUuid,
        host_uuid=target_host.uuid)

    #del data volume template
    img_ops.delete_image(vol_image.uuid)

    # dvol ops test
    test_stub.dvol_ops_test(volume2, vm1, "DVOL_TEST_ALL")

    #expunge data volume template
    img_ops.expunge_image(vol_image.uuid)

    # dvol ops test
    test_stub.dvol_ops_test(volume2, vm1, "DVOL_TEST_ALL")

    test_lib.lib_robot_cleanup(test_obj_dict)
    test_util.test_pass('deleting and expunge vol image check vol ops Success')
コード例 #24
0
def test():
    global project_uuid, project_admin_uuid, virtual_id_uuid

    # 1 create project
    project_name = 'test_project'
    project = iam2_ops.create_iam2_project(project_name)
    project_uuid = project.uuid
    project_linked_account_uuid = project.linkedAccountUuid

    # 2 create virtual id
    project_admin_name = 'username'
    project_admin_password = '******'
    project_admin_uuid = iam2_ops.create_iam2_virtual_id(project_admin_name, project_admin_password).uuid
    virtual_id_uuid = iam2_ops.create_iam2_virtual_id('usernametwo', 'password').uuid

    # 3 create project admin
    iam2_ops.add_iam2_virtual_ids_to_project([project_admin_uuid],project_uuid)
    attributes = [{"name": "__ProjectAdmin__", "value": project_uuid}]
    iam2_ops.add_attributes_to_iam2_virtual_id(project_admin_uuid, attributes)

    # 4 login in project by project admin
    project_admin_session_uuid = iam2_ops.login_iam2_virtual_id(project_admin_name, project_admin_password)
    project_login_uuid = iam2_ops.login_iam2_project(project_name, session_uuid=project_admin_session_uuid).uuid
    # iam2_ops.remove_attributes_from_iam2_virtual_id(virtual_id_uuid, attributes)


    # Image related ops: Add, Delete, Expunge, sync image size, Update QGA, delete, expunge
    bs = res_ops.query_resource(res_ops.BACKUP_STORAGE)[0]
    image_option = test_util.ImageOption()
    image_option.set_name('fake_image')
    image_option.set_description('fake image')
    image_option.set_format('raw')
    image_option.set_mediaType('RootVolumeTemplate')
    image_option.set_backup_storage_uuid_list([bs.uuid])
    image_option.url = "http://fake/fake.raw"
    image_option.set_session_uuid(project_login_uuid)
    image_uuid = img_ops.add_image(image_option).uuid
    img_ops.sync_image_size(image_uuid, session_uuid=project_login_uuid)
    img_ops.change_image_state(image_uuid, 'disable', session_uuid=project_login_uuid)
    img_ops.change_image_state(image_uuid, 'enable', session_uuid=project_login_uuid)
    if bs.type == inventory.IMAGE_STORE_BACKUP_STORAGE_TYPE:
        img_ops.export_image_from_backup_storage(image_uuid, bs.uuid, session_uuid=project_login_uuid)
        img_ops.delete_exported_image_from_backup_storage(image_uuid, bs.uuid, session_uuid=project_login_uuid)
    img_ops.set_image_qga_enable(image_uuid, session_uuid=project_login_uuid)
    img_ops.set_image_qga_disable(image_uuid, session_uuid=project_login_uuid)
    img_ops.delete_image(image_uuid, session_uuid=project_login_uuid)
    img_ops.expunge_image(image_uuid, session_uuid=project_login_uuid)

    # Volume related ops: Create, Delete, Expunge, Attach, Dettach, Enable, Disable
    disk_offering_uuid = res_ops.query_resource(res_ops.DISK_OFFERING)[0].uuid
    acc_ops.share_resources([project_linked_account_uuid], [disk_offering_uuid])
    volume_option = test_util.VolumeOption()
    volume_option.set_disk_offering_uuid(disk_offering_uuid)
    volume_option.set_name('data_volume_project_management')
    volume_option.set_session_uuid(project_login_uuid)
    data_volume = vol_ops.create_volume_from_offering(volume_option)
    vol_ops.stop_volume(data_volume.uuid, session_uuid=project_login_uuid)
    vol_ops.start_volume(data_volume.uuid, session_uuid=project_login_uuid)
    vm_creation_option = test_util.VmOption()
    l3_net_uuid = test_lib.lib_get_l3_by_name(os.environ.get('l3VlanNetwork3')).uuid
    acc_ops.share_resources([project_linked_account_uuid], [l3_net_uuid])
    vm_creation_option.set_l3_uuids([l3_net_uuid])
    image_uuid = test_lib.lib_get_image_by_name("centos").uuid
    vm_creation_option.set_image_uuid(image_uuid)
    acc_ops.share_resources([project_linked_account_uuid], [image_uuid])
    instance_offering_uuid = test_lib.lib_get_instance_offering_by_name(os.environ.get('instanceOfferingName_s')).uuid
    vm_creation_option.set_instance_offering_uuid(instance_offering_uuid)
    acc_ops.share_resources([project_linked_account_uuid], [instance_offering_uuid])
    vm_creation_option.set_name('vm_for_project_management')
    vm_creation_option.set_session_uuid(project_login_uuid)
    vm = test_stub.create_vm(image_uuid = image_uuid, session_uuid=project_login_uuid) 
    vm_uuid = vm.get_vm().uuid
    vol_ops.attach_volume(data_volume.uuid, vm_uuid, session_uuid=project_login_uuid)
    vol_ops.detach_volume(data_volume.uuid, vm_uuid, session_uuid=project_login_uuid)
    vol_ops.delete_volume(data_volume.uuid, session_uuid=project_login_uuid)
    vol_ops.expunge_volume(data_volume.uuid, session_uuid=project_login_uuid)

    # VM related ops: Create, Delete, Expunge, Start, Stop, Suspend, Resume, Migrate
    vm_ops.stop_vm(vm_uuid, session_uuid=project_login_uuid)
    vm_ops.start_vm(vm_uuid, session_uuid=project_login_uuid)
    candidate_hosts = vm_ops.get_vm_migration_candidate_hosts(vm_uuid)
    if candidate_hosts != None and test_lib.lib_check_vm_live_migration_cap(vm.get_vm()):
        vm_ops.migrate_vm(vm_uuid, candidate_hosts.inventories[0].uuid, session_uuid=project_login_uuid)
    vm_ops.stop_vm(vm_uuid, force='cold', session_uuid=project_login_uuid)
    vm_ops.start_vm(vm_uuid, session_uuid=project_login_uuid)
    vm_ops.suspend_vm(vm_uuid, session_uuid=project_login_uuid)
    vm_ops.resume_vm(vm_uuid, session_uuid=project_login_uuid)
    vm_ops.destroy_vm(vm_uuid, session_uuid=project_login_uuid)
    vm_ops.expunge_vm(vm_uuid, session_uuid=project_login_uuid)

    # L2 related ops: create, delete
    zone_uuid = res_ops.get_resource(res_ops.ZONE)[0].uuid
    try:
        l2 = net_ops.create_l2_novlan('l2_for_pm', 'eth0', zone_uuid, session_uuid=project_login_uuid)
        test_util.test_fail("Expect exception: project admin not allowed to create Novlan L2 except vxlan")
    except:
        pass

    try:
        l2 = net_ops.create_l2_vlan('l2_for_pm', 'eth0', zone_uuid, 1234, session_uuid=project_login_uuid)
        test_util.test_fail("Expect exception: project admin not allowed to create vlan L2 except vxlan")
    except:
        pass

    #net_ops.delete_l2(l2.uuid, session_uuid=project_login_uuid)

    # L3 related ops:

    # network service ops:

    # zwatch ops:

    # scheduler ops:

    # certificate

    # 11 delete
    acc_ops.logout(project_login_uuid)
    iam2_ops.delete_iam2_virtual_id(virtual_id_uuid)
    iam2_ops.delete_iam2_virtual_id(project_admin_uuid)
    iam2_ops.delete_iam2_project(project_uuid)
    iam2_ops.expunge_iam2_project(project_uuid)

    test_util.test_pass('success test iam2 login in by project admin!')
コード例 #25
0
def test():
    global project_uuid, project_admin_uuid, virtual_id_uuid, project_operator_uuid, plain_user_uuid

    flavor = case_flavor[os.environ.get('CASE_FLAVOR')]
    # 1 create project
    project_name = 'test_project'
    project = iam2_ops.create_iam2_project(project_name)
    project_uuid = project.uuid
    project_linked_account_uuid = project.linkedAccountUuid

    if flavor['target_role'] == 'project_admin':
        # 2 create virtual id
        project_admin_name = 'username'
        project_admin_password = '******'
        project_admin_uuid = iam2_ops.create_iam2_virtual_id(
            project_admin_name, project_admin_password).uuid
        virtual_id_uuid = iam2_ops.create_iam2_virtual_id(
            'usernametwo', 'password').uuid

        # 3 create project admin
        iam2_ops.add_iam2_virtual_ids_to_project([project_admin_uuid],
                                                 project_uuid)
        attributes = [{"name": "__ProjectAdmin__", "value": project_uuid}]
        iam2_ops.add_attributes_to_iam2_virtual_id(project_admin_uuid,
                                                   attributes)

        # login in project by project admin
        project_admin_session_uuid = iam2_ops.login_iam2_virtual_id(
            project_admin_name, project_admin_password)
        project_login_uuid = iam2_ops.login_iam2_project(
            project_name, session_uuid=project_admin_session_uuid).uuid
        # iam2_ops.remove_attributes_from_iam2_virtual_id(virtual_id_uuid, attributes)
    elif flavor['target_role'] == 'project_operator':
        project_operator_name = 'username2'
        project_operator_password = '******'
        attributes = [{"name": "__ProjectOperator__", "value": project_uuid}]
        project_operator_uuid = iam2_ops.create_iam2_virtual_id(
            project_operator_name,
            project_operator_password,
            attributes=attributes).uuid
        virtual_id_uuid = iam2_ops.create_iam2_virtual_id(
            'usernamethree', 'password').uuid

        # login in project by project operator
        iam2_ops.add_iam2_virtual_ids_to_project([project_operator_uuid],
                                                 project_uuid)
        project_operator_session_uuid = iam2_ops.login_iam2_virtual_id(
            project_operator_name, project_operator_password)
        project_login_uuid = iam2_ops.login_iam2_project(
            project_name, session_uuid=project_operator_session_uuid).uuid
    elif flavor['target_role'] == 'project_member':
        plain_user_name = 'username'
        plain_user_password = '******'
        plain_user_uuid = iam2_ops.create_iam2_virtual_id(
            plain_user_name, plain_user_password,
            project_uuid=project_uuid).uuid
        # 3 add virtual id to project
        iam2_ops.add_iam2_virtual_ids_to_project([plain_user_uuid],
                                                 project_uuid)

        # 4 login in project by plain user
        plain_user_session_uuid = iam2_ops.login_iam2_virtual_id(
            plain_user_name, plain_user_password)

        # 4 login in project
        #project_inv=iam2_ops.get_iam2_projects_of_virtual_id(plain_user_session_uuid)
        project_login_uuid = iam2_ops.login_iam2_project(
            project_name, plain_user_session_uuid).uuid

    # Image related ops: Add, Delete, Expunge, sync image size, Update QGA, delete, expunge
    if flavor['target_role'] == 'project_member':
        statements = [{
            "effect": "Allow",
            "actions": ["org.zstack.header.image.**"]
        }, {
            "effect": "Allow",
            "actions": ["org.zstack.header.storage.backup.**"]
        }]
        role_uuid = iam2_ops.create_role('test_role', statements).uuid
        iam2_ops.add_roles_to_iam2_virtual_id([role_uuid], plain_user_uuid)
    bs = res_ops.query_resource(res_ops.BACKUP_STORAGE)[0]
    image_option = test_util.ImageOption()
    image_option.set_name('fake_image')
    image_option.set_description('fake image')
    image_option.set_format('raw')
    image_option.set_mediaType('RootVolumeTemplate')
    image_option.set_backup_storage_uuid_list([bs.uuid])
    image_option.url = "http://fake/fake.raw"
    image_option.set_session_uuid(project_login_uuid)
    image_uuid = img_ops.add_image(image_option).uuid
    img_ops.sync_image_size(image_uuid, session_uuid=project_login_uuid)
    img_ops.change_image_state(image_uuid,
                               'disable',
                               session_uuid=project_login_uuid)
    img_ops.change_image_state(image_uuid,
                               'enable',
                               session_uuid=project_login_uuid)
    if bs.type == inventory.IMAGE_STORE_BACKUP_STORAGE_TYPE:
        img_ops.export_image_from_backup_storage(
            image_uuid, bs.uuid, session_uuid=project_login_uuid)
        img_ops.delete_exported_image_from_backup_storage(
            image_uuid, bs.uuid, session_uuid=project_login_uuid)
    img_ops.set_image_qga_enable(image_uuid, session_uuid=project_login_uuid)
    img_ops.set_image_qga_disable(image_uuid, session_uuid=project_login_uuid)
    cond = res_ops.gen_query_conditions('name', '=', "fake_image")
    image = res_ops.query_resource(res_ops.IMAGE,
                                   cond,
                                   session_uuid=project_login_uuid)
    if image == None:
        test_util.test_fail('fail to query image just added')
    img_ops.delete_image(image_uuid, session_uuid=project_login_uuid)
    img_ops.expunge_image(image_uuid, session_uuid=project_login_uuid)

    # 11 delete
    acc_ops.logout(project_login_uuid)
    if virtual_id_uuid != None:
        iam2_ops.delete_iam2_virtual_id(virtual_id_uuid)
    if project_admin_uuid != None:
        iam2_ops.delete_iam2_virtual_id(project_admin_uuid)
    if project_operator_uuid != None:
        iam2_ops.delete_iam2_virtual_id(project_operator_uuid)
    if plain_user_uuid != None:
        iam2_ops.delete_iam2_virtual_id(plain_user_uuid)

    iam2_ops.delete_iam2_project(project_uuid)
    iam2_ops.expunge_iam2_project(project_uuid)

    test_util.test_pass('success test iam2 login in by project admin!')
def test():
    global image1
    global test_obj_dict

    #run condition
    hosts = res_ops.query_resource(res_ops.HOST)
    if len(hosts) <= 1:
        test_util.test_skip("skip for host_num is not satisfy condition host_num>1")

    cond = res_ops.gen_query_conditions("status", '=', "Connected")
    ps = res_ops.query_resource_fields(res_ops.PRIMARY_STORAGE, cond, None, fields=['uuid'])
    bss = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, cond, None, fields=['uuid'])

    # add iso and create vm from iso
    iso = test_stub.add_test_minimal_iso('minimal_iso')
    test_obj_dict.add_image(iso)
    root_volume_offering = test_stub.add_test_root_volume_offering('root-disk-iso', 10737418240)
    test_obj_dict.add_disk_offering(root_volume_offering)
    vm_offering = test_stub.add_test_vm_offering(2, 2147483648, 'iso-vm-offering')
    test_obj_dict.add_instance_offering(vm_offering)
    vm = test_stub.create_vm_with_iso_for_test(vm_offering.uuid, iso.image.uuid, root_volume_offering.uuid, 'iso-vm')
    test_obj_dict.add_vm(vm)

    #check vm
    vm_inv = vm.get_vm()
    test_lib.lib_set_vm_host_l2_ip(vm_inv)
    test_lib.lib_wait_target_up(vm.get_vm().vmNics[0].ip, 22, 1800)

    #add data volume template
    template_option = test_util.ImageOption()
    template_option.set_name('data-volume-template')
    template_option.set_backup_storage_uuid_list([bss[0].uuid])
    template_option.set_format('qcow2')
    template_option.set_url('http://192.168.200.100/mirror/diskimages/data_volume_image_chunli_200M-4M.qcow2')
    template_inv = img_ops.add_data_volume_template(template_option)
    template = test_image.ZstackTestImage()
    template.set_image(template_inv)
    template.set_creation_option(template_option)
    test_obj_dict.add_image(template)

    #export vol template
    if bss[0].type in [inventory.IMAGE_STORE_BACKUP_STORAGE_TYPE]:
        img_ops.export_image_from_backup_storage(template.image.uuid, bss[0].uuid)
    #create data volume from template
    target_host = test_lib.lib_find_host_by_vm(vm.vm)
    volume = vol_ops.create_volume_from_template(template.image.uuid, ps[0].uuid,
                                                  host_uuid=target_host.uuid)
    # create template from data volume
    template_option2 = test_util.ImageOption()
    template_option2.set_data_volume_uuid(volume.uuid)
    template_option2.set_name('data-template-from-vol')
    template_option2.set_backup_storage_uuid_list([bss[0].uuid])
    template2 = img_ops.create_data_volume_template(template_option2)
    #export vol template
    if bss[0].type in [inventory.IMAGE_STORE_BACKUP_STORAGE_TYPE]:
        img_ops.export_image_from_backup_storage(template2.uuid, bss[0].uuid)
    volume2 = vol_ops.create_volume_from_template(template2.uuid, volume.primaryStorageUuid, host_uuid = target_host.uuid)

    #del data volume template
    img_ops.delete_image(template2.uuid)

    # dvol ops test
    test_stub.dvol_ops_test(volume2, vm, "DVOL_TEST_ALL")

    #expunge data volume template
    img_ops.expunge_image(template2.uuid)

    # dvol ops test
    test_stub.dvol_ops_test(volume2, vm, "DVOL_TEST_ALL")

    test_lib.lib_robot_cleanup(test_obj_dict)
    test_util.test_pass('deleting and expunge vol image check vol ops Success')
コード例 #27
0
def test():
    global project_uuid, project_admin_uuid, virtual_id_uuid

    # 1 create project
    project_name = 'test_project'
    project = iam2_ops.create_iam2_project(project_name)
    project_uuid = project.uuid
    project_linked_account_uuid = project.linkedAccountUuid

    # 2 create virtual id
    project_admin_name = 'username'
    project_admin_password = '******'
    project_admin_uuid = iam2_ops.create_iam2_virtual_id(
        project_admin_name, project_admin_password).uuid
    virtual_id_uuid = iam2_ops.create_iam2_virtual_id('usernametwo',
                                                      'password').uuid

    # 3 create project admin
    iam2_ops.add_iam2_virtual_ids_to_project([project_admin_uuid],
                                             project_uuid)
    attributes = [{"name": "__ProjectAdmin__", "value": project_uuid}]
    iam2_ops.add_attributes_to_iam2_virtual_id(project_admin_uuid, attributes)

    # 4 login in project by project admin
    project_admin_session_uuid = iam2_ops.login_iam2_virtual_id(
        project_admin_name, project_admin_password)
    project_login_uuid = iam2_ops.login_iam2_project(
        project_name, session_uuid=project_admin_session_uuid).uuid
    # iam2_ops.remove_attributes_from_iam2_virtual_id(virtual_id_uuid, attributes)

    # Image related ops: Add, Delete, Expunge, sync image size, Update QGA, delete, expunge
    bs = res_ops.query_resource(res_ops.BACKUP_STORAGE)[0]
    image_option = test_util.ImageOption()
    image_option.set_name('fake_image')
    image_option.set_description('fake image')
    image_option.set_format('raw')
    image_option.set_mediaType('RootVolumeTemplate')
    image_option.set_backup_storage_uuid_list([bs.uuid])
    image_option.url = "http://fake/fake.raw"
    image_option.set_session_uuid(project_login_uuid)
    image_uuid = img_ops.add_image(image_option).uuid
    img_ops.sync_image_size(image_uuid, session_uuid=project_login_uuid)
    img_ops.change_image_state(image_uuid,
                               'disable',
                               session_uuid=project_login_uuid)
    img_ops.change_image_state(image_uuid,
                               'enable',
                               session_uuid=project_login_uuid)
    if bs.type == inventory.IMAGE_STORE_BACKUP_STORAGE_TYPE:
        img_ops.export_image_from_backup_storage(
            image_uuid, bs.uuid, session_uuid=project_login_uuid)
        img_ops.delete_exported_image_from_backup_storage(
            image_uuid, bs.uuid, session_uuid=project_login_uuid)
    img_ops.set_image_qga_enable(image_uuid, session_uuid=project_login_uuid)
    img_ops.set_image_qga_disable(image_uuid, session_uuid=project_login_uuid)
    img_ops.delete_image(image_uuid, session_uuid=project_login_uuid)
    img_ops.expunge_image(image_uuid, session_uuid=project_login_uuid)

    # Volume related ops: Create, Delete, Expunge, Attach, Dettach, Enable, Disable
    disk_offering_uuid = res_ops.query_resource(res_ops.DISK_OFFERING)[0].uuid
    acc_ops.share_resources([project_linked_account_uuid],
                            [disk_offering_uuid])
    volume_option = test_util.VolumeOption()
    volume_option.set_disk_offering_uuid(disk_offering_uuid)
    volume_option.set_name('data_volume_project_management')
    volume_option.set_session_uuid(project_login_uuid)
    data_volume = vol_ops.create_volume_from_offering(volume_option)
    vol_ops.stop_volume(data_volume.uuid, session_uuid=project_login_uuid)
    vol_ops.start_volume(data_volume.uuid, session_uuid=project_login_uuid)
    vm_creation_option = test_util.VmOption()
    l3_net_uuid = test_lib.lib_get_l3_by_name(
        os.environ.get('l3VlanNetwork3')).uuid
    acc_ops.share_resources([project_linked_account_uuid], [l3_net_uuid])
    vm_creation_option.set_l3_uuids([l3_net_uuid])
    image_uuid = test_lib.lib_get_image_by_name("centos").uuid
    vm_creation_option.set_image_uuid(image_uuid)
    acc_ops.share_resources([project_linked_account_uuid], [image_uuid])
    instance_offering_uuid = test_lib.lib_get_instance_offering_by_name(
        os.environ.get('instanceOfferingName_s')).uuid
    vm_creation_option.set_instance_offering_uuid(instance_offering_uuid)
    acc_ops.share_resources([project_linked_account_uuid],
                            [instance_offering_uuid])
    vm_creation_option.set_name('vm_for_project_management')
    vm_creation_option.set_session_uuid(project_login_uuid)
    vm = test_stub.create_vm(image_uuid=image_uuid,
                             session_uuid=project_login_uuid)
    vm_uuid = vm.get_vm().uuid
    vol_ops.attach_volume(data_volume.uuid,
                          vm_uuid,
                          session_uuid=project_login_uuid)
    vol_ops.detach_volume(data_volume.uuid,
                          vm_uuid,
                          session_uuid=project_login_uuid)
    vol_ops.delete_volume(data_volume.uuid, session_uuid=project_login_uuid)
    vol_ops.expunge_volume(data_volume.uuid, session_uuid=project_login_uuid)

    # VM related ops: Create, Delete, Expunge, Start, Stop, Suspend, Resume, Migrate
    vm_ops.stop_vm(vm_uuid, session_uuid=project_login_uuid)
    vm_ops.start_vm(vm_uuid, session_uuid=project_login_uuid)
    candidate_hosts = vm_ops.get_vm_migration_candidate_hosts(vm_uuid)
    if candidate_hosts != None and test_lib.lib_check_vm_live_migration_cap(
            vm.get_vm()):
        vm_ops.migrate_vm(vm_uuid,
                          candidate_hosts.inventories[0].uuid,
                          session_uuid=project_login_uuid)
    vm_ops.stop_vm(vm_uuid, force='cold', session_uuid=project_login_uuid)
    vm_ops.start_vm(vm_uuid, session_uuid=project_login_uuid)
    vm_ops.suspend_vm(vm_uuid, session_uuid=project_login_uuid)
    vm_ops.resume_vm(vm_uuid, session_uuid=project_login_uuid)
    vm_ops.destroy_vm(vm_uuid, session_uuid=project_login_uuid)
    vm_ops.expunge_vm(vm_uuid, session_uuid=project_login_uuid)

    # L2 related ops: create, delete
    zone_uuid = res_ops.get_resource(res_ops.ZONE)[0].uuid
    try:
        l2 = net_ops.create_l2_novlan('l2_for_pm',
                                      'eth0',
                                      zone_uuid,
                                      session_uuid=project_login_uuid)
        test_util.test_fail(
            "Expect exception: project admin not allowed to create Novlan L2 except vxlan"
        )
    except:
        pass

    try:
        l2 = net_ops.create_l2_vlan('l2_for_pm',
                                    'eth0',
                                    zone_uuid,
                                    1234,
                                    session_uuid=project_login_uuid)
        test_util.test_fail(
            "Expect exception: project admin not allowed to create vlan L2 except vxlan"
        )
    except:
        pass

    #net_ops.delete_l2(l2.uuid, session_uuid=project_login_uuid)

    # L3 related ops:

    # network service ops:

    # zwatch ops:

    # scheduler ops:

    # certificate

    # 11 delete
    acc_ops.logout(project_login_uuid)
    iam2_ops.delete_iam2_virtual_id(virtual_id_uuid)
    iam2_ops.delete_iam2_virtual_id(project_admin_uuid)
    iam2_ops.delete_iam2_project(project_uuid)
    iam2_ops.expunge_iam2_project(project_uuid)

    test_util.test_pass('success test iam2 login in by project admin!')
コード例 #28
0
def test():
    test_util.test_dsc('Test Change VM Image Function')
    #set overProvisioning.primaryStorage's value as 10
    con_ops.change_global_config('mevoco', 'overProvisioning.primaryStorage',
                                 10)
    global vm
    bs_cond = res_ops.gen_query_conditions("status", "=", "Connected")
    bss = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE,
                                        bs_cond,
                                        None,
                                        fields=['uuid'])
    if not bss:
        test_util.test_skip("not find available backup storage.Skip test")
    test_lib.lib_create_disk_offering(diskSize=1099511627776, name="1T")
    disk_offering_uuids = [
        test_lib.lib_get_disk_offering_by_name("smallDiskOffering").uuid,
        test_lib.lib_get_disk_offering_by_name("root-disk").uuid,
        test_lib.lib_get_disk_offering_by_name("1T").uuid
    ]
    #create vm with 3 data volumes
    vm = test_stub.create_vm(image_name="ttylinux",
                             vm_name="test-vm",
                             disk_offering_uuids=disk_offering_uuids)
    test_obj_dict.add_vm(vm)
    vm.check()

    vm_uuid = vm.get_vm().uuid
    last_data_volumes_uuids = []
    last_data_volumes = test_lib.lib_get_data_volumes(vm.get_vm())
    for data_volume in last_data_volumes:
        last_data_volumes_uuids.append(data_volume.uuid)
    last_l3network_uuid = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm())
    last_primarystorage_uuid = test_lib.lib_get_root_volume(
        vm.get_vm()).primaryStorageUuid
    vm_ops.stop_vm(vm_uuid)
    image_option = test_util.ImageOption()
    image_option.set_name('windows_for_test')
    image_option.set_format('qcow2')
    image_option.set_mediaType('RootVolumeTemplate')
    image_option.set_platform('windows')
    image_option.set_url(
        'http://172.20.1.16:7480/diskimages/windows-telnet.qcow2')
    image_option.set_backup_storage_uuid_list([bss[0].uuid])
    image_option.set_timeout(1800 * 1000)
    new_image = zstack_image_header.ZstackTestImage()
    new_image.set_creation_option(image_option)
    new_image.add_root_volume_template()

    image_windows_uuid = test_lib.lib_get_image_by_name(
        "windows_for_test").uuid
    vm_ops.change_vm_image(vm_uuid, image_windows_uuid)
    vm_ops.start_vm(vm_uuid)
    vm.update()
    vm_ip = vm.get_vm().vmNics[0].ip
    #check whether the windows vm is running successfully
    if not test_lib.lib_wait_target_up(vm_ip, '23', 1200):
        test_util.test_fail(
            'vm:%s is not startup in 1200 seconds.Fail to reboot it.' %
            vm_uuid)
    #check whether data volumes attached to the vm has changed
    data_volumes_after_uuids = []
    data_volumes_after = test_lib.lib_get_data_volumes(vm.get_vm())
    for data_volume in data_volumes_after:
        data_volumes_after_uuids.append(data_volume.uuid)
    if set(last_data_volumes_uuids) != set(data_volumes_after_uuids):
        test_util.test_fail('Change Vm Image Failed.Data volumes changed.')
    #check whether the network config has changed
    l3network_uuid_after = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm())
    if l3network_uuid_after != last_l3network_uuid:
        test_util.test_fail(
            'Change VM Image Failed.The Network config has changed.')
    #check whether primarystorage has changed
    primarystorage_uuid_after = test_lib.lib_get_root_volume(
        vm.get_vm()).primaryStorageUuid
    if primarystorage_uuid_after != last_primarystorage_uuid:
        test_util.test_fail(
            'Change VM Image Failed.Primarystorage has changed.')
    #check whether the linux vm is running successfully
    image_linux_uuid = test_lib.lib_get_image_by_name("image_for_sg_test").uuid
    vm_ops.stop_vm(vm_uuid)
    vm_ops.change_vm_image(vm_uuid, image_linux_uuid)
    vm_ops.start_vm(vm_uuid)
    if not test_lib.lib_wait_target_up(vm_ip, '22', 120):
        test_util.test_fail(
            'vm:%s is not startup in 120 seconds.Fail to reboot it.' % vm_uuid)
    #check whether data volumes attached to the vm has changed
    data_volumes_after_uuids_linux = []
    data_volumes_after_linux = test_lib.lib_get_data_volumes(vm.get_vm())
    for data_volume in data_volumes_after_linux:
        data_volumes_after_uuids_linux.append(data_volume.uuid)
    if set(data_volumes_after_uuids) != set(data_volumes_after_uuids_linux):
        test_util.test_fail('Change Vm Image Failed.Data volumes changed.')
    #check whether the network config has changed
    l3network_uuid_after_linux = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm())
    if l3network_uuid_after != l3network_uuid_after_linux:
        test_util.test_fail(
            'Change VM Image Failed.The Network config has changed.')
    #check whether primarystorage has changed
    primarystorage_uuid_after_linux = test_lib.lib_get_root_volume(
        vm.get_vm()).primaryStorageUuid
    if primarystorage_uuid_after != primarystorage_uuid_after_linux:
        test_util.test_fail(
            'Change VM Image Failed.Primarystorage has changed.')

    test_lib.lib_destroy_vm_and_data_volumes(vm.get_vm())
    vm.expunge()
    img_ops.delete_image(image_windows_uuid)
    img_ops.expunge_image(image_windows_uuid)
    test_util.test_pass('Change Vm Image Test Success')
コード例 #29
0
def test():
    global disaster_bs_uuid
    global image_uuid
    global vm
    disasterBsUrls = os.environ.get('disasterBsUrls')
    name = 'disaster_bs'
    description = 'backup storage for disaster'
    url = '/zstack_bs'
    sshport = 22
    hostname = disasterBsUrls.split('@')[1]
    username = disasterBsUrls.split(':')[0]
    password = disasterBsUrls.split('@')[0].split(':')[1]
    test_util.test_logger(
        'Disaster bs server hostname is %s, username is %s, password is %s' %
        (hostname, username, password))
    #AddDisasterImageStoreBackupStorage
    disaster_backup_storage = bs_ops.add_disaster_image_store_bs(
        url, hostname, username, password, sshport, name, description)
    disaster_bs_uuid = disaster_backup_storage.uuid
    #AttachBackupStorageToZone
    zone_uuid = res_ops.query_resource(res_ops.ZONE)[0].uuid
    bs_ops.attach_backup_storage(disaster_bs_uuid, zone_uuid)
    #Create vm
    primary_storage_uuid = res_ops.query_resource(
        res_ops.PRIMARY_STORAGE)[0].uuid
    disk_offering_uuid = res_ops.query_resource(res_ops.DISK_OFFERING)[0].uuid
    host_ip = res_ops.query_resource(res_ops.HOST)[0].managementIp
    cond = res_ops.gen_query_conditions(
        'name', '=', os.environ.get('imageStoreBackupStorageName'))
    local_bs_uuid = res_ops.query_resource(res_ops.BACKUP_STORAGE,
                                           cond)[0].uuid

    cond = res_ops.gen_query_conditions('system', '=', False)
    l3network_uuid = res_ops.query_resource(res_ops.L3_NETWORK, cond)[0].uuid
    cond = res_ops.gen_query_conditions('type', '=', 'UserVm')
    instance_offering_uuid = res_ops.query_resource(res_ops.INSTANCE_OFFERING,
                                                    cond)[0].uuid
    cond = res_ops.gen_query_conditions('backupStorage.uuid', '=',
                                        local_bs_uuid)
    cond = res_ops.gen_query_conditions('name', '=', 'other', cond)
    image_uuid = res_ops.query_resource(res_ops.IMAGE, cond)[0].uuid
    vm_option = test_util.VmOption()
    vm_option.set_instance_offering_uuid(instance_offering_uuid)
    vm_option.set_name('vm_for_data_protect_test')
    vm_option.set_l3_uuids([l3network_uuid])
    vm_option.set_image_uuid(image_uuid)
    vm = vm_ops.create_vm(vm_option)
    #CreateRootVolumeTemplateFromRootVolume
    root_volume_uuid = vm.rootVolumeUuid
    image_option = test_util.ImageOption()
    image_option.set_root_volume_uuid(root_volume_uuid)
    image_option.set_name('create_root_image_to_image_store')
    image_option.set_backup_storage_uuid_list([disaster_bs_uuid])
    image = img_ops.create_root_volume_template(image_option)
    disaster_bs_image_uuid = image.uuid
    #Check if the system tag of the image in disaster bs is 'remote'
    cond = res_ops.gen_query_conditions('resourceUuid', '=',
                                        disaster_bs_image_uuid)
    system_tag = res_ops.query_resource(res_ops.SYSTEM_TAG, cond)[0]
    if system_tag.tag != "remote":
        test_util.test_fail(
            "Here isn't 'remote' system tag for image in data protect bs")
    #Check if the image's media_type correct
    cond = res_ops.gen_query_conditions('uuid', '=', disaster_bs_image_uuid)
    media_type = res_ops.query_resource(res_ops.IMAGE, cond)[0].mediaType
    if media_type != 'RootVolumeTemplate':
        test_util.test_fail(
            'Wrong image type, the expect is "RootVolumeTemplate", the real is "%s"'
            % media_type)
    #Check recovery root volume
    recovery_image = img_ops.recovery_image_from_image_store_backup_storage(
        local_bs_uuid, disaster_bs_uuid, disaster_bs_image_uuid)
    #Check the process status when recoverying image
    cond = res_ops.gen_query_conditions('resourceUuid', '=', local_bs_uuid)
    system_tag = res_ops.query_resource(res_ops.SYSTEM_TAG, cond)[0].tag
    status = system_tag.split('::')[7]
    if status not in ['running', 'success']:
        test_util.test_fail('Error status for recovery image, status: %s' %
                            status)
    #Check if recovery root volume success
    if recovery_image.backupStorageRefs[0].backupStorageUuid != local_bs_uuid:
        test_util.test_fail('Recovery image failed, image uuid is %s' %
                            recovery_image.uuid)
    if recovery_image.mediaType != 'RootVolumeTemplate':
        test_util.test_fail(
            'Wrong image type after recovery, the expect is "RootVolumeTemplate", the real is "%s"'
            % recovery_image.mediaType)
    image_uuid = recovery_image.uuid

    try:
        #Try to recovery the same image again, it's negative test
        recovery_image = img_ops.recovery_image_from_image_store_backup_storage(
            local_bs_uuid, disaster_bs_uuid, disaster_bs_image_uuid)
        img_ops.delete_image(recovery_image.uuid)
    except Exception, e:
        if unicode(e).encode("utf-8").find('包含') != -1:
            test_util.test_pass(
                'Try to recovery the same image again and get the error info expectly: %s'
                % unicode(e).encode("utf-8"))
コード例 #30
0
def delete_volume_image(image_uuid):
    img_ops.delete_image(image_uuid)
def test():
    global vcenter_uuid1
    global vcenter_uuid2
    global mevoco1_ip
    global mevoco2_ip
    global img_uuid
    global delete_policy1
    global delete_policy2

    print os.environ
    vcenter1_name = os.environ['vcenter2_name']
    vcenter1_domain_name = os.environ['vcenter2_ip']
    vcenter1_username = os.environ['vcenter2_domain_name']
    vcenter1_password = os.environ['vcenter2_password']
    sync_image_url = os.environ['vcenter2_sync_image_url']
    image_name = os.environ['vcenter2_sync_image_name']

    mevoco1_ip = os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP']
    mevoco2_ip = os.environ['serverIp2']

    os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip
    delete_policy1 = test_lib.lib_set_delete_policy('image', 'Delay')
    zone_uuid = res_ops.get_resource(res_ops.ZONE)[0].uuid
    inv = vct_ops.add_vcenter(vcenter1_name, vcenter1_domain_name,
                              vcenter1_username, vcenter1_password, True,
                              zone_uuid)
    vcenter_uuid1 = inv.uuid
    if vcenter_uuid1 == None:
        test_util.test_fail("vcenter_uuid is None")

    os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip
    delete_policy2 = test_lib.lib_set_delete_policy('image', 'Delay')
    zone_uuid = res_ops.get_resource(res_ops.ZONE)[0].uuid
    inv = vct_ops.add_vcenter(vcenter1_name, vcenter1_domain_name,
                              vcenter1_username, vcenter1_password, True,
                              zone_uuid)
    vcenter_uuid2 = inv.uuid
    if vcenter_uuid2 == None:
        test_util.test_fail("vcenter_uuid is None")

    #bs_cond = res_ops.gen_query_conditions("name", '=', "vCenter[vm-center]")
    bs_cond = res_ops.gen_query_conditions("type", '=', "VCenter")
    bss = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, bs_cond, \
            None, fields=['uuid'])
    if not bss:
        test_util.test_skip("not find available backup storage. Skip test")

    #add sync image in mevoco2
    image_option = test_util.ImageOption()
    image_option.set_name(image_name)
    #image_option.set_mediaType('RootVolumeTemplate')
    image_option.set_format('vmtx')
    image_option.set_system_tags('vcenter::datacenter::datacenter1')
    #image_option.set_url(os.environ.get(sync_image_url))
    image_option.set_url(sync_image_url)
    image_option.set_backup_storage_uuid_list([bss[0].uuid])

    new_image = zstack_image_header.ZstackTestImage()
    new_image.set_creation_option(image_option)

    #if a error happens here, check whether the image with the same name is already
    #exist in vcenter, which is also raise exception about can't download on all backup storage
    test_util.test_logger("add image from url:%s" % (sync_image_url))
    new_image.add_root_volume_template()

    #reconnect vcenter and check newly add image in mevoco1
    test_util.test_logger("check image sync from mevoco1")
    os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip
    bs_cond = res_ops.gen_query_conditions("type", '=', "VCenter")
    bss = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE,
                                        bs_cond,
                                        None,
                                        fields=['uuid'])
    bs_ops.reconnect_backup_storage(bss[0].uuid)
    image_cond = res_ops.gen_query_conditions("name", '=', image_name)
    img_inv = res_ops.query_resource_fields(res_ops.IMAGE,
                                            image_cond,
                                            None,
                                            fields=['uuid'])[0]
    img_uuid = img_inv.uuid
    if not img_uuid:
        test_util.test_fail("local woodpecker image uuid is null")

    #delete image in mevoco2
    test_util.test_logger("delete image from mevoco2")
    os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip
    image_cond = res_ops.gen_query_conditions("name", '=', image_name)
    img_inv = res_ops.query_resource_fields(res_ops.IMAGE,
                                            image_cond,
                                            None,
                                            fields=['uuid'])[0]
    img_uuid = img_inv.uuid
    img_ops.delete_image(img_uuid)
    img_ops.expunge_image(img_uuid)

    #check image in mevoco1
    test_util.test_logger("check image delete sync from mevoco1")
    os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip
    bs_cond = res_ops.gen_query_conditions("type", '=', "VCenter")
    bss = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE,
                                        bs_cond,
                                        None,
                                        fields=['uuid'])
    bs_ops.reconnect_backup_storage(bss[0].uuid)
    image_cond = res_ops.gen_query_conditions("name", '=', image_name)
    #img_inv = res_ops.query_resource_fields(res_ops.IMAGE, image_cond, None, fields=['uuid'])[0]
    #img_uuid = img_inv.uuid
    img_inv = res_ops.query_resource_fields(res_ops.IMAGE,
                                            image_cond,
                                            None,
                                            fields=['uuid'])
    if img_inv:
        test_util.test_fail(
            "local woodpecker image is not deleted as expected")

    os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip
    test_lib.lib_set_delete_policy('image', delete_policy2)
    if vcenter_uuid2:
        vct_ops.delete_vcenter(vcenter_uuid2)

    os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip
    test_lib.lib_set_delete_policy('image', delete_policy1)
    if vcenter_uuid1:
        vct_ops.delete_vcenter(vcenter_uuid1)

    test_util.test_pass("vcenter sync image test passed.")
コード例 #32
0
def test():
   test_util.test_dsc('Test Change VM Image Function')
   #set overProvisioning.primaryStorage's value as 10
   con_ops.change_global_config('mevoco','overProvisioning.primaryStorage',10)
   global vm
   bs_cond = res_ops.gen_query_conditions("status","=","Connected")
   bss = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, bs_cond, None, fields=['uuid'])
   if not bss:
      test_util.test_skip("not find available backup storage.Skip test")
   test_lib.lib_create_disk_offering(diskSize=1099511627776,name="1T")
   disk_offering_uuids = [test_lib.lib_get_disk_offering_by_name("smallDiskOffering").uuid,test_lib.lib_get_disk_offering_by_name("root-disk").uuid,test_lib.lib_get_disk_offering_by_name("1T").uuid]
   #create vm with 3 data volumes
   vm = test_stub.create_vm(image_name = "ttylinux",vm_name="test-vm",disk_offering_uuids = disk_offering_uuids)
   test_obj_dict.add_vm(vm)
   vm.check()

   vm_uuid = vm.get_vm().uuid
   last_data_volumes_uuids = []
   last_data_volumes = test_lib.lib_get_data_volumes(vm.get_vm())
   for data_volume in last_data_volumes:
        last_data_volumes_uuids.append(data_volume.uuid)
   last_l3network_uuid = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm())
   last_primarystorage_uuid = test_lib.lib_get_root_volume(vm.get_vm()).primaryStorageUuid
   vm_ops.stop_vm(vm_uuid)
   image_option = test_util.ImageOption()
   image_option.set_name('windows_for_test')
   image_option.set_format('qcow2')
   image_option.set_mediaType('RootVolumeTemplate')
   image_option.set_platform('windows')
   #image_option.set_url('http://172.20.1.16:7480/diskimages/windows-telnet.qcow2')
   image_option.set_url(os.environ.get('windowsImageUrl'))
   image_option.set_backup_storage_uuid_list([bss[0].uuid])
   image_option.set_timeout(1800*1000)
   new_image = zstack_image_header.ZstackTestImage()
   new_image.set_creation_option(image_option)
   new_image.add_root_volume_template()

   image_windows_uuid = test_lib.lib_get_image_by_name("windows_for_test").uuid
   vm_ops.change_vm_image(vm_uuid,image_windows_uuid)
   vm_ops.start_vm(vm_uuid)
   vm.update()
   vm_ip = vm.get_vm().vmNics[0].ip
   #check whether the windows vm is running successfully
   if not test_lib.lib_wait_target_up(vm_ip,'23',1200):
      test_util.test_fail('vm:%s is not startup in 1200 seconds.Fail to reboot it.' % vm_uuid)
   #check whether data volumes attached to the vm has changed
   data_volumes_after_uuids = []
   data_volumes_after = test_lib.lib_get_data_volumes(vm.get_vm())
   for data_volume in data_volumes_after:
      data_volumes_after_uuids.append(data_volume.uuid)
   if set(last_data_volumes_uuids) != set(data_volumes_after_uuids):
      test_util.test_fail('Change Vm Image Failed.Data volumes changed.')
   #check whether the network config has changed
   l3network_uuid_after = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm())
   if l3network_uuid_after != last_l3network_uuid:
      test_util.test_fail('Change VM Image Failed.The Network config has changed.')
   #check whether primarystorage has changed
   primarystorage_uuid_after = test_lib.lib_get_root_volume(vm.get_vm()).primaryStorageUuid
   if primarystorage_uuid_after != last_primarystorage_uuid:
      test_util.test_fail('Change VM Image Failed.Primarystorage has changed.')
   #check whether the linux vm is running successfully
   image_linux_uuid = test_lib.lib_get_image_by_name("image_for_sg_test").uuid
   vm_ops.stop_vm(vm_uuid)
   vm_ops.change_vm_image(vm_uuid,image_linux_uuid)
   vm_ops.start_vm(vm_uuid)
   if not test_lib.lib_wait_target_up(vm_ip,'22',180):
      test_util.test_fail('vm:%s is not startup in 180 seconds.Fail to reboot it.' % vm_uuid)
   #check whether data volumes attached to the vm has changed
   data_volumes_after_uuids_linux = []
   data_volumes_after_linux = test_lib.lib_get_data_volumes(vm.get_vm())
   for data_volume in data_volumes_after_linux:
      data_volumes_after_uuids_linux.append(data_volume.uuid)
   if set(data_volumes_after_uuids) != set(data_volumes_after_uuids_linux):
      test_util.test_fail('Change Vm Image Failed.Data volumes changed.')
   #check whether the network config has changed
   l3network_uuid_after_linux = test_lib.lib_get_l3s_uuid_by_vm(vm.get_vm())
   if l3network_uuid_after != l3network_uuid_after_linux:
      test_util.test_fail('Change VM Image Failed.The Network config has changed.')
   #check whether primarystorage has changed
   primarystorage_uuid_after_linux = test_lib.lib_get_root_volume(vm.get_vm()).primaryStorageUuid
   if primarystorage_uuid_after != primarystorage_uuid_after_linux:
      test_util.test_fail('Change VM Image Failed.Primarystorage has changed.')


   test_lib.lib_destroy_vm_and_data_volumes(vm.get_vm())
   vm.expunge()
   img_ops.delete_image(image_windows_uuid)
   img_ops.expunge_image(image_windows_uuid)
   test_util.test_pass('Change Vm Image Test Success')
コード例 #33
0
            'Wrong image media type after recovery, the expect is "DataVolumeTemplate", the real is "%s"'
            % media_type)
    image_uuid = recovery_image.uuid

    try:
        #Try to recovery the same image again, it's negative test
        recovery_image = img_ops.recovery_image_from_image_store_backup_storage(
            local_bs_uuid, disaster_bs_uuid, disaster_bs_image_uuid)
    except Exception, e:
        if unicode(e).encode("utf-8").find('包含') != -1:
            test_util.test_pass(
                'Try to recovery the same image again and get the error info expectly: %s'
                % unicode(e).encode("utf-8"))
    finally:
        vol_ops.delete_volume(data_volume_uuid)
        img_ops.delete_image(image_uuid)
    test_util.test_fail(
        'Try to recovery the same image second time success unexpectly')


#Will be called only if exception happens in test().
def error_cleanup():
    global disaster_bs_uuid
    global data_volume_uuid
    global image_uuid
    vol_ops.delete_volume(data_volume_uuid)
    img_ops.delete_image(image_uuid)
    if disaster_bs_uuid != None:
        bs_ops.delete_backup_storage(disaster_bs_uuid)

コード例 #34
0
    if system_tag.tag != "remote":
        test_util.test_fail("Here isn't 'remote' system tag for image in data protect bs")
    #Check if GetImagesFromImageStoreBackupStorage works well
    #disaster_bs_image_lst = img_ops.get_images_from_image_store_backup_storage(disaster_bs_uuid)
    #if disaster_bs_image_lst.infos == []:
    #    test_util.test_fail('GetImagesFromImageStoreBackupStorage unable to list the images in disaster bs')
    #Try to sync the same image again, it's negative test
    try:
        image_uuid = img_ops.sync_image_from_image_store_backup_storage(disaster_bs_uuid, local_bs_uuid, image_uuid_local)
    except Exception,e:
        if str(e).find('already contains it') != -1:
            test_util.test_logger('Try to sync the image which had exist in disaster bs get the error info expectly: %s' %str(e))
    else:
        test_util.test_fail('Try to sync the image which had exist in local bs success unexpectly')
    #Delete local image and recovery from disaster bs
    img_ops.delete_image(image_uuid_local)
    img_ops.expunge_image(image_uuid_local)
    recovery_image = img_ops.recovery_image_from_image_store_backup_storage(local_bs_uuid, disaster_bs_uuid, disaster_bs_image_uuid, 'other')
    image_uuid_recovery = recovery_image.uuid
    #Check the process status when recoverying image
    cond = res_ops.gen_query_conditions('resourceUuid', '=', local_bs_uuid)
    system_tag = res_ops.query_resource(res_ops.SYSTEM_TAG, cond)[0].tag
    status = system_tag.split('::')[7]
    if status not in ['running', 'success']:
        test_util.test_fail('Error status for recovery image, status: %s' %status)
    #Check if recovery image success
    if recovery_image.backupStorageRefs[0].backupStorageUuid != local_bs_uuid:
        test_util.test_fail('Recovery image failed, image uuid is %s' %recovery_image.uuid)
    if recovery_image.mediaType != 'RootVolumeTemplate':
        test_util.test_fail('Wrong image media type after recovery, the expect is "RootVolumeTemplate", the real is "%s"' %media_type)
 
コード例 #35
0
 def delete(self):
     img_ops.delete_image(self.image.uuid)
     super(ZstackTestImage, self).delete()
コード例 #36
0
def test():
    global project_uuid, project_admin_uuid, virtual_id_uuid, project_operator_uuid, plain_user_uuid

    flavor = case_flavor[os.environ.get('CASE_FLAVOR')]
    # 1 create project
    if flavor['target_role'] != 'system_admin':
        project_name = 'test_project'
        project = iam2_ops.create_iam2_project(project_name)
        project_uuid = project.uuid
        project_linked_account_uuid = project.linkedAccountUuid

    if flavor['target_role'] == 'project_admin':
        # 2 create virtual id
        project_admin_name = 'username'
        project_admin_password = '******'
        project_admin_uuid = iam2_ops.create_iam2_virtual_id(project_admin_name, project_admin_password).uuid
        virtual_id_uuid = iam2_ops.create_iam2_virtual_id('usernametwo', 'password').uuid
    
        # 3 create project admin
        iam2_ops.add_iam2_virtual_ids_to_project([project_admin_uuid],project_uuid)
        attributes = [{"name": "__ProjectAdmin__", "value": project_uuid}]
        iam2_ops.add_attributes_to_iam2_virtual_id(project_admin_uuid, attributes)

        # login in project by project admin
        project_admin_session_uuid = iam2_ops.login_iam2_virtual_id(project_admin_name, project_admin_password)
        project_login_uuid = iam2_ops.login_iam2_project(project_name, session_uuid=project_admin_session_uuid).uuid
        # iam2_ops.remove_attributes_from_iam2_virtual_id(virtual_id_uuid, attributes)
    elif flavor['target_role'] == 'project_operator':
        project_operator_name = 'username2'
        project_operator_password = '******'
        attributes = [{"name": "__ProjectOperator__", "value": project_uuid}]
        project_operator_uuid = iam2_ops.create_iam2_virtual_id(project_operator_name,project_operator_password,attributes=attributes).uuid
        virtual_id_uuid = iam2_ops.create_iam2_virtual_id('usernamethree','password').uuid

        # login in project by project operator
        iam2_ops.add_iam2_virtual_ids_to_project([project_operator_uuid],project_uuid)
        project_operator_session_uuid = iam2_ops.login_iam2_virtual_id(project_operator_name,project_operator_password)
        project_login_uuid = iam2_ops.login_iam2_project(project_name,session_uuid=project_operator_session_uuid).uuid
    elif flavor['target_role'] == 'project_member':
	plain_user_name = 'username'
	plain_user_password = '******'
	plain_user_uuid = iam2_ops.create_iam2_virtual_id(plain_user_name, plain_user_password,
	                                                  project_uuid=project_uuid).uuid
	# 3 add virtual id to project
	iam2_ops.add_iam2_virtual_ids_to_project([plain_user_uuid],project_uuid)

	# 4 login in project by plain user
	plain_user_session_uuid = iam2_ops.login_iam2_virtual_id(plain_user_name, plain_user_password)

	# 4 login in project
	#project_inv=iam2_ops.get_iam2_projects_of_virtual_id(plain_user_session_uuid)
	project_login_uuid = iam2_ops.login_iam2_project(project_name, plain_user_session_uuid).uuid
    elif flavor['target_role'] == 'system_admin':
        username = "******"
        password = '******'
        vid_tst_obj = test_vid.ZstackTestVid()
        test_stub.create_system_admin(username, password, vid_tst_obj)
        virtual_id_uuid = vid_tst_obj.get_vid().uuid
        project_login_uuid = acc_ops.login_by_account(username, password)

    # Image related ops: Add, Delete, Expunge, sync image size, Update QGA, delete, expunge
    if flavor['target_role'] == 'project_member':
        statements = [{"effect": "Allow", "actions": ["org.zstack.header.image.**"]}, {"effect": "Allow", "actions": ["org.zstack.header.storage.backup.**"]}]
        role_uuid = iam2_ops.create_role('test_role', statements).uuid
        iam2_ops.add_roles_to_iam2_virtual_id([role_uuid], plain_user_uuid)
    bs = res_ops.query_resource(res_ops.BACKUP_STORAGE)[0]
    image_option = test_util.ImageOption()
    image_option.set_name('fake_image')
    image_option.set_description('fake image')
    image_option.set_format('raw')
    image_option.set_mediaType('RootVolumeTemplate')
    image_option.set_backup_storage_uuid_list([bs.uuid])
    image_option.url = "http://fake/fake.raw"
    image_option.set_session_uuid(project_login_uuid)
    image_uuid = img_ops.add_image(image_option).uuid
    img_ops.sync_image_size(image_uuid, session_uuid=project_login_uuid)
    img_ops.change_image_state(image_uuid, 'disable', session_uuid=project_login_uuid)
    img_ops.change_image_state(image_uuid, 'enable', session_uuid=project_login_uuid)
    if bs.type == inventory.IMAGE_STORE_BACKUP_STORAGE_TYPE:
        img_ops.export_image_from_backup_storage(image_uuid, bs.uuid, session_uuid=project_login_uuid)
        img_ops.delete_exported_image_from_backup_storage(image_uuid, bs.uuid, session_uuid=project_login_uuid)
    img_ops.set_image_qga_enable(image_uuid, session_uuid=project_login_uuid)
    img_ops.set_image_qga_disable(image_uuid, session_uuid=project_login_uuid)
    cond = res_ops.gen_query_conditions('name', '=', "fake_image")
    image = res_ops.query_resource(res_ops.IMAGE, cond, session_uuid=project_login_uuid)
    if image == None:
        test_util.test_fail('fail to query image just added')
    img_ops.delete_image(image_uuid, session_uuid=project_login_uuid)
    img_ops.expunge_image(image_uuid, session_uuid=project_login_uuid)

    # 11 delete
    acc_ops.logout(project_login_uuid)
    if virtual_id_uuid != None:
        iam2_ops.delete_iam2_virtual_id(virtual_id_uuid)
    if project_admin_uuid != None:
        iam2_ops.delete_iam2_virtual_id(project_admin_uuid)
    if project_operator_uuid != None:
        iam2_ops.delete_iam2_virtual_id(project_operator_uuid)
    if plain_user_uuid != None:
        iam2_ops.delete_iam2_virtual_id(plain_user_uuid)

    if flavor['target_role'] != 'system_admin':
        iam2_ops.delete_iam2_project(project_uuid)
        iam2_ops.expunge_iam2_project(project_uuid)

    test_util.test_pass('success test iam2 login in by project admin!')
コード例 #37
0
def test():
    global vcenter_uuid1
    global vcenter_uuid2
    global mevoco1_ip
    global mevoco2_ip
    global img_uuid
    global delete_policy1
    global delete_policy2

    print os.environ
    vcenter1_name = os.environ['vcenter2_name']
    vcenter1_domain_name = os.environ['vcenter2_ip']
    vcenter1_username = os.environ['vcenter2_domain_name']
    vcenter1_password = os.environ['vcenter2_password']
    sync_image_url = os.environ['vcenter2_sync_image_url']
    image_name = os.environ['vcenter2_sync_image_name']

    mevoco1_ip = os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP']
    mevoco2_ip = os.environ['serverIp2']


    os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip
    delete_policy1 = test_lib.lib_set_delete_policy('image', 'Delay')
    zone_uuid = res_ops.get_resource(res_ops.ZONE)[0].uuid
    inv = vct_ops.add_vcenter(vcenter1_name, vcenter1_domain_name, vcenter1_username, vcenter1_password, True, zone_uuid)
    vcenter_uuid1 = inv.uuid
    if vcenter_uuid1 == None:
        test_util.test_fail("vcenter_uuid is None")


    os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip
    delete_policy2 = test_lib.lib_set_delete_policy('image', 'Delay')
    zone_uuid = res_ops.get_resource(res_ops.ZONE)[0].uuid
    inv = vct_ops.add_vcenter(vcenter1_name, vcenter1_domain_name, vcenter1_username, vcenter1_password, True, zone_uuid)
    vcenter_uuid2 = inv.uuid
    if vcenter_uuid2 == None:
        test_util.test_fail("vcenter_uuid is None")

    #bs_cond = res_ops.gen_query_conditions("name", '=', "vCenter[vm-center]")
    bs_cond = res_ops.gen_query_conditions("type", '=', "VCenter")
    bss = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, bs_cond, \
            None, fields=['uuid'])
    if not bss:
        test_util.test_skip("not find available backup storage. Skip test")

    #add sync image in mevoco2
    image_option = test_util.ImageOption()
    image_option.set_name(image_name)
    #image_option.set_mediaType('RootVolumeTemplate')
    image_option.set_format('vmtx')
    image_option.set_system_tags('vcenter::datacenter::datacenter1')
    #image_option.set_url(os.environ.get(sync_image_url))
    image_option.set_url(sync_image_url)
    image_option.set_backup_storage_uuid_list([bss[0].uuid])


    new_image = zstack_image_header.ZstackTestImage()
    new_image.set_creation_option(image_option)

    #if a error happens here, check whether the image with the same name is already
    #exist in vcenter, which is also raise exception about can't download on all backup storage
    test_util.test_logger("add image from url:%s" %(sync_image_url))
    new_image.add_root_volume_template()


    #reconnect vcenter and check newly add image in mevoco1
    test_util.test_logger("check image sync from mevoco1")
    os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip
    bs_cond = res_ops.gen_query_conditions("type", '=', "VCenter")
    bss = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, bs_cond, None, fields=['uuid'])
    bs_ops.reconnect_backup_storage(bss[0].uuid)
    image_cond = res_ops.gen_query_conditions("name", '=', image_name)
    img_inv = res_ops.query_resource_fields(res_ops.IMAGE, image_cond, None, fields=['uuid'])[0]
    img_uuid = img_inv.uuid
    if not img_uuid:
        test_util.test_fail("local woodpecker image uuid is null")


    #delete image in mevoco2
    test_util.test_logger("delete image from mevoco2")
    os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip
    image_cond = res_ops.gen_query_conditions("name", '=', image_name)
    img_inv = res_ops.query_resource_fields(res_ops.IMAGE, image_cond, None, fields=['uuid'])[0]
    img_uuid = img_inv.uuid
    img_ops.delete_image(img_uuid)
    img_ops.expunge_image(img_uuid)

    #check image in mevoco1
    test_util.test_logger("check image delete sync from mevoco1")
    os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip
    bs_cond = res_ops.gen_query_conditions("type", '=', "VCenter")
    bss = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, bs_cond, None, fields=['uuid'])
    bs_ops.reconnect_backup_storage(bss[0].uuid)
    image_cond = res_ops.gen_query_conditions("name", '=', image_name)
    #img_inv = res_ops.query_resource_fields(res_ops.IMAGE, image_cond, None, fields=['uuid'])[0]
    #img_uuid = img_inv.uuid
    img_inv = res_ops.query_resource_fields(res_ops.IMAGE, image_cond, None, fields=['uuid'])
    if img_inv:
        test_util.test_fail("local woodpecker image is not deleted as expected")


    os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco2_ip
    test_lib.lib_set_delete_policy('image', delete_policy2)
    if vcenter_uuid2:
        vct_ops.delete_vcenter(vcenter_uuid2)

    os.environ['ZSTACK_BUILT_IN_HTTP_SERVER_IP'] = mevoco1_ip
    test_lib.lib_set_delete_policy('image', delete_policy1)
    if vcenter_uuid1:
        vct_ops.delete_vcenter(vcenter_uuid1)

    test_util.test_pass("vcenter sync image test passed.")
def test():
    global image1
    global test_obj_dict

    #run condition
    hosts = res_ops.query_resource(res_ops.HOST)
    if len(hosts) <= 1:
        test_util.test_skip("skip for host_num is not satisfy condition host_num>1")

    cond = res_ops.gen_query_conditions("status", '=', "Connected")
    ps = res_ops.query_resource_fields(res_ops.PRIMARY_STORAGE, cond, None, fields=['uuid'])
    bss = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, cond, None, fields=['uuid'])

    # add iso and create vm from iso
    iso = test_stub.add_test_minimal_iso('minimal_iso')
    test_obj_dict.add_image(iso)
    root_volume_offering = test_stub.add_test_root_volume_offering('root-disk-iso', 10737418240)
    test_obj_dict.add_disk_offering(root_volume_offering)
    vm_offering = test_stub.add_test_vm_offering(2, 1024*1024*1024, 'iso-vm-offering')
    test_obj_dict.add_instance_offering(vm_offering)
    vm = test_stub.create_vm_with_iso_for_test(vm_offering.uuid, iso.image.uuid, root_volume_offering.uuid, 'iso-vm')
    test_obj_dict.add_vm(vm)

    #check vm
    vm_inv = vm.get_vm()
    test_lib.lib_set_vm_host_l2_ip(vm_inv)
    test_lib.lib_wait_target_up(vm.get_vm().vmNics[0].ip, 22, 1800)

    #add data volume template
    template_option = test_util.ImageOption()
    template_option.set_name('data-volume-template')
    template_option.set_backup_storage_uuid_list([bss[0].uuid])
    template_option.set_format('qcow2')
    template_option.set_url(os.environ.get('data_vol_qcow2'))
    template_inv = img_ops.add_data_volume_template(template_option)
    template = test_image.ZstackTestImage()
    template.set_image(template_inv)
    template.set_creation_option(template_option)
    test_obj_dict.add_image(template)

    #export vol template
    if bss[0].type in [inventory.IMAGE_STORE_BACKUP_STORAGE_TYPE]:
        img_ops.export_image_from_backup_storage(template.image.uuid, bss[0].uuid)
    #create data volume from template
    target_host = test_lib.lib_find_host_by_vm(vm.vm)
    volume = vol_ops.create_volume_from_template(template.image.uuid, ps[0].uuid,
                                                  host_uuid=target_host.uuid)
    # create template from data volume
    template_option2 = test_util.ImageOption()
    template_option2.set_data_volume_uuid(volume.uuid)
    template_option2.set_name('data-template-from-vol')
    template_option2.set_backup_storage_uuid_list([bss[0].uuid])
    template2 = img_ops.create_data_volume_template(template_option2)
    #export vol template
    if bss[0].type in [inventory.IMAGE_STORE_BACKUP_STORAGE_TYPE]:
        img_ops.export_image_from_backup_storage(template2.uuid, bss[0].uuid)
    volume2 = vol_ops.create_volume_from_template(template2.uuid, volume.primaryStorageUuid, host_uuid = target_host.uuid)

    #del data volume template
    img_ops.delete_image(template2.uuid)

    # dvol ops test
    test_stub.dvol_ops_test(volume2, vm, "DVOL_TEST_ALL")

    #expunge data volume template
    img_ops.expunge_image(template2.uuid)

    # dvol ops test
    test_stub.dvol_ops_test(volume2, vm, "DVOL_TEST_ALL")

    test_lib.lib_robot_cleanup(test_obj_dict)
    test_util.test_pass('deleting and expunge vol image check vol ops Success')
コード例 #39
0
 def delete(self):
     img_ops.delete_image(self.image.uuid)
     super(ZstackTestImage, self).delete()
def test():
    global image1
    global test_obj_dict

    #run condition
    hosts = res_ops.query_resource(res_ops.HOST)
    if len(hosts) <= 1:
        test_util.test_skip("skip for host_num is not satisfy condition host_num>1")

    bs_cond = res_ops.gen_query_conditions("status", '=', "Connected")
    bss = res_ops.query_resource_fields(res_ops.BACKUP_STORAGE, bs_cond, None, fields=['uuid'])


    image_name1 = 'image1_a'
    image_option = test_util.ImageOption()
    image_option.set_format('qcow2')
    image_option.set_name(image_name1)
    # image_option.set_system_tags('qemuga')
    image_option.set_mediaType('RootVolumeTemplate')
    image_option.set_url(os.environ.get('imageUrl_s'))
    image_option.set_backup_storage_uuid_list([bss[0].uuid])
    image_option.set_timeout(3600 * 1000)

    image1 = zstack_image_header.ZstackTestImage()
    image1.set_creation_option(image_option)
    image1.add_root_volume_template()
    image1.check()
    test_obj_dict.add_image(image1)

    image_name = os.environ.get('imageName_net')
    l3_name = os.environ.get('l3VlanNetworkName1')
    vm1 = test_stub.create_vm(image_name1, image_name, l3_name)
    test_obj_dict.add_vm(vm1)

    #create data volume
    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('volume1')
    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.check()
    volume.attach(vm1)
    volume.detach()
    # dvol ops test
    test_stub.dvol_ops_test(volume.volume, vm1, "DVOL_TEST_ALL")
    volume.attach(vm1)

    #create data volume from template
    image_option2 = test_util.ImageOption()
    image_option2.set_data_volume_uuid(volume.volume.uuid)
    image_option2.set_name('data_template')
    image_option2.set_backup_storage_uuid_list([bss[0].uuid])
    vol_image = img_ops.create_data_volume_template(image_option2)
    #export vol template
    if bss[0].type in [inventory.IMAGE_STORE_BACKUP_STORAGE_TYPE]:
        img_ops.export_image_from_backup_storage(vol_image.uuid, bss[0].uuid)
    target_host = test_lib.lib_find_host_by_vm(vm1.vm)
    volume2 = vol_ops.create_volume_from_template(vol_image.uuid, volume.volume.primaryStorageUuid, host_uuid = target_host.uuid)

    #del data volume template
    img_ops.delete_image(vol_image.uuid)

    # dvol ops test
    test_stub.dvol_ops_test(volume2, vm1, "DVOL_TEST_ALL")

    #expunge data volume template
    img_ops.expunge_image(vol_image.uuid)

    # dvol ops test
    test_stub.dvol_ops_test(volume2, vm1, "DVOL_TEST_ALL")

    test_lib.lib_robot_cleanup(test_obj_dict)
    test_util.test_pass('deleting and expunge vol image check vol ops Success')