diff --git a/01-TestCase/tsg_bfapi/policy_object/PolicyObjectTests.robot b/01-TestCase/tsg_bfapi/policy_object/PolicyObjectTests.robot index 8436c23..0693de1 100644 --- a/01-TestCase/tsg_bfapi/policy_object/PolicyObjectTests.robot +++ b/01-TestCase/tsg_bfapi/policy_object/PolicyObjectTests.robot @@ -581,4 +581,19 @@ Policy-Import-v1-00032 Policy-Export-v1-00033 Comment 导 出Excel ${objectIds} Set Variable ${EMPTY} - ${response} ExportObject ip endpoint ${EMPTY} ${EMPTY} \ No newline at end of file + ${response} ExportObject ip endpoint ${EMPTY} ${EMPTY} +Policy-Sort-v1-00034 + Comment 策略排序 + ${objectIds} Set Variable ${EMPTY} + ${params} Create Dictionary policyType=tsg_security policyId=${1517} afterPolicyId=${1518} + ${params1} Create Dictionary policyType=tsg_security policyId=${1515} beforePolicyId=${1514} + ${paramsList} Create List ${params} ${params1} + ${response} SortPolicies ${paramsList} +Policy-Statistics-v1-00035 + Comment 策略统计 + ${objectIds} Set Variable ${EMPTY} + ${response} StatisticsPolicies +Policy-ProtocolFields-v1-00035 + Comment 策略对象生效协议字段查询 + ${objectIds} Set Variable ${EMPTY} + ${response} PolicProtocolFields tsg_security ${EMPTY} ip \ No newline at end of file diff --git a/02-Keyword/tsg_bfapi/policy_object/Object.robot b/02-Keyword/tsg_bfapi/policy_object/Object.robot index ccfc058..67cd4bc 100644 --- a/02-Keyword/tsg_bfapi/policy_object/Object.robot +++ b/02-Keyword/tsg_bfapi/policy_object/Object.robot @@ -183,4 +183,20 @@ CountLines ${count} Run Keyword If "${line[0]}"=="0" and ${len}>0 Set Variable ${count} ... ELSE Evaluate ${count}+1 END - [Return] ${count} \ No newline at end of file + [Return] ${count} +PolicProtocolFields + [Documentation] + ... 策略对象生效协议字段查询 + ... policyType策略类型 + ... protocol协议 + ... objectType对象类型 + [Arguments] ${policyType} ${protocol} ${objectType} + ${dict} Create Dictionary + Run Keyword If "${policyType}"!="${EMPTY}" Set To Dictionary ${dict} policyType=${policyType} + Run Keyword If "${protocol}"!="${EMPTY}" Set To Dictionary ${dict} protocol=${protocol} + Run Keyword If "${objectType}"!="${EMPTY}" Set To Dictionary ${dict} objectType=${objectType} + ${parmStr} Dictionary-To-QueryParams ${dict} + ${response} BaseFormRequest ${objectUrl}/protocolFields ${parmStr} ${version} + ${rescode} Set Variable ${response['code']} + Should Be Equal As Strings ${rescode} 200 + [Return] ${response['data']} \ No newline at end of file diff --git a/02-Keyword/tsg_bfapi/policy_object/Policy.robot b/02-Keyword/tsg_bfapi/policy_object/Policy.robot index aa96408..e8c506a 100644 --- a/02-Keyword/tsg_bfapi/policy_object/Policy.robot +++ b/02-Keyword/tsg_bfapi/policy_object/Policy.robot @@ -37,7 +37,7 @@ AddPolicies ... v2版本中无referenceObject,取而代之的是source,destination,filterList ... source= ${265}|TSG_FIELD_HTTP_HOST,${266}|TSG_FIELD_SSL_SNI&TSG_FIELD_SSL_SAN ... destination= ${265}|TSG_FIELD_HTTP_HOST,${266}|TSG_FIELD_SSL_SNI&TSG_FIELD_SSL_SAN - ... filterList= ${265}|${257}:TSG_FIELD_HTTP_HOST,${266}|${299}:TSG_FIELD_SSL_SNI&TSG_FIELD_SSL_SAN + ... filterList= ${265}|${257}:TSG_FIELD_HTTP_HOST,${266}|${299}:TSG_FIELD_SSL_SNI ... filterList由多个数字用‘|’分隔,加上:对上对应的protocolFiled, ... 一个filter中的protocolFiled是确定的,一个protocolFiled对应多个objectId ... appIdObjects==${2},${3} @@ -187,4 +187,30 @@ GetPolicyTotal Should Be Equal As Strings ${rescode} 200 ${total} Set Variable ${response['data']['policyNum']} ${total} Evaluate ${total} - ${initializeNum} - [Return] ${total} \ No newline at end of file + [Return] ${total} +SortPolicies + [Documentation] + ... 将策略排序 + ... policyList + ... 支持list dict两种结构 + ... dict结构:policyType=tsg_security policyId=${1517} afterPolicyId=${1518} + [Arguments] ${policyList} + Should Not Be Empty ${policyList} + ${isList} Evaluate isinstance(${policyList},list) + ${policyJson} Run Keyword If "${isList}"=="True" SortPolicyList ${policyList} + ... ELSE SortPolicyObject ${policyList} + + ${response} BasePostRequestForV2 ${policyUrl}/moveto {"policyList":${policyJson}} ${version} + ${rescode} Set Variable ${response['code']} + Should Be Equal As Strings ${rescode} 200 + [Return] ${response} +StatisticsPolicies + [Documentation] + ... 获取策略总量 + ... 不需要传参 + [Arguments] + ${response} BaseFormRequest ${policyUrl}/statistics ${EMPTY} ${version} + ${rescode} Set Variable ${response['code']} + Should Be Equal As Strings ${rescode} 200 + ${data} Set Variable ${response['data']} + [Return] ${data} \ No newline at end of file diff --git a/02-Keyword/tsg_bfapi/policy_object/ProcessPolicyBody.robot b/02-Keyword/tsg_bfapi/policy_object/ProcessPolicyBody.robot index d691aad..7873018 100644 --- a/02-Keyword/tsg_bfapi/policy_object/ProcessPolicyBody.robot +++ b/02-Keyword/tsg_bfapi/policy_object/ProcessPolicyBody.robot @@ -277,9 +277,9 @@ ManageClientSubIDObjectV2 AnalysisObjectV2 [Arguments] ${policy} ${objectType} ${objList} Log To Console Call AnalysisObjectV2 - ${policyObjectDefault} Run Keyword If "${objectType}"=="source" Set Variable ${Default_v2_SourceObject} - ... ELSE IF "${objectType}"=="destination" Set Variable ${Default_v2_DestinationObject} - ... ELSE IF "${objectType}"=="filterList" Set Variable ${Default_v2_FilterObject} + ${policyObjectDefault} Run Keyword If "${objectType}"=="source" Set Variable ${EMPTY} + ... ELSE IF "${objectType}"=="destination" Set Variable ${EMPTY} + ... ELSE IF "${objectType}"=="filterList" Set Variable ${EMPTY} ${return} ${objectList} Run Keyword And Ignore Error Get From Dictionary ${policy} ${objectType} @@ -287,7 +287,7 @@ AnalysisObjectV2 ${objectList} Run Keyword If "${return}"=="FAIL" or "${objectList}"=="${EMPTY}" Set Variable ${policyObjectDefault} ... ELSE Set Variable ${objectList} - ${list} Evaluate re.split('[,]', '${objectList}') re + ${list} Evaluate re.split('[,]', '${objectList}') re FOR ${var} IN @{list} ${tempObj} Run Keyword If "${objectType}"=="filterList" and "${var}" != "" ManageFilter ${var} ... ELSE IF "${var}" != "" ManageObject ${var} ELSE Set Variable ${EMPTY} @@ -314,7 +314,7 @@ ManageFilter [Documentation] ... filterList处理 [Arguments] ${filter} - Log To Console Call ManageFilter + Log Call ManageFilter ${filterObjectList} Create List #截取objectId ${objectIds} Evaluate '${filter}'[0:'${filter}'.find(':')] @@ -322,6 +322,7 @@ ManageFilter ${protocolField} Evaluate '${filter}'['${filter}'.find(':')+1:] #遍历 objectId ${list} Evaluate re.split('[|]', '${objectIds}') re + Log list ${list} FOR ${var} IN @{list} ${tempObj} Create Dictionary ${var} Run Keyword If '${var}'.isdigit() Evaluate int('${var}') @@ -471,4 +472,37 @@ ManageStringAttributeValue ${string} Get From Dictionary ${attributeValue} string Should Not Be Empty ${string} Set To Dictionary ${dict} string=${string} - [Return] ${dict} \ No newline at end of file + [Return] ${dict} +SortPolicyList + [Documentation] + ... 多策略排序 + ... policyList为数组结构 + [Arguments] ${policyList} + Log Call SortPolicyList + ${policyListJson} Set Variable [ + FOR ${policyObj} IN @{policyList} + ${json} SortPolicyObject ${policyObj} + ${policyListJson} Set Variable ${policyListJson}${json}, + END + ${policyListJson}= Replace String Using Regexp ${policyListJson} ,$ ] + Log SortPolicyList-${policyListJson} + [Return] ${policyListJson} +SortPolicyObject + [Documentation] + ... 策略排序 + ... policyObject为字典结构 + ... policyObject policyId=${policyId} policyType=${policyType} beforePolicyId=${beforePolicyId} afterPolicyId=${afterPolicyId} + [Arguments] ${policyObject} + Dictionary Should Contain Key ${policyObject} policyId + Dictionary Should Contain Key ${policyObject} policyType + ${policyId} Get From Dictionary ${policyObject} policyId + Run Keyword If "${policyId}"=="${EMPTY}" Should Not Be Empty ${policyId} + ${policyType} Get From Dictionary ${policyObject} policyType + Should Not Be Empty ${policyType} + ${return} ${beforePolicyId} Run Keyword And Ignore Error Get From Dictionary ${policyObject} beforePolicyId + ${return1} ${afterPolicyId} Run Keyword And Ignore Error Get From Dictionary ${policyObject} afterPolicyId + Run Keyword If "${return}"=="FAIL" and "${return1}"=="FAIL" Fail beforePolicyId和 afterPolicyId必须设置一个! + Run Keyword If "${return}"=="PASS" and "${return1}"=="PASS" and "${beforePolicyId}"=="${EMPTY}" and "${afterPolicyId}"=="${EMPTY}" + ... Fail beforePolicyId和 afterPolicyId不能同时为空! + ${json} json.Dumps ${policyObject} ensure_ascii=False + [Return] ${json} \ No newline at end of file