From 33ccfc3466d4eb48caf4f0866c38f3f574b987b2 Mon Sep 17 00:00:00 2001 From: byb11 Date: Wed, 12 May 2021 15:16:59 +0800 Subject: [PATCH] =?UTF-8?q?1.=E6=96=B0=E5=A2=9E=E4=B8=8A=E4=BC=A0Log?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E7=BA=AF=E6=8E=A5=E5=8F=A3=E5=8F=8A=E9=92=88?= =?UTF-8?q?=E5=AF=B9=E5=85=A8=E6=B5=81=E7=A8=8Blog=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E7=9A=84=E7=9B=AE=E7=9A=84=E6=80=A7=E9=AA=8C?= =?UTF-8?q?=E8=AF=81=E5=85=B3=E9=94=AE=E5=AD=97=E5=8F=8A=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api_log/LogPureInterfaceCase.robot | 30 +++- .../api_log/LogPurposeInterfaceCase.robot | 54 ++++++++ .../tsg_bfapi/api_log/NewApiLogCase.robot | 130 ------------------ .../Custometest/LogResponseVAL.py | 30 +++- 04-CustomLibrary/Custometest/LogSchema.py | 123 +++++++++++++++-- 5 files changed, 222 insertions(+), 145 deletions(-) create mode 100644 01-TestCase/tsg_bfapi/api_log/LogPurposeInterfaceCase.robot diff --git a/01-TestCase/tsg_bfapi/api_log/LogPureInterfaceCase.robot b/01-TestCase/tsg_bfapi/api_log/LogPureInterfaceCase.robot index 39c184a..323ae1f 100644 --- a/01-TestCase/tsg_bfapi/api_log/LogPureInterfaceCase.robot +++ b/01-TestCase/tsg_bfapi/api_log/LogPureInterfaceCase.robot @@ -1,9 +1,7 @@ *** Settings *** -Force Tags tsg_adc_wp Resource ../../../03-Variable/BifangApiVariable.txt Library ../../../04-CustomLibrary/Custometest/LogSchema.py Library ../../../04-CustomLibrary/Custometest/LogResponseVAL.py -Resource ../../../05-Other/AllFlowCaseVariable1.txt Library DateTime Library json Library OperatingSystem @@ -59,6 +57,18 @@ LogExportVerifyCase ${Schemaurl} Set Variable http://${host}:${port}/v1/log/schema?logType=${logType} exportlog ${Logurl} ${Schemaurl} ${token} ${StartTime1} ${EndTime1} ${logType} ${filter} END + +LogExportCeilingVerifyCase + [Documentation] 验证日志导出接口上限测试,当前导出上限为十万 + ${Logurl} Set Variable http://${host}:${port}/v1/log/batch + ${logTypelist} create list security_event_log proxy_event_log connection_record_log radius_record_log voip_record_log live_session_record_log transaction_record_log gtpc_record_log + ${StartTime1} Set Variable 2020-05-01 00:00:00 + ${EndTime1} Set Variable 2021-05-01 00:00:00 + ${filter} Set Variable + FOR ${logType} in @{logTypelist} + ${Schemaurl} Set Variable http://${host}:${port}/v1/log/schema?logType=${logType} + exportlog ${Logurl} ${Schemaurl} ${token} ${StartTime1} ${EndTime1} ${logType} ${filter} + END LogRetrieveVerifyCase [Documentation] 验证日志检索条件接口 @@ -74,6 +84,22 @@ LogRetrieveVerifyCase ${responsebody} loglistverify ${Logurl} ${Schemaurl} ${token} ${StartTime1} ${EndTime1} ${logType} ${filter} LogRetrieve ${Schemaurl} ${host} ${port} ${token} ${logType} ${responsebody} END + +LogRetrieveComplexSqlVerifyCase + [Documentation] 日志检索条件接口复杂SQL验证 + ${Logurl} Set Variable http://${host}:${port}/v1/log/list + ${logTypelist} create list security_event_log connection_record_log security_event_log proxy_event_log connection_record_log radius_record_log voip_record_log live_session_record_log transaction_record_log gtpc_record_log + ${EndTime} get current date + ${EndTime1} Get Substring ${EndTime} \ -4 + ${StartTime} add time to date ${EndTime} -03:00:00 + ${StartTime1} Get Substring ${StartTime} \ -4 + ${filter} Set Variable + FOR ${logType} in @{logTypelist} + ${Schemaurl} Set Variable http://${host}:${port}/v1/log/schema?logType=${logType} + ${responsebody} loglistverify ${Logurl} ${Schemaurl} ${token} ${StartTime1} ${EndTime1} ${logType} ${filter} + LogRetrieveSql ${Schemaurl} ${host} ${port} ${token} ${logType} ${responsebody} + END + diff --git a/01-TestCase/tsg_bfapi/api_log/LogPurposeInterfaceCase.robot b/01-TestCase/tsg_bfapi/api_log/LogPurposeInterfaceCase.robot new file mode 100644 index 0000000..554a285 --- /dev/null +++ b/01-TestCase/tsg_bfapi/api_log/LogPurposeInterfaceCase.robot @@ -0,0 +1,54 @@ +*** Settings *** +Force Tags tsg_adc_wp +Resource ../../../03-Variable/BifangApiVariable.txt +Library ../../../04-CustomLibrary/Custometest/LogSchema.py +Resource ../../../05-Other/AllFlowCaseVariable1.txt +Library OperatingSystem +Library Selenium2Library +Library RequestsLibrary +Library Collections +Library String + +*** Variables *** + +*** Test Cases *** + +LogAllConditionsVerifyCase + [Documentation] 全流程日志各字段查询 + ${Logurl} Set Variable http://${host}:${port}/v1/log/list + ${logTypelist} create list security_event_log proxy_event_log connection_record_log radius_record_log voip_record_log live_session_record_log transaction_record_log gtpc_record_log + ${EndTime1} Set Variable ${endtime} + ${StartTime1} Set Variable ${starttime} + ${filter} Set Variable + FOR ${logType} in @{logTypelist} + ${Schemaurl} Set Variable http://${host}:${port}/v1/log/schema?logType=${logType} + ${responsebody} loglistverify ${Logurl} ${Schemaurl} ${token} ${StartTime1} ${EndTime1} ${logType} ${filter} + log ${responsebody} + logAllFieldsListInterface ${Logurl} ${Schemaurl} ${token} ${StartTime1} ${EndTime1} ${logType} ${responsebody} ${lognumber} ${logcycles} + END + +LogFieldVerifyCase + [Documentation] 全流程日志详情字段 + ${Logurl} Set Variable http://${host}:${port}/v1/log/list + ${logTypelist} create list security_event_log proxy_event_log connection_record_log radius_record_log voip_record_log live_session_record_log transaction_record_log gtpc_record_log + ${EndTime1} Set Variable ${endtime} + ${StartTime1} Set Variable ${starttime} + ${filter} Set Variable + FOR ${logType} in @{logTypelist} + ${Schemaurl} Set Variable http://${host}:${port}/v1/log/schema?logType=${logType} + ${responsebody} loglistverify ${Logurl} ${Schemaurl} ${token} ${StartTime1} ${EndTime1} ${logType} ${filter} + log ${responsebody} + LogFieldValidation ${Schemaurl} ${token} ${responsebody} + END + +LogExportVerifyCase + [Documentation] 全流程日志导出 + ${Logurl} Set Variable http://${host}:${port}/v1/log/batch + ${logTypelist} create list security_event_log proxy_event_log connection_record_log radius_record_log voip_record_log live_session_record_log transaction_record_log gtpc_record_log + ${EndTime1} Set Variable ${endtime} + ${StartTime1} Set Variable ${starttime} + ${filter} Set Variable + FOR ${logType} in @{logTypelist} + ${Schemaurl} Set Variable http://${host}:${port}/v1/log/schema?logType=${logType} + exportlog ${Logurl} ${Schemaurl} ${token} ${StartTime1} ${EndTime1} ${logType} ${filter} + END \ No newline at end of file diff --git a/01-TestCase/tsg_bfapi/api_log/NewApiLogCase.robot b/01-TestCase/tsg_bfapi/api_log/NewApiLogCase.robot index 5d002f6..88e2227 100644 --- a/01-TestCase/tsg_bfapi/api_log/NewApiLogCase.robot +++ b/01-TestCase/tsg_bfapi/api_log/NewApiLogCase.robot @@ -145,136 +145,6 @@ LogApiVerifyCase-007 log ${responsebody} - -###################################################白云波 20.15版本接口测试#################################################################### - -LogGTPFieldVerifyCase - [Documentation] 验证api接口:验证Session Records 日志GTP字段丰富验证 - ${Logurl} Set Variable http://${host}:${port}/v1/log/list - ${logType} Set Variable connection_record_log - ${Schemaurl} Set Variable http://${host}:${port}/v1/log/schema?logType=${logType} - ${EndTime} get current date - ${EndTime1} Get Substring ${EndTime} \ -4 - ${StartTime} add time to date ${EndTime} -01:00:00 - ${StartTime1} Get Substring ${StartTime} \ -4 - ${filter} Set Variable ${条件待定} - ${responsebody} loglistverify ${Logurl} ${Schemaurl} ${token} ${StartTime1} ${EndTime1} ${logType} ${filter} - ${targetdict} create list tunnel_schema_type gtp_SGW_ip gtp_PGW_ip gtp_SGW_port gtp_PGW_port gtp_uplink_TEID gtp_downlink_TEID mpls_c2s_direction_label mpls_s2c_direction_label - ... vlan_c2s_direction_id vlan_s2c_direction_id source_mac destination_mac c2s_source_mac c2s_destination_mac s2c_source_mac s2c_destination_mac - log ${responsebody} - ${strlist} FieldValidation ${responsebody} ${targetdict} - log ${strlist} - - - LiveSessionRecordLogApiVerifyCase - [Documentation] live_session_record_log纯接口测试用例 - ${Logurl} Set Variable http://${host}:${port}/v1/log/list - ${logType} Set Variable live_session_record_log - ${Schemaurl} Set Variable http://${host}:${port}/v1/log/schema?logType=${logType} - ${EndTime} get current date - ${EndTime1} Get Substring ${EndTime} \ -4 - ${StartTime} add time to date ${EndTime} -01:00:00 - ${StartTime1} Get Substring ${StartTime} \ -4 - logapiverify ${Logurl} ${Schemaurl} ${token} ${StartTime1} ${EndTime1} ${logType} - -LiveSessionRecordLogCount - [Documentation] live_session_record_log统计日志总数 - ${Logurl} Set Variable http://${host}:${port}/v1/log/count - ${logType} Set Variable live_session_record_log - ${EndTime} get current date - ${EndTime1} Get Substring ${EndTime} \ -4 - ${StartTime} add time to date ${EndTime} -01:00:00 - ${StartTime1} Get Substring ${StartTime} \ -4 - ${count} countlog_query ${Logurl} ${token} ${StartTime1} ${EndTime1} ${logType} - log ${count} - -LiveSessionRecordLogExportLog - [Documentation] live_session_record_log导出日志 - ${Logurl} Set Variable http://${host}:${port}/v1/log/batch - ${logType} Set Variable live_session_record_log - ${Schemaurl} Set Variable http://${host}:${port}/v1/log/schema?logType=${logType} - ${EndTime} get current date - ${EndTime1} Get Substring ${EndTime} \ -4 - ${StartTime} add time to date ${EndTime} -01:00:00 - ${StartTime1} Get Substring ${StartTime} \ -4 - ${filter} Set Variable - exportlog ${Logurl} ${Schemaurl} ${token} ${StartTime1} ${EndTime1} ${logType} ${filter} - - -LiveSessionRecordLogRetrievalConditionApiVerify - [Documentation] 验证api接口:日志检索条件校验(filter内容验证) - ${logType} Set Variable live_session_record_log - ${filter} Set Variable common_recv_time = 45535 - ${urlpath} Set Variable ?logType=${logType}&filter=${filter} - ${Logurl} Set Variable http://${host}:${port}/v1/interface/gateway/sql/galaxy/log/filter/validation${urlpath} - ${responsebody} distributed_query ${Logurl} ${token} - log ${responsebody} - - -TransactionRecordLogApiVerifyCase - [Documentation] transaction_record_log纯接口测试用例 - ${Logurl} Set Variable http://${host}:${port}/v1/log/list - ${logType} Set Variable transaction_record_log - ${Schemaurl} Set Variable http://${host}:${port}/v1/log/schema?logType=${logType} - ${EndTime} get current date - ${EndTime1} Get Substring ${EndTime} \ -4 - ${StartTime} add time to date ${EndTime} -01:00:00 - ${StartTime1} Get Substring ${StartTime} \ -4 - logapiverify ${Logurl} ${Schemaurl} ${token} ${StartTime1} ${EndTime1} ${logType} - -TransactionRecordLogCount - [Documentation] transaction_record_log统计日志总数 - ${Logurl} Set Variable http://${host}:${port}/v1/log/count - ${logType} Set Variable transaction_record_log - ${EndTime} get current date - ${EndTime1} Get Substring ${EndTime} \ -4 - ${StartTime} add time to date ${EndTime} -01:00:00 - ${StartTime1} Get Substring ${StartTime} \ -4 - ${count} countlog_query ${Logurl} ${token} ${StartTime1} ${EndTime1} ${logType} - log ${count} - -TransactionRecordLogExportLog - [Documentation] transaction_record_log导出日志 - ${Logurl} Set Variable http://${host}:${port}/v1/log/batch - ${logType} Set Variable transaction_record_log - ${Schemaurl} Set Variable http://${host}:${port}/v1/log/schema?logType=${logType} - ${EndTime} get current date - ${EndTime1} Get Substring ${EndTime} \ -4 - ${StartTime} add time to date ${EndTime} -01:00:00 - ${StartTime1} Get Substring ${StartTime} \ -4 - ${filter} Set Variable - exportlog ${Logurl} ${Schemaurl} ${token} ${StartTime1} ${EndTime1} ${logType} ${filter} - - -TransactionRecordLogRetrievalConditionApiVerify - [Documentation] transaction_record_log:日志检索条件校验(filter内容验证) - ${logType} Set Variable transaction_record_log - ${filter} Set Variable common_recv_time = 45535 - ${urlpath} Set Variable ?logType=${logType}&filter=${filter} - ${Logurl} Set Variable http://${host}:${port}/v1/interface/gateway/sql/galaxy/log/filter/validation${urlpath} - ${responsebody} distributed_query ${Logurl} ${token} - log ${responsebody} - - - - - - - - - - - - - - - - - - - - - diff --git a/04-CustomLibrary/Custometest/LogResponseVAL.py b/04-CustomLibrary/Custometest/LogResponseVAL.py index ce80d98..dbf6474 100644 --- a/04-CustomLibrary/Custometest/LogResponseVAL.py +++ b/04-CustomLibrary/Custometest/LogResponseVAL.py @@ -1,3 +1,6 @@ +import re +import time + import jsonpath # 1.说明:本方法用于对日志接口返回数据中的字段和数据进行判断 # 2.传入数据说明:responsedict - 接口返回数据的json数据 @@ -35,11 +38,21 @@ def FieldValidation(responsedict, targetlist): responsevalue=str(responsevalue) if len(target) == 3: targetvalue = target[2] - p = conditional(conditions, responsevalue, targetkey, sum, targetvalue) - strlist.append(p) + torf=is_valid_date(responsevalue) + if torf == True: + timeArray = time.strptime(responsevalue, "%Y-%m-%d %H:%M:%S") + timeStamp = str(int(time.mktime(timeArray))) + p = conditional(conditions, timeStamp, targetkey, sum, targetvalue) + if p != "": + strlist.append(p) + else: + p = conditional(conditions, responsevalue, targetkey, sum, targetvalue) + if p != "": + strlist.append(p) elif len(target) == 2: p = conditional(conditions, responsevalue, targetkey, sum) - strlist.append(p) + if p != "": + strlist.append(p) else: str2 = "返回数据第" + str(sum) + "组数据中不存在该字段:" + target[0] print(str2) @@ -177,3 +190,14 @@ def Assertresults(resultslist): for i in resultslist: if i != "": assert 1 == 2 + + +def is_valid_date(strdate): + '''判断是否是一个有效的日期字符串''' + a = re.findall(":", strdate) + b = re.findall("-", strdate) + if len(a) ==2 and len(b) == 2: + return True + else: + return False + diff --git a/04-CustomLibrary/Custometest/LogSchema.py b/04-CustomLibrary/Custometest/LogSchema.py index 8dbe5f4..d190ff1 100644 --- a/04-CustomLibrary/Custometest/LogSchema.py +++ b/04-CustomLibrary/Custometest/LogSchema.py @@ -247,7 +247,6 @@ def logapiverify(schemauerl,logurl, token, starttime, endtime,logtype): def loglistverify(logurl, schemauerl, token, starttime, endtime, logtype, filtervalue): a = schema(schemauerl, token) fields = a["data"]["fields"] - print(fields) url = logurl # "http://192.168.44.72:8080/v1/log/list" headers = {"Content-Type": "application/json", "Authorization": token} @@ -258,12 +257,85 @@ def loglistverify(logurl, schemauerl, token, starttime, endtime, logtype, filter "fields": fields, "filter": filtervalue } + # print(json.dumps(data)) response1 = requests.post(url=url, data=json.dumps(data), headers=headers) code = response1.json()["code"] assert code == 200 print(response1.json()["code"]) return response1.json() +#目的性验证,循坏返回列表中所有字段进行查询 +def loglistverifys(logurl, schemaurl, token, starttime, endtime, logtype, datajson): + nullkey = [] + data = datajson + keylist = LogResponseVAL.getKeys(data) + a = schema(schemaurl, token) + fields = a["data"]["fields"] + for i in keylist: + conditions = data[i] + for field in fields: + name = field["name"] + if field["doc"] == None or field["doc"]["visibility"] == None: + if i == name: + if conditions != None and conditions != "": + if field["type"] == "string": + if conditions[0] == "'" and conditions[-1] == "'": + filtervalue = i + " = " + conditions + VasserValue=i + " = " + conditions[1:-1] + + else: + filtervalue = i + " = " + "'" + conditions + "'" + VasserValue= i + " = " + conditions + else: + if i == "common_recv_time" or i == "common_start_time" or i == "common_end_time" or i == "common_processing_time": + timeArray = time.strptime(conditions, "%Y-%m-%d %H:%M:%S") + timeStamp = str(int(time.mktime(timeArray))) + filtervalue = i + " = " + timeStamp + VasserValue = filtervalue + + else: + filtervalue = i + " = " + str(conditions) + VasserValue = filtervalue + print("filtervalue",filtervalue) + #根据提取条件进行查询日志列表 + responsebody = loglistverify(logurl, schemaurl, token, starttime, endtime, logtype, + filtervalue) + filterlist=[VasserValue] + print(VasserValue) + LogResponseVAL.FieldValidation(responsebody,filterlist) + + else: + nullkey.append(i) #所有为None或者“”的字段 + return nullkey + + # 多条循环 变量设置为公共参数 若循环内一个字段没有值 进行下次循坏 +def logAllFieldsListInterface(logurl, schemaurl, token, starttime, endtime, logtype, datajson,lognumber,logcycles): + datalist = datajson["data"]["list"] + keylist=[] + number=0 + print(lognumber) + print(type(lognumber)) + print(logcycles) + print(type(logcycles)) + for i in range(0, len(datalist), int(lognumber)):# 循环取出count个列表元素 + number+=1 + nullkeylist=[] + ret=datalist[i:i + int(lognumber)] + for data in ret: + nullkey=loglistverifys(logurl, schemaurl, token, starttime, endtime, logtype, data) + nullkeylist.append(nullkey) + print(nullkeylist) + for j in nullkeylist: + #对返回的为空的key进行取交集 + if len(keylist) == 0: + keylist=j + else: + #取两个列表的交集 + keylist=list(set(keylist).intersection(set(j))) + if len(keylist) == 0 or number >= int(logcycles): + break + print("最终数据中没有值的字段为:",keylist) + # 事件日志和通联日志时间分布查询 ,日志检索条件校验(filter内容验证) def distributed_query(logurl, token): @@ -291,23 +363,54 @@ def LogRetrieve(schemaurl,host,port,token,logType,datajson): if i == name: if field["type"] == "string": filter = "logType=" + logType + "&" + "filter=" + i + "=" + "'" + str1 + "'" - Logurl = "http://" + host + ":" + port + "/v1/interface/gateway/sql/galaxy/log/filter/validation?" + filter - print(Logurl) - responsebody = distributed_query(Logurl, token) else: if i == "common_recv_time" or i == "common_start_time" or i == "common_end_time" or i == "common_processing_time": timeArray = time.strptime(conditions, "%Y-%m-%d %H:%M:%S") timeStamp = str(int(time.mktime(timeArray))) filter = "logType=" + logType + "&" + "filter=" + i + "=" + timeStamp - Logurl = "http://" + host + ":" + port + "/v1/interface/gateway/sql/galaxy/log/filter/validation?" + filter - print(Logurl) - responsebody = distributed_query(Logurl, token) else: filter = "logType=" + logType + "&" + "filter=" + i + "=" + str(number) - Logurl = "http://" + host + ":" + port + "/v1/interface/gateway/sql/galaxy/log/filter/validation?" + filter - print(Logurl) - responsebody = distributed_query(Logurl, token) + Logurl = "http://" + host + ":" + port + "/v1/interface/gateway/sql/galaxy/log/filter/validation?" + filter + print(Logurl) + responsebody = distributed_query(Logurl, token) +# 日志检索条件校验 复杂sql +def LogRetrieveSql(schemaurl,host,port,token,logType,datajson): + data = datajson["data"]["list"][0] + keylist = LogResponseVAL.getKeys(data) + sqllist=random.sample(keylist, 4) + number = 45585 + str1 = random.choice('abcdefghijklmnopqrstuvwxyz') + print(sqllist) + a = schema(schemaurl, token) + filterlist=[] + fields=a["data"]["fields"] + for i in sqllist: + conditions = data[i] + for field in fields: + name = field["name"] + if i == name: + if field["type"] == "string": + if conditions == "" or conditions == None: + conditions=str1 + filter = i + "=" + "'" + conditions + "'" + else: + if i == "common_recv_time" or i == "common_start_time" or i == "common_end_time" or i == "common_processing_time": + timeArray = time.strptime(conditions, "%Y-%m-%d %H:%M:%S") + timeStamp = str(int(time.mktime(timeArray))) + filter =i + "=" + timeStamp + else: + if conditions == "" or conditions == None: + conditions = number + filter = i + "=" + str(conditions) + print(filter) + filterlist.append(filter) + sqlfilter = "(("+filterlist[0]+" OR "+filterlist[1]+") AND "+filterlist[2]+") OR "+filterlist[3] + _filter = "logType=" + logType + "&" + "filter=" + sqlfilter + Logurl = "http://" + host + ":" + port + "/v1/interface/gateway/sql/galaxy/log/filter/validation?" + _filter + print(Logurl) + responsebody = distributed_query(Logurl, token) + print(sqlfilter) # 原始日志检索时间分布计算 def timedistribution(logurl, token, starttime, endtime, logtype, granularity, filtervalue):