def test_update_network_object(uri, headers, resourcepool, network_name, objectName, updata_object_name, resourcePoolType): id = get_network_object_id(uri, headers, resourcepool, network_name, objectName) network_id = get_network_id(uri, headers, network_name) object_id = get_network_dvportgroup_id(uri, headers, resourcePoolType, resourcepool, updata_object_name) resourcePoolId = get_resourcepoolid(uri, headers, resourcepool) param = { # 'id': id, 'networkId': network_id, 'objectId': object_id, 'objectName': updata_object_name, # 'objectType': 'DistributePortGroup', 'resourcePoolId': resourcePoolId # 'resourcePoolName': resourcepool, # 'resourcePoolType': resourcePoolType } update_network_object_response = requests.put( url=uri + update_network_object_url_path + str(id) + '?networkId=' + str(network_id), headers=headers, json=param).json() code = update_network_object_response['status'] allure.attach("请求响应code", str(update_network_object_response['status'])) allure.attach("请求响应结果", str(update_network_object_response)) my_log().info(update_network_object_response) assert code == 200
def test_update_datacenter(uri, headers, ID, testcases, regionname, update_region, description, status_code): """ 编辑数据中心 :param uri: :param headers: :param ID: :param testcases: :param regionname:需要编辑的数据中心名称 :param update_region: 更改的数据中心名称 :param description: 更改后的数据中心描述 :return: """ regionId = str(get_datacenterid(uri, headers, regionname)) update_datacenter_data = { "name": update_region, "description": description } update_datacenter_response = requests.post( url=uri + createDataCenter_url + "/" + regionId, data=json.dumps(update_datacenter_data), headers=headers).json() allure.attach("请求响应code", str(update_datacenter_response['status'])) allure.attach("请求响应结果", str(update_datacenter_response)) my_log().info(update_datacenter_response) AssertUtil().assert_code(update_datacenter_response['status'], status_code) assert update_region in get_datacenter(uri, headers)
def test_category_relationship(uri, headers, ID, testcases, categoryfrom, relationship, categoryto,status_code, expected_result): """ 创建配置类型间关系 :param uri: :param headers: :param ID: :param testcases: :param categoryfrom:源配置项类型 :param relationship:关系 :param categoryto:目的配置项类型 :return: """ category_from = get_categorykey(categoryfrom) category_to = get_categorykey(categoryto) relationshipkey = get_dictionary(relationship) create_categoryRelationship_param = { "_to": category_to, "_from": category_from, "dictionaryItemKey": relationshipkey._key } create_categoryRelationship_response = requests.post(url = uri + category_relationship_url, headers = headers, json= create_categoryRelationship_param).json() allure.attach("请求响应code", str(create_categoryRelationship_response['status'])) allure.attach("请求响应结果", str(create_categoryRelationship_response)) my_log().info(create_categoryRelationship_response) AssertUtil().assert_code(create_categoryRelationship_response['status'], status_code) AssertUtil().assert_in_body(create_categoryRelationship_response['data'], expected_result)
def test_udpate_user(uri, headers, ID, org_name, account, name, status, mobilePhone, birstday, sex, isManager, roles): user_id = str(get_user_account_id(uri, headers, account, org_name)) roled = json.loads(roles) update_user_param = { "account": account, "name": name, "mobilePhone": mobilePhone, "extra": { "birstday": birstday, "sex": sex, "isManager": isManager }, "roles": roled, "status": status, } udpate_user_response = requests.post(url=uri + update_user_url + user_id, headers=headers, json=update_user_param).json() allure.attach("请求响应code", str(udpate_user_response['status'])) allure.attach("请求响应结果", str(udpate_user_response)) my_log().info(udpate_user_response) assert udpate_user_response['status'] == 200 # 断言用户名在列表里 assert account in get_user_account_list(uri, headers, org_name) # 断言姓名在列表里 assert name in get_user_name_list(uri, headers, org_name)
def test_configitem_relationship(uri, headers, ID, testcases, fromcode,configitemfrom, relationship, tocode,configitemto,status_code, expected_result): """ 创建配置项间关系 :param uri: :param headers: :param ID: :param testcases: :param fromcode:源配置项名称code :param configitemfrom:源配置项名称 :param relationship:关系 :param tocode:目的配置项名称code :param configitemto:目的配置项名称 :return: """ relationshipkey = get_dictionary(relationship) configitem_from = get_configitem_key(fromcode,configitemfrom) configitem_to = get_configitem_key(tocode,configitemto) create_configitemRelationship_param = [{ "_to": configitem_to, "_from": configitem_from, "dictionaryItemKey": relationshipkey._key }] create_configitemRelationship_response = requests.post(url = uri + configitem_relationship_url, headers = headers, json =create_configitemRelationship_param).json() allure.attach("请求响应code", str(create_configitemRelationship_response['status'])) allure.attach("请求响应结果", str(create_configitemRelationship_response)) my_log().info(create_configitemRelationship_response) AssertUtil().assert_code(create_configitemRelationship_response['status'], status_code) AssertUtil().assert_in_body(create_configitemRelationship_response['data'], expected_result)
def test_create_user(uri, headers, ID, org_name, account, password, name, status, mobilePhone, birstday, sex, isManager, roles): orgnization_id = get_orgnization_id(uri, headers, org_name) roled = json.loads(roles) create_param = { "account": account, "password": password, "name": name, "mobilePhone": mobilePhone, "extra": { "birstday": birstday, "sex": sex, "isManager": isManager }, "organizations": [orgnization_id], "roles": roled, "status": status, } create_user_response = requests.post(url=uri + create_user_url, headers=headers, json=create_param).json() allure.attach("请求响应code", str(create_user_response['status'])) allure.attach("请求响应结果", str(create_user_response)) my_log().info(create_user_response) assert create_user_response['status'] == 200 # 断言用户名在列表里 assert account in get_user_account_list(uri, headers, org_name) # 断言姓名在列表里 assert name in get_user_name_list(uri, headers, org_name)
def test_update_dictionaries(uri, headers, ID, testcases, dictionaries_name, update_dictionaries_name, status_code, expected_result): DictionaryKey = get_dictionaries_key(dictionaries_name) DictionaryCode = get_dictionaries_code(dictionaries_name) parentDictionaryKey = get_parent_dictionaries_key(dictionaries_name) parentDictionaryCode = get_parent_dictionaries_code(dictionaries_name) update_dictionaries_param = { 'name': update_dictionaries_name, 'code': DictionaryCode, 'properties': { 'reverseName': "" }, 'parentDictionaryKey': parentDictionaryKey, 'parentDictionaryCode': parentDictionaryCode } update_dictionaries_response = requests.put( url=uri + update_dictionaries_url + str(DictionaryKey), headers=headers, json=update_dictionaries_param).json() allure.attach("请求响应code", str(update_dictionaries_response['status'])) allure.attach("请求响应结果", str(update_dictionaries_response)) my_log().info(update_dictionaries_response) AssertUtil().assert_code(update_dictionaries_response['status'], status_code) AssertUtil().assert_in_body(update_dictionaries_response['data'], expected_result)
def test_instance_migrate(uri, headers, vmname, resourcepool, hostname, storename): instance_id = get_instance_id(uri, headers, vmname, resourcepool) instance_migrate_url = create_instance_url + "/" + str(instance_id) + "/migrate" instance_migrateHost_data = { "instanceId": instance_id, "migrateType": "MigrateHost", "hostName": hostname } instance_migrateStore_data = { "instanceId": instance_id, "migrateType": "MigrateStore", "storeName": storename } instance_migrateHost_response = requests.put(url = uri + instance_migrate_url, headers = headers, data = json.dumps(instance_migrateHost_data)).json() allure.attach("请求响应code", str(instance_migrateHost_response['status'])) allure.attach("请求响应结果", str(instance_migrateHost_response)) my_log().info(instance_migrateHost_response) assert instance_migrateHost_response["status"] == 200 time.sleep(30) instance_migrateStore_response = requests.put(url = uri + instance_migrate_url, headers = headers, data = json.dumps(instance_migrateStore_data)).json() allure.attach("请求响应code", str(instance_migrateStore_response['status'])) allure.attach("请求响应结果", str(instance_migrateStore_response)) my_log().info(instance_migrateStore_response) assert instance_migrateStore_response["status"] == 200
def test_create_dictionaries(uri, headers, ID, testcases, dictionaries_name, dictionaries_code, parentDictionary, status_code, expected_result): parentDictionaryKey = get_dictionaries_key(parentDictionary) parentDictionaryCode = get_dictionaries_code(parentDictionary) create_dictionaries_param = { 'name': dictionaries_name, 'code': dictionaries_code, 'properties': { 'reverseName': "" }, 'parentDictionaryKey': parentDictionaryKey, 'parentDictionaryCode': parentDictionaryCode } create_dictionaries_response = requests.post( url=uri + create_dictionaries_url, headers=headers, json=create_dictionaries_param).json() code = create_dictionaries_response['status'] allure.attach("请求响应code", str(create_dictionaries_response['status'])) allure.attach("请求响应结果", str(create_dictionaries_response)) my_log().info(create_dictionaries_response) AssertUtil().assert_code(create_dictionaries_response['status'], status_code) AssertUtil().assert_in_body(create_dictionaries_response['data'], expected_result)
def test_instance_clone(uri, headers, cloned_vmname, resourcepool, count, region, tenant, project, hypervisorType, name, ostype, cpu, memory, network, subnet, ipaddress): instance_id = get_instance_id(uri, headers, cloned_vmname, resourcepool) instance_clone_url = create_instance_url + "/" + str(instance_id) + "/clone" region_id = get_datacenterid(uri, headers, region) resourcepool_id = get_resourcepoolid(uri, headers, resourcepool) tenant_id = get_tenant_id(uri, headers, tenant) project_id = get_project_id(uri, headers, project) disk = get_instance_disks(uri, headers, cloned_vmname, resourcepool) nic = get_intance_nics(uri, headers, cloned_vmname, resourcepool) network_id = get_network_id(uri, headers, network) subnet_id = get_subnet_id(uri, headers, network, subnet) ip_id = get_subnetip_id(uri, headers, network, subnet, ipaddress) object_id = get_object_id(uri,headers, resourcepool,network) instance_clone_param =[{ "count" : count, "regionId" : region_id, "resourcePoolId" : resourcepool_id, "vdcId" : tenant_id, "projectId" : project_id, "hypervisorType" : hypervisorType, "name" : name, "description" : "", "imageId" : "" , "osType" : ostype, "cpu" : cpu, "memory" : memory, "osDatastore" : "", "disks" : [{ "os" : disk["os"], "size" : disk["size"], "id" : None, "name" : disk["name"], "diskId" : None, "diskName" : disk["diskName"], "instanceId" : None, "type" : disk["type"], "configs" : { "datastore" : "" } }], "nics" : [{ "id" : "", "instanceId" : "", "networkId" : network_id, "subnetId" : subnet_id, "ipId" : ip_id, "ip" : ipaddress, "targetId": object_id, "type" : nic["type"], }] }] instance_clone_response = requests.post(url = uri + instance_clone_url, headers = headers, data = json.dumps(instance_clone_param)).json() allure.attach("请求响应code", str(instance_clone_response['status'])) allure.attach("请求响应结果", str(instance_clone_response)) my_log().info(instance_clone_response) assert instance_clone_response["status"] == 200 time.sleep(300)
def test_create_resourcepool_template(uri, headers, init_name, resourcepool, loading, password, username, template_name, resourcepoolType): images_Id = str(get_image_id(uri, headers, init_name)) resourcePoolId = get_resourcepoolid(uri, headers, resourcepool) relavant_id = str( get_template_id(uri, headers, resourcepoolType, resourcepool, template_name)) relation_url = "/relations" create_resourcepool_template_param = [{ "imageId": images_Id, "loading": loading, "extra": { "password": password, "username": username }, "relavant": {}, "relavantId": relavant_id, "relavantName": template_name, "resourcepoolId": resourcePoolId, "resourcepoolType": resourcepoolType }] create_resourcepool_template_response = requests.post( url=uri + get_images_url + images_Id + relation_url, json=create_resourcepool_template_param, headers=headers).json() allure.attach("请求响应code", str(create_resourcepool_template_response['status'])) allure.attach("请求响应结果", str(create_resourcepool_template_response)) my_log().info(create_resourcepool_template_response) assert create_resourcepool_template_response["status"] == 200 # 断言创建的模板关联能在查询到的响应结果中存在 assert template_name in get_template_name_list(uri, headers, init_name)
def test_create_tenant(uri, headers, create_tenant_data): createTenant_response = requests.post(url=uri + create_tenant_url, data=json.dumps(create_tenant_data), headers=headers).json() allure.attach("请求响应code", str(createTenant_response['status'])) allure.attach("请求响应结果", str(createTenant_response)) my_log().info(createTenant_response) assert createTenant_response['status'] == 200
def test_delete_vlanpool(uri, headers,ID,vlanpool_name): vlanpoolId=get_vlanpool_id(uri,headers,vlanpool_name) delete_vlanpool_response=requests.delete(url=uri+delete_vlanpool_url_path+str(vlanpoolId), headers=headers).json() code=delete_vlanpool_response['status'] allure.attach("请求响应code", str(delete_vlanpool_response['status'])) allure.attach("请求响应结果", str(delete_vlanpool_response)) my_log().info(delete_vlanpool_response) assert code == 200
def test_delete_project(uri, headers,ID,testcases,projectname): project_id = get_project_id(uri,headers,projectname) delete_project_response = requests.delete( url=uri + delete_project_url + str(project_id), headers=headers ).json() allure.attach("请求响应code", str(delete_project_response['status'])) allure.attach("请求响应结果", str(delete_project_response)) my_log().info(delete_project_response) assert delete_project_response == 200
def test_instance_delete(uri, headers, vmname, resourcepool): instance_id = get_instance_id(uri, headers, vmname, resourcepool) instance_delete_url = create_instance_url + "/" + str(instance_id) instance_delete_response = requests.delete(url= uri + instance_delete_url, headers = headers).json() allure.attach("请求响应code", str(instance_delete_response['status'])) allure.attach("请求响应结果", str(instance_delete_response)) my_log().info(instance_delete_response) assert instance_delete_response["status"] == 200 time.sleep(300)
def test_instance_delete_nic(uri, headers, vmname, resourcepool, ipaddress): instance_id = get_instance_id(uri, headers, vmname, resourcepool) nic_id = get_instance_nicId(uri, headers, vmname, resourcepool, ipaddress) instance_deleteNic_url = create_instance_url + "/" + str(instance_id) + "/nics/" + str(nic_id) instance_deleteNic_response = requests.delete(url=uri + instance_deleteNic_url, headers = headers).json() allure.attach("请求响应code", str(instance_deleteNic_response['status'])) allure.attach("请求响应结果", str(instance_deleteNic_response)) my_log().info(instance_deleteNic_response) assert instance_deleteNic_response["status"] == 200
def test_delete_network(uri, headers, ID, network_name): networkId = get_network_id(uri, headers, network_name) delete_network_response = requests.delete( url=uri + delete_network_url_path + str(networkId), headers=headers).json() code = delete_network_response['status'] allure.attach("请求响应code", str(delete_network_response['status'])) allure.attach("请求响应结果", str(delete_network_response)) my_log().info(delete_network_response) assert code == 200
def exec(self, sql): try: if self.conn and self.currsor: self.currsor.execute(sql) self.conn.commit() #---这里开始写错了 except Exception as e: self.conn.rollback() my_log().error("mysql执行失败") my_log().error(e) return False return True
def test_delete_tenant(uri, headers,ID,testcases,tenantname): tenant_id=get_tenant_id(uri,headers,tenantname) delete_tenant_response = requests.delete( url=uri + delete_tenant_url + str(tenant_id), headers=headers ).json() code = delete_tenant_response["status"] allure.attach("请求响应code", str(delete_tenant_response['status'])) allure.attach("请求响应结果", str(delete_tenant_response)) my_log().info(delete_tenant_response) assert code == 200
def test_instance_resume(uri, headers, vmname, resourcepool): instance_id = get_instance_id(uri, headers, vmname, resourcepool) instance_resume_url = create_instance_url +"/" + str(instance_id) + "/resume" instance_resume_response = requests.post(url = uri + instance_resume_url, headers = headers).json() allure.attach("请求响应code", str(instance_resume_response['status'])) allure.attach("请求响应结果", str(instance_resume_response)) my_log().info(instance_resume_response) assert instance_resume_response["status"] == 200 #虚拟机恢复后等待15s time.sleep(120)
def test_instance_sync(uri, headers, vmname, resourcepool): instance_id = get_instance_id(uri, headers, vmname, resourcepool) instance_sync_url = create_instance_url + "/sync" instance_sync_data = [instance_id] instance_sync_response = requests.post(url = uri + instance_sync_url, headers = headers, data = json.dumps(instance_sync_data)).json() allure.attach("请求响应code", str(instance_sync_response['status'])) allure.attach("请求响应结果", str(instance_sync_response)) my_log().info(instance_sync_response) assert instance_sync_response["status"] == 200
def test_instance_resetOs(uri, headers, vmname, resourcepool): instance_id = get_instance_id(uri, headers, vmname, resourcepool) instance_resetOs_url = create_instance_url + "/" + str(instance_id) + "/resetOs" instance_resetOs_response = requests.put(url = uri + instance_resetOs_url, headers = headers).json() allure.attach("请求响应code", str(instance_resetOs_response['status'])) allure.attach("请求响应结果", str(instance_resetOs_response)) my_log().info(instance_resetOs_response) assert instance_resetOs_response["status"] == 200 #重置虚拟机后等待5min,需要等待虚拟机创建完成 time.sleep(300)
def test_export_configitems(uri, auth_token, ID, testcases, category): categoryCode = get_category_code(category) headers = {"T-AUTH-TOKEN": auth_token} export_configitems_response = requests.get(url=uri + base_configitems_url + "/export?categoryCode=" + categoryCode, headers=headers).json() allure.attach("请求响应code", str(export_configitems_response['status'])) allure.attach("请求响应结果", str(export_configitems_response)) my_log().info(export_configitems_response) assert export_configitems_response['status'] == 200
def test_delete_image(uri, headers, ID, image_name): images_Id = str(get_imageedited_id(uri, headers, image_name)) delete_images_response = requests.delete(url=uri + get_images_url + images_Id, headers=headers).json() allure.attach("请求响应code", str(delete_images_response['status'])) allure.attach("请求响应结果", str(delete_images_response)) my_log().info(delete_images_response) assert delete_images_response['status'] == 200 # 断言镜像名称不在列表里 assert image_name not in get_images_name_list(uri, headers)
def test_delete_orgnization(uri, headers, ID, name): orgnization_Id = str(get_orgnization_id(uri, headers, name)) delete_orgnization_response = requests.delete( url=uri + update_orgnization_url + orgnization_Id, headers=headers).json() allure.attach("请求响应code", str(delete_orgnization_response['status'])) allure.attach("请求响应结果", str(delete_orgnization_response)) my_log().info(delete_orgnization_response) assert delete_orgnization_response["status"] == 200 # 断言组织已删除 assert name not in get_orgnization_name_list(uri, headers)
def test_delete_datacenter(uri, headers, ID, testcases, regionname, status_code): regionId = str(get_datacenterid(uri, headers, regionname)) delete_datacenter_response = requests.delete( url=uri + createDataCenter_url + "/" + regionId, headers=headers).json() allure.attach("请求响应code", str(delete_datacenter_response['status'])) allure.attach("请求响应结果", str(delete_datacenter_response)) my_log().info(delete_datacenter_response) AssertUtil().assert_code(delete_datacenter_response['status'], status_code) assert regionname not in get_datacenter(uri, headers)
def test_delete_user(uri, headers, ID, org_name, account): # 删除编辑后的用户胡 user_id = str(get_user_account_id(uri, headers, account, org_name)) delete_user_response = requests.delete(url=uri + update_user_url + user_id, headers=headers).json() allure.attach("请求响应code", str(delete_user_response['status'])) allure.attach("请求响应结果", str(delete_user_response)) my_log().info(delete_user_response) assert delete_user_response["status"] == 200 # 断言用户名不在列表里 assert account not in get_user_account_list(uri, headers, org_name)
def test_update_password(uri, headers, ID, password, org_name, account): user_id = str(get_user_account_id(uri, headers, account, org_name)) password_url = "/password" update_password_param = {"password": password} update_user_password_response = requests.post( url=uri + update_user_url + user_id + password_url, headers=headers, json=update_password_param).json() allure.attach("请求响应code", str(update_password_param['status'])) allure.attach("请求响应结果", str(update_password_param)) my_log().info(update_password_param) assert update_user_password_response['status'] == 200
def test_instance_deleteSnapshot(uri, headers): vmname = instance_snapshot_data[0][0] resourcepool = instance_snapshot_data[0][1] instance_id = get_instance_id(uri, headers, vmname, resourcepool) snapshot_id = get_snapshot_id(uri, headers, vmname,resourcepool) instance_deleteSnapshot_url = create_instance_url + "/" + str(instance_id) + "/snapshots/" + str(snapshot_id) instance_deleteSnapshot_response = requests.delete(url = uri + instance_deleteSnapshot_url, headers = headers).json() allure.attach("请求响应code", str(instance_deleteSnapshot_response['status'])) allure.attach("请求响应结果", str(instance_deleteSnapshot_response)) my_log().info(instance_deleteSnapshot_response) assert instance_deleteSnapshot_response["status"] == 200
def get_instance_db(vmname): """ 查询instance表 :param vmname: :return: """ sql = init_mysqldb("tcrc_db") try: db_res = sql.fetchone("select * from cmp_compute.instance where name='%s'" % vmname) return db_res except: my_log("cmp_compute_instance").error("%s名称虚拟机不存在" % vmname)