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)
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)
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()
예제 #4
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)
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)
def test():
    global image
    iam2_ops.clean_iam2_enviroment()
    zone_uuid = res_ops.get_resource(res_ops.ZONE)[0].uuid

    # 1 create project
    project_name = 'test_project'
    password = \
        'b109f3bbbc244eb82441917ed06d618b9008dd09b3befd1b5e07394c706a8bb980b1d7785e5976ec049b46df5f1326af5a2ea6d103fd07c95385ffab0cacbc86'
    project = iam2_ops.create_iam2_project(project_name)
    project_uuid = project.uuid
    linked_account_uuid = project.linkedAccountUuid
    attributes = [{"name": "__ProjectRelatedZone__", "value": zone_uuid}]
    iam2_ops.add_attributes_to_iam2_project(project_uuid, attributes)
    test_stub.share_admin_resource_include_vxlan_pool([linked_account_uuid])

    # 2 create projectAdmin  into project
    project_admin_name = 'projectadmin'
    project_admin_uuid = iam2_ops.create_iam2_virtual_id(project_admin_name, password).uuid
    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)
    project_admin_session_uuid = iam2_ops.login_iam2_virtual_id(project_admin_name,password)
    project_admin_session_uuid = iam2_ops.login_iam2_project(project_name,project_admin_session_uuid).uuid
    res_ops.query_resource(res_ops.L2_VXLAN_NETWORK_POOL)

    # 3 add image
    bs_cond = res_ops.gen_query_conditions("status", '=', "Connected")
    bss = res_ops.query_resource(res_ops.BACKUP_STORAGE, bs_cond)

    image_option = test_util.ImageOption()
    image_option.set_format('iso')
    image_option.set_name('test_add_iso_image')
    image_option.set_url(os.environ.get('imageServer') + "/iso/CentOS-x86_64-7.2-Minimal.iso")
    image_option.set_backup_storage_uuid_list([bss[0].uuid])
    image_option.set_timeout(60000)
    image_option.set_session_uuid(project_admin_session_uuid)
    image = img_ops.add_image(image_option)

    # 4 delete project
    iam2_ops.delete_iam2_project(project_uuid)
    cond =res_ops.gen_query_conditions('uuid','=',image.uuid)
    img_inv=res_ops.query_resource(res_ops.IMAGE,cond)
    if not img_inv:
        test_util.test_fail("can't query image %s after delete the project,test fail"%image.uuid)

    # 5 expunge project
    iam2_ops.expunge_iam2_project(project_uuid)
    cond = res_ops.gen_query_conditions('uuid','=',image.uuid)
    img_inv = res_ops.query_resource(res_ops.IMAGE,cond)[0]
    if img_inv.status != 'Deleted':
        test_util.test_fail('The image created in project is not deleted after project is expunge, test fail')

    img_ops.expunge_image(image.uuid)
    iam2_ops.clean_iam2_enviroment()
    test_util.test_pass('success')
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')
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 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():
    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():
   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')
예제 #12
0
 def expunge(self, bs_uuid_list = None):
     img_ops.expunge_image(self.image.uuid, bs_uuid_list)
     super(ZstackTestImage, self).expunge()
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!')
예제 #14
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')
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')
예제 #16
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():
    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')
예제 #18
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!')
예제 #19
0
def test():
    global image
    iam2_ops.clean_iam2_enviroment()
    zone_uuid = res_ops.get_resource(res_ops.ZONE)[0].uuid

    # 1 create project
    project_name = 'test_project'
    password = \
        'b109f3bbbc244eb82441917ed06d618b9008dd09b3befd1b5e07394c706a8bb980b1d7785e5976ec049b46df5f1326af5a2ea6d103fd07c95385ffab0cacbc86'
    project = iam2_ops.create_iam2_project(project_name)
    project_uuid = project.uuid
    linked_account_uuid = project.linkedAccountUuid
    attributes = [{"name": "__ProjectRelatedZone__", "value": zone_uuid}]
    iam2_ops.add_attributes_to_iam2_project(project_uuid, attributes)
    test_stub.share_admin_resource_include_vxlan_pool([linked_account_uuid])

    # 2 create projectAdmin  into project
    project_admin_name = 'projectadmin'
    project_admin_uuid = iam2_ops.create_iam2_virtual_id(
        project_admin_name, password).uuid
    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)
    project_admin_session_uuid = iam2_ops.login_iam2_virtual_id(
        project_admin_name, password)
    project_admin_session_uuid = iam2_ops.login_iam2_project(
        project_name, project_admin_session_uuid).uuid
    res_ops.query_resource(res_ops.L2_VXLAN_NETWORK_POOL)

    # 3 add image
    bs_cond = res_ops.gen_query_conditions("status", '=', "Connected")
    bss = res_ops.query_resource(res_ops.BACKUP_STORAGE, bs_cond)

    image_option = test_util.ImageOption()
    image_option.set_format('iso')
    image_option.set_name('test_add_iso_image')
    image_option.set_url(
        os.environ.get('imageServer') + "/iso/CentOS-x86_64-7.2-Minimal.iso")
    image_option.set_backup_storage_uuid_list([bss[0].uuid])
    image_option.set_timeout(60000)
    image_option.set_session_uuid(project_admin_session_uuid)
    image = img_ops.add_image(image_option)

    # 4 delete project
    iam2_ops.delete_iam2_project(project_uuid)
    cond = res_ops.gen_query_conditions('uuid', '=', image.uuid)
    img_inv = res_ops.query_resource(res_ops.IMAGE, cond)
    if not img_inv:
        test_util.test_fail(
            "can't query image %s after delete the project,test fail" %
            image.uuid)

    # 5 expunge project
    iam2_ops.expunge_iam2_project(project_uuid)
    cond = res_ops.gen_query_conditions('uuid', '=', image.uuid)
    img_inv = res_ops.query_resource(res_ops.IMAGE, cond)[0]
    if img_inv.status != 'Deleted':
        test_util.test_fail(
            'The image created in project is not deleted after project is expunge, test fail'
        )

    img_ops.expunge_image(image.uuid)
    iam2_ops.clean_iam2_enviroment()
    test_util.test_pass('success')
        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)
 
    try:
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!')
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.")
        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)
 
    try:
예제 #24
0
def expunge_image(image_uuid):
    evt = img_ops.expunge_image(image_uuid)
    return evt
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')
 def expunge(self, bs_uuid_list):
     img_ops.expunge_image(self.image.uuid, bs_uuid_list)
     super(ZstackTestImage, self).expunge()
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')