def test(): flavor = case_flavor[os.environ.get('CASE_FLAVOR')] global agent_url global image agent_url = flavor['agent_url'] agent_action = flavor['agent_action'] if agent_action == 1: agent_time = (24*60*60-60)*1000 elif agent_action == 2: agent_time = 360 * 1000 image_uuid = str(uuid.uuid4()).replace('-', '') rsp = dep_ops.json_post("http://127.0.0.1:8888/test/api/v1.0/store/create", simplejson.dumps({"key": image_uuid, "value": '{"%s":%s}' % (agent_url, agent_action)})) image_creation_option = test_util.ImageOption() imagestore = test_lib.lib_get_image_store_backup_storage() if imagestore == None: test_util.test_skip('Required imagestore to test') bs_uuid = imagestore.uuid image_option = test_util.ImageOption() image_option.set_uuid(image_uuid) 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_timeout(24*60*60*1000) start = time.time() image = img_ops.add_image(image_option) end = time.time() if end - start < agent_time / 2 / 1000: test_util.test_fail('execution time too short %s' % (end - start))
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 disaster_bs_uuid 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) #get a candidate image 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('backupStorageRefs.backupStorageUuid', '=', local_bs_uuid) image = res_ops.query_resource(res_ops.IMAGE, cond)[0] #setup image option image_option = test_util.ImageOption() image_option.set_name('add_image_to_data_protect_bs') image_option.set_format(image.format) image_option.set_platform(image.platform) image_option.set_url(image.url) image_option.set_mediaType(image.mediaType) image_option.set_backup_storage_uuid_list([disaster_bs_uuid]) #Try to add image to disaster bs directly try: new_img = img_ops.add_image(image_option) except Exception, e: if unicode(e).encode("utf-8").find('禁止') != -1: test_util.test_pass( 'AddImage is forbidden in Disaster BS, Here is the expect error info: %s' % unicode(e).encode("utf-8"))
def test(): global disaster_bs_uuid disaster_bs_dict = bs_ops.get_disaster_backup_storage_info( test_lib.deploy_config) name = disaster_bs_dict['name'] description = disaster_bs_dict['description'] hostname = disaster_bs_dict['hostname'] url = disaster_bs_dict['url'] username = disaster_bs_dict['username'] password = disaster_bs_dict['password'] sshport = disaster_bs_dict['port'] #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) #get a candidate image cond = res_ops.gen_query_conditions('name', '=', 'sftp') local_bs_uuid = res_ops.query_resource(res_ops.BACKUP_STORAGE, cond)[0].uuid cond = res_ops.gen_query_conditions('backupStorageRefs.backupStorageUuid', '=', local_bs_uuid) image = res_ops.query_resource(res_ops.IMAGE, cond)[0] #setup image option image_option = test_util.ImageOption() image_option.set_name('add_image_to_data_protect_bs') image_option.set_format(image.format) image_option.set_platform(image.platform) image_option.set_url(image.url) image_option.set_mediaType(image.mediaType) image_option.set_backup_storage_uuid_list([disaster_bs_uuid]) #Try to add image to disaster bs directly try: new_img = img_ops.add_image(image_option) except Exception, e: if str(e).find('forbidden') != -1: test_util.test_pass( 'AddImage is forbidden in Disaster BS, Here is the expect error info: %s' % str(e))
def test(): flavor = case_flavor[os.environ.get('CASE_FLAVOR')] global agent_url global image agent_url = flavor['agent_url'] agent_action = flavor['agent_action'] if agent_action == 1: agent_time = (24 * 60 * 60 - 60) * 1000 elif agent_action == 2: agent_time = 360 * 1000 image_uuid = str(uuid.uuid4()).replace('-', '') rsp = dep_ops.json_post( "http://127.0.0.1:8888/test/api/v1.0/store/create", simplejson.dumps({ "key": image_uuid, "value": '{"%s":%s}' % (agent_url, agent_action) })) image_creation_option = test_util.ImageOption() bss = res_ops.query_resource(res_ops.CEPH_BACKUP_STORAGE, []) if len(bss) == 0: test_util.test_skip('Required ceph bs to test') bs_uuid = bss[0].uuid image_option = test_util.ImageOption() image_option.set_uuid(image_uuid) 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_timeout(24 * 60 * 60 * 1000) start = time.time() image = img_ops.add_image(image_option) end = time.time() if end - start < agent_time / 2 / 1000: test_util.test_fail('execution time too short %s' % (end - start))
def test(): global disaster_bs_uuid 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) #get a candidate image 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('backupStorageRefs.backupStorageUuid', '=', local_bs_uuid) image = res_ops.query_resource(res_ops.IMAGE, cond)[0] #setup image option image_option = test_util.ImageOption() image_option.set_name('add_image_to_data_protect_bs') image_option.set_format(image.format) image_option.set_platform(image.platform) image_option.set_url(image.url) image_option.set_mediaType(image.mediaType) image_option.set_backup_storage_uuid_list([disaster_bs_uuid]) #Try to add image to disaster bs directly try: new_img = img_ops.add_image(image_option) except Exception,e: if unicode(e).encode("utf-8").find('禁止') != -1: test_util.test_pass('AddImage is forbidden in Disaster BS, Here is the expect error info: %s' %unicode(e).encode("utf-8"))
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!')
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 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 test_dict bs_cond = res_ops.gen_query_conditions("status", '=', "Connected") bss = res_ops.query_resource(res_ops.BACKUP_STORAGE, bs_cond) if not bss: test_util.test_skip("not find available backup storage. Skip test") for bs in bss: 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: test_util.test_skip('Not find image store type backup storage.') #test add iso image_option = test_util.ImageOption() image_option.set_format('qcow2') image_option.set_name('test_add_iso_image') # image_option.set_mediaType('ISO') 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(120000) image=img_ops.add_image(image_option) new_image = zstack_image_header.ZstackTestImage() new_image.set_creation_option(image_option) new_image.set_image(image) test_dict.add_image(new_image) image_cond = res_ops.gen_query_conditions('uuid', '=', new_image.get_image().uuid) image_inv = res_ops.query_resource(res_ops.IMAGE, image_cond)[0] if image_inv.format != 'iso': test_util.test_fail('image\'s format is not iso,fail') #test add qcow2 image_option = test_util.ImageOption() image_option.set_format('iso') image_option.set_name('test_add_qcow2_image') # image_option.set_mediaType('ISO') image_option.set_url(os.environ.get('imageServer')+"/diskimages/core-image-minimal-qemux86-64_v1.qcow2") image_option.set_backup_storage_uuid_list([bss[0].uuid]) image_option.set_timeout(120000) image=img_ops.add_image(image_option) new_image = zstack_image_header.ZstackTestImage() new_image.set_creation_option(image_option) new_image.set_image(image) test_dict.add_image(new_image) image_cond = res_ops.gen_query_conditions('uuid', '=', new_image.get_image().uuid) image_inv = res_ops.query_resource(res_ops.IMAGE, image_cond)[0] if bss[0].type!=inventory.CEPH_BACKUP_STORAGE_TYPE: if image_inv.format != 'qcow2': test_util.test_fail('image\'s format is not qcow2,fail') else: if image_inv.format!='raw': test_util.test_fail('image\' format is not raw,fail') #test add raw image_option = test_util.ImageOption() image_option.set_format('iso') image_option.set_name('test_add_raw_image') # image_option.set_mediaType('ISO') image_option.set_url(os.environ.get('imageServer')+"/diskimages/zstack_image_test.raw") image_option.set_backup_storage_uuid_list([bss[0].uuid]) image_option.set_timeout(120000) image=img_ops.add_image(image_option) new_image = zstack_image_header.ZstackTestImage() new_image.set_creation_option(image_option) new_image.set_image(image) test_dict.add_image(new_image) image_cond = res_ops.gen_query_conditions('uuid', '=', new_image.get_image().uuid) image_inv = res_ops.query_resource(res_ops.IMAGE, image_cond)[0] if image_inv.format != 'raw': test_util.test_fail('image\'s format is not raw,fail') #test add other format image_option = test_util.ImageOption() image_option.set_format('qcow2') image_option.set_name('test_add_vmdk_image') # image_option.set_mediaType('ISO') image_option.set_url(os.environ.get('imageServer')+"/diskimages/zstack-image-1.2-flat.vmdk") image_option.set_backup_storage_uuid_list([bss[0].uuid]) image_option.set_timeout(120000) image=img_ops.add_image(image_option) new_image = zstack_image_header.ZstackTestImage() new_image.set_creation_option(image_option) new_image.set_image(image) test_dict.add_image(new_image) image_cond = res_ops.gen_query_conditions('uuid', '=', new_image.get_image().uuid) image_inv = res_ops.query_resource(res_ops.IMAGE, image_cond)[0] if image_inv.format!='raw': test_util.test_fail('image\' format is not raw,fail') test_lib.lib_robot_cleanup(test_dict) test_util.test_pass('test add image auto format success!')
def test(): global test_dict bs_cond = res_ops.gen_query_conditions("status", '=', "Connected") bss = res_ops.query_resource(res_ops.BACKUP_STORAGE, bs_cond) if not bss: test_util.test_skip("not find available backup storage. Skip test") for bs in bss: 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: test_util.test_skip('Not find image store type backup storage.') #test add iso image_option = test_util.ImageOption() image_option.set_format('qcow2') image_option.set_name('test_add_iso_image') # image_option.set_mediaType('ISO') 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 = img_ops.add_image(image_option) new_image = zstack_image_header.ZstackTestImage() new_image.set_creation_option(image_option) new_image.set_image(image) test_dict.add_image(new_image) image_cond = res_ops.gen_query_conditions('uuid', '=', new_image.get_image().uuid) image_inv = res_ops.query_resource(res_ops.IMAGE, image_cond)[0] if image_inv.format != 'iso': test_util.test_fail('image\'s format is not iso,fail') #test add qcow2 image_option = test_util.ImageOption() image_option.set_format('iso') image_option.set_name('test_add_qcow2_image') # image_option.set_mediaType('ISO') image_option.set_url( os.environ.get('imageServer') + "/diskimages/core-image-minimal-qemux86-64_v1.qcow2") image_option.set_backup_storage_uuid_list([bss[0].uuid]) image_option.set_timeout(60000) image = img_ops.add_image(image_option) new_image = zstack_image_header.ZstackTestImage() new_image.set_creation_option(image_option) new_image.set_image(image) test_dict.add_image(new_image) image_cond = res_ops.gen_query_conditions('uuid', '=', new_image.get_image().uuid) image_inv = res_ops.query_resource(res_ops.IMAGE, image_cond)[0] if bss[0].type != inventory.CEPH_BACKUP_STORAGE_TYPE: if image_inv.format != 'qcow2': test_util.test_fail('image\'s format is not qcow2,fail') else: if image_inv.format != 'raw': test_util.test_fail('image\' format is not raw,fail') #test add raw image_option = test_util.ImageOption() image_option.set_format('iso') image_option.set_name('test_add_raw_image') # image_option.set_mediaType('ISO') image_option.set_url( os.environ.get('imageServer') + "/diskimages/zstack_image_test.raw") image_option.set_backup_storage_uuid_list([bss[0].uuid]) image_option.set_timeout(60000) image = img_ops.add_image(image_option) new_image = zstack_image_header.ZstackTestImage() new_image.set_creation_option(image_option) new_image.set_image(image) test_dict.add_image(new_image) image_cond = res_ops.gen_query_conditions('uuid', '=', new_image.get_image().uuid) image_inv = res_ops.query_resource(res_ops.IMAGE, image_cond)[0] if image_inv.format != 'raw': test_util.test_fail('image\'s format is not raw,fail') #test add other format image_option = test_util.ImageOption() image_option.set_format('qcow2') image_option.set_name('test_add_vmdk_image') # image_option.set_mediaType('ISO') image_option.set_url( os.environ.get('imageServer') + "/diskimages/zstack-image-1.2-flat.vmdk") image_option.set_backup_storage_uuid_list([bss[0].uuid]) image_option.set_timeout(60000) image = img_ops.add_image(image_option) new_image = zstack_image_header.ZstackTestImage() new_image.set_creation_option(image_option) new_image.set_image(image) test_dict.add_image(new_image) image_cond = res_ops.gen_query_conditions('uuid', '=', new_image.get_image().uuid) image_inv = res_ops.query_resource(res_ops.IMAGE, image_cond)[0] if image_inv.format != 'raw': test_util.test_fail('image\' format is not raw,fail') test_lib.lib_robot_cleanup(test_dict) test_util.test_pass('test add image auto format success!')
def test(): global agent_url global agent_url2 global vm flavor = case_flavor[os.environ.get('CASE_FLAVOR')] agent_url = flavor['agent_url'] script = ''' { entity -> throw new Exception("shuang") } ''' if agent_url != None: deploy_operations.remove_simulator_agent_script(agent_url) deploy_operations.deploy_simulator_agent_script(agent_url, script) if agent_url == FLAT_DHCP_RELEASE or agent_url == LOCAL_DELETE: agent_url2 = CREATE_VOLUME deploy_operations.remove_simulator_agent_script(agent_url2) deploy_operations.deploy_simulator_agent_script(agent_url2, script) l3net_uuid = test_lib.lib_get_l3_by_name(os.environ.get('l3VlanNetworkName3')).uuid is_flat = test_lib.lib_get_flat_dhcp_by_l3_uuid(l3net_uuid) if is_flat: try: dhcp_ip = net_ops.get_l3network_dhcp_ip(l3net_uuid) except: dhcp_ip = None else: dhcp_ip = None imagestore = test_lib.lib_get_image_store_backup_storage() if imagestore == None: test_util.test_skip('Required imagestore to test') cond = res_ops.gen_query_conditions('type', '=', 'LocalStorage') local_pss = res_ops.query_resource(res_ops.PRIMARY_STORAGE, cond) if len(local_pss) == 0: test_util.test_skip('Required ceph ps to test') ps_uuid = local_pss[0].uuid image_creation_option = test_util.ImageOption() imagestore = test_lib.lib_get_image_store_backup_storage() bs_uuid = imagestore.uuid 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 = img_ops.add_image(image_option) image_uuid = image.uuid saved_db_stats = test_stub.get_db_stats(dhcp_ip) create_vm_failure = False try: vm = test_stub.create_vm(image_uuid=image_uuid, ps_uuid=ps_uuid) except: create_vm_failure = True if agent_url != None and not create_vm_failure: test_util.test_fail("Expect failure during creating VM while it passed. Test Exception handling for Create VM FAIL") if agent_url != None: if is_flat: try: dhcp_ip = net_ops.get_l3network_dhcp_ip(l3net_uuid) except: dhcp_ip = None else: dhcp_ip = None saved_db_stats2 = test_stub.get_db_stats(dhcp_ip) test_stub.compare_db_stats(saved_db_stats, saved_db_stats2, db_tables_white_list)
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 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!')