From 568029c8ef9a5b4ee7104e522c4258b97a00d659 Mon Sep 17 00:00:00 2001 From: wangxin Date: Tue, 30 Jun 2020 18:26:22 +0800 Subject: [PATCH] =?UTF-8?q?feat:(=E7=AD=96=E7=95=A5)1.=E7=AD=96=E7=95=A5?= =?UTF-8?q?=E6=8E=92=E5=BA=8F;2.=E7=AD=96=E7=95=A5=E7=BB=9F=E8=AE=A1;3.?= =?UTF-8?q?=E7=AD=96=E7=95=A5=E7=94=9F=E6=95=88=E5=AD=97=E6=AE=B5=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=20=E6=B3=A8=E6=84=8F=E7=AD=96=E7=95=A5=E6=8E=92?= =?UTF-8?q?=E5=BA=8F=E8=B0=83=E7=94=A8=E6=8E=A5=E5=8F=A3=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=EF=BC=8C=E7=AD=96=E7=95=A5=E7=94=9F=E6=95=88?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E6=9F=A5=E8=AF=A2=E8=BF=94=E5=9B=9E=E6=80=BB?= =?UTF-8?q?=E6=98=AF=E7=A9=BA=E6=95=B0=E6=8D=AE=204.Default=5Fv2=E5=BC=80?= =?UTF-8?q?=E5=A4=B4=E7=9A=84=E5=8F=82=E6=95=B0=E9=85=8D=E7=BD=AE=E6=9B=BF?= =?UTF-8?q?=E6=8D=A2=E4=B8=BAEMPTY?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../policy_object/PolicyObjectTests.robot | 17 ++++++- .../tsg_bfapi/policy_object/Object.robot | 18 +++++++- .../tsg_bfapi/policy_object/Policy.robot | 30 +++++++++++- .../policy_object/ProcessPolicyBody.robot | 46 ++++++++++++++++--- 4 files changed, 101 insertions(+), 10 deletions(-) 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