253 lines
13 KiB
Plaintext
253 lines
13 KiB
Plaintext
*** Settings ***
|
||
Library json
|
||
Library Collections
|
||
Resource ../../03-Variable/BifangApiVariable.txt
|
||
Resource ../../03-Variable/PolicyObjectDefault.txt
|
||
Resource ../../02-Keyword/tsg_bfapi/PolicyObject.robot
|
||
|
||
*** Keywords ***
|
||
# ... 特殊参数说明:
|
||
# ... effectiveRange=Nursurtan|Transtelecom&Astel,Almaty&Nursurtan,|Astel&Transtelecom
|
||
# ... 为字符串类型,每条生效区域信息以','分隔
|
||
# ... ①以'|'字符开头表示仅为isp信息,如:effectiveRange=|Astel&Transtelecom
|
||
# ... ②非'|'字符开头表示仅为location信息或location和isp信息,如:
|
||
# ... effectiveRange=Nursurtan(仅为location信息)
|
||
# ... effectiveRange=Nursurtan|Transtelecom&Astel(location和isp信息)
|
||
# ... userRegion=protocol:HTTP,keyring:${1}
|
||
# ... 为字符串类型,每条动作参数以','分隔
|
||
# ... [key]:[value],...
|
||
# ... referenceObject=${265}|TSG_FIELD_HTTP_HOST,${266}|TSG_FIELD_SSL_SNI&TSG_FIELD_SSL_SAN
|
||
# ... 为字符串类型,每条引用的策略对象信息以','分隔
|
||
# ... [objectId]|[protocolFileds],... ,多个protocolFileds用'&'连接
|
||
# ... scheduleId=${3},${1}
|
||
# ... 为字符串类型,以','分隔
|
||
# ... appObjectIdArray==${2},${3}
|
||
# ... 为字符串类型,以','分隔
|
||
# ...
|
||
# ... 注:数字类型变量为${0}、${1}、${...}
|
||
|
||
PolicyParamsOpertion
|
||
[Documentation]
|
||
... 描述:入口,opAction参数固定为'add'
|
||
... 参数:returnData: 必传,是否返回请求数据。可选${0}(不返回)/${1}(返回)。
|
||
... policyList: 必传,字典类型。字典内可选参数信息:
|
||
... 其它参数默认值见../../03-Variable/PolicyObjectDefault.txt
|
||
|
||
[Arguments] ${returnData} ${policyList}
|
||
${emptyList} Create List
|
||
# 断言必传参数
|
||
# Should Not Be Empty ${policyList}[policyType]
|
||
# Should Not Be Empty ${policyList}[action]
|
||
# 取可选参数,为传入设置默认值
|
||
${return} ${policyName} Run Keyword And Ignore Error Set Variable ${policyList}[policyName]
|
||
Run Keyword If "${return}"=="FAIL" or "${policyName}"=="${EMPTY}" Set To Dictionary ${policyList} policyName=${Default_PolicyName}
|
||
${return} ${policyType} Run Keyword And Ignore Error Set Variable ${policyList}[policyType]
|
||
Run Keyword If "${return}"=="FAIL" or "${policyType}"=="${EMPTY}" Set To Dictionary ${policyList} policyType=${Default_PolicyType}
|
||
${return} ${policyDesc} Run Keyword And Ignore Error Set Variable ${policyList}[policyDesc]
|
||
Run Keyword If "${return}"=="FAIL" or "${policyDesc}"=="${EMPTY}" Set To Dictionary ${policyList} policyDesc=${Default_PolicyDesc}
|
||
${return} ${action} Run Keyword And Ignore Error Set Variable ${policyList}[action]
|
||
Run Keyword If "${return}"=="FAIL" or "${action}"=="${EMPTY}" Set To Dictionary ${policyList} action=${Default_Action}
|
||
${return} ${userTags} Run Keyword And Ignore Error Set Variable ${policyList}[userTags]
|
||
Run Keyword If "${return}"=="FAIL" or "${userTags}"=="${EMPTY}" Set To Dictionary ${policyList} userTags=${Default_UserTags}
|
||
${return} ${doLog} Run Keyword And Ignore Error Set Variable ${policyList}[doLog]
|
||
Run Keyword If "${return}"=="FAIL" or "${doLog}"=="${EMPTY}" Set To Dictionary ${policyList} doLog=${Default_DoLog}
|
||
${return} ${isValid} Run Keyword And Ignore Error Set Variable ${policyList}[isValid]
|
||
Run Keyword If "${return}"=="FAIL" or "${isValid}"=="${EMPTY}" Set To Dictionary ${policyList} isValid=${Default_IsValid}
|
||
${return} ${scheduleId} Run Keyword And Ignore Error Set Variable ${policyList}[scheduleId]
|
||
${scheduleIdV} Run Keyword If "${return}"=="FAIL" or "${scheduleId}"=="${EMPTY}" Evaluate list(map(int, re.split('[,]', '${Default_ScheduleId}'))) re
|
||
... ELSE Evaluate list(map(int, re.split('[,]', '${scheduleId}'))) re
|
||
${return} ${appObjectIdArray} Run Keyword And Ignore Error Set Variable ${policyList}[appObjectIdArray]
|
||
${appObjectIdArrayV} Run Keyword If "${return}"=="FAIL" or "${appObjectIdArray}"=="${EMPTY}" Evaluate list(map(int, re.split('[,]', '${Default_AppObjectIdArray}'))) re
|
||
... ELSE Evaluate list(map(int, re.split('[,]', '${appObjectIdArray}'))) re
|
||
Set To Dictionary ${policyList} scheduleId=${scheduleIdV}
|
||
Set To Dictionary ${policyList} appObjectIdArray=${appObjectIdArrayV}
|
||
# 固定值
|
||
Set To Dictionary ${policyList} policyId= doBlacklist=${0}
|
||
# 分别处理EffectiveRange、UserRegion和ReferenceObject参数
|
||
ManageEffectiveRange ${policyList}
|
||
ManageUserRegion ${policyList}
|
||
ManageReferenceObject ${policyList}
|
||
# 转为json结构并返回
|
||
${dict} Create Dictionary opAction=add returnData=${returnData} policyList=${policyList}
|
||
${json} json.Dumps ${dict} ensure_ascii=False
|
||
Log Policy_Request_Body-${json}
|
||
[Return] ${json}
|
||
|
||
ManageEffectiveRange
|
||
# 处理EffectiveRange
|
||
[Arguments] ${policyList}
|
||
${emptyList} Create List
|
||
${emptyListDouble} Create List ${emptyList}
|
||
|
||
${return} ${effectiveRange} Run Keyword And Ignore Error Set Variable ${policyList}[effectiveRange]
|
||
${effectiveRange} Run Keyword If "${return}"=="FAIL" or "${effectiveRange}"=="${EMPTY}" Set Variable ${Default_EffectiveRange}
|
||
... ELSE Set Variable ${effectiveRange}
|
||
|
||
${value} Run Keyword If "${effectiveRange}"=="${EMPTY}" Create Dictionary tag_sets=${emptyListDouble}
|
||
... ELSE AnalysisEffectiveRange ${effectiveRange}
|
||
Set To Dictionary ${policyList} effectiveRange=${value}
|
||
|
||
AnalysisEffectiveRange
|
||
# 解析EffectiveRange,区分值类型
|
||
[Arguments] ${effectiveRange}
|
||
${value} Create List
|
||
${list} Evaluate re.split('[,]', '${effectiveRange}') re
|
||
FOR ${var} IN @{list}
|
||
${param} Run Keyword If '${var}'.startswith('|') EffectiveRangeValueType1 ${var}
|
||
... ELSE IF '|' in '${var}' EffectiveRangeValueType2 ${var}
|
||
... ELSE EffectiveRangeValueType3 ${var}
|
||
Append To List ${value} ${param}
|
||
END
|
||
${obj} Create Dictionary tag_sets=${value}
|
||
[Return] ${obj}
|
||
|
||
EffectiveRangeValueType1
|
||
# EffectiveRange值类型1,仅为isp信息
|
||
[Arguments] ${str}
|
||
# #Astel
|
||
${value} Evaluate '${str}'[1:]
|
||
|
||
${valueList} Create List
|
||
${list} Evaluate re.split('[&]', '${value}') re
|
||
FOR ${var} IN @{list}
|
||
Append To List ${valueList} ${var}
|
||
END
|
||
${obj} Create Dictionary tag=isp value=${valueList}
|
||
${return} Create List ${obj}
|
||
[Return] ${return}
|
||
|
||
EffectiveRangeValueType2
|
||
# EffectiveRange值类型2,location|isp都包含
|
||
[Arguments] ${str}
|
||
# Nursurtan#Transtelecom
|
||
${list} Evaluate re.split('[|]', '${str}') re
|
||
# Location
|
||
${valueList1} Create List
|
||
${list1} Evaluate re.split('[&]', '${list}[0]') re
|
||
FOR ${var} IN @{list1}
|
||
Append To List ${valueList1} ${var}
|
||
END
|
||
${obj1} Create Dictionary tag=location value=${valueList1}
|
||
# ISP
|
||
${valueList2} Create List
|
||
${list2} Evaluate re.split('[&]', '${list}[1]') re
|
||
FOR ${var} IN @{list2}
|
||
Append To List ${valueList2} ${var}
|
||
END
|
||
${obj2} Create Dictionary tag=isp value=${valueList2}
|
||
|
||
${return} Create List ${obj1} ${obj2}
|
||
[Return] ${return}
|
||
|
||
EffectiveRangeValueType3
|
||
# EffectiveRange值类型3,仅为location信息
|
||
[Arguments] ${str}
|
||
# Almaty
|
||
${valueList} Create List
|
||
${list} Evaluate re.split('[&]', '${str}') re
|
||
FOR ${var} IN @{list}
|
||
Append To List ${valueList} ${var}
|
||
END
|
||
${obj} Create Dictionary tag=location value=${valueList}
|
||
${return} Create List ${obj}
|
||
[Return] ${return}
|
||
|
||
ManageUserRegion
|
||
[Arguments] ${policyList}
|
||
${emptyObj} Create Dictionary
|
||
|
||
${return} ${userRegion} Run Keyword And Ignore Error Set Variable ${policyList}[userRegion]
|
||
${userRegion} Run Keyword If "${return}"=="FAIL" or "${userRegion}"=="${EMPTY}" Set Variable ${Default_UserRegion}
|
||
... ELSE Set Variable ${userRegion}
|
||
|
||
${value} Run Keyword If "${userRegion}"=="${EMPTY}" Create Dictionary
|
||
... ELSE AnalysisUserRegion ${userRegion}
|
||
Set To Dictionary ${policyList} userRegion=${value}
|
||
|
||
Log ${policyList}[userRegion]
|
||
|
||
AnalysisUserRegion
|
||
[Arguments] ${userRegion}
|
||
# protocol:HTTP,keyring:1
|
||
${obj} Create Dictionary
|
||
${list} Evaluate re.split('[,]', '${userRegion}') re
|
||
FOR ${var} IN @{list}
|
||
${k} Evaluate '${var}'[0:'${var}'.find(':')]
|
||
${v} Evaluate '${var}'['${var}'.find(':')+1:]
|
||
${v} Run Keyword If '${v}'.isdigit() Evaluate int('${v}')
|
||
... ELSE Set Variable ${v}
|
||
Set To Dictionary ${obj} ${k}=${v}
|
||
END
|
||
[Return] ${obj}
|
||
|
||
ManageReferenceObject
|
||
# 处理引用对象字符串
|
||
[Arguments] ${policyList}
|
||
${emptyList} Create List
|
||
#默认客户端条件类型:clientip or clientsubid
|
||
${return} ${defaultClient} Run Keyword And Ignore Error Set Variable ${policyList}[defalutClient]
|
||
${defaultClient} Run Keyword If "${return}"=="FAIL" or "${defaultClient}"=="${EMPTY}" Set Variable ${Default_Client_Type}
|
||
... ELSE Set Variable ${defaultClient}
|
||
Run Keyword If '${addTestClentIPFlag}'=='1' and '${defaultClient}'=='clientip' ManageClientIPObject ${emptyList}
|
||
Run Keyword If '${addTestClentIPFlag}'=='1' and '${defaultClient}'=='clientsubid' ManageClientSubIDObject ${emptyList}
|
||
#Run Keyword If '${addTestClentIPFlag}'=='1' ManageClientObject ${emptyList}
|
||
# Run Keyword If "${clientHostObj}"!="${None}" Append To List ${emptyList} ${clientHostObj}
|
||
|
||
${defaultObj} Create Dictionary
|
||
${return} ${referenceObject} Run Keyword And Ignore Error Set Variable ${policyList}[referenceObject]
|
||
${referenceObject} Run Keyword If "${return}"=="FAIL" or "${referenceObject}"=="${EMPTY}" Set Variable ${Default_ReferenceObject}
|
||
... ELSE Set Variable ${referenceObject}
|
||
${value} Run Keyword If "${referenceObject}"=="${EMPTY}" Create List ${defaultObj}
|
||
... ELSE AnalysisReferenceObject ${referenceObject}
|
||
# 若参数为空,设置默认结构
|
||
FOR ${var} IN @{value}
|
||
Run Keyword If ${var}!={} Append To List ${emptyList} ${var}
|
||
END
|
||
Set To Dictionary ${policyList} referenceObject=${emptyList}
|
||
|
||
ManageClientIPObject
|
||
[Arguments] ${emptyList}
|
||
# 增加引用测试终端IP策略对象
|
||
${list1} Create List TSG_SECURITY_SOURCE_ADDR
|
||
${obj1} Create Dictionary objectId=${testClentID} protocolFields=${list1}
|
||
Append To List ${emptyList} ${obj1}
|
||
# ${list2} Create List null
|
||
# ${obj2} Create Dictionary objectId=${testClentSubID} protocolFields=${list2}
|
||
# Append To List ${emptyList} ${obj2}
|
||
ManageClientSubIDObject
|
||
[Arguments] ${emptyList}
|
||
# 增加引用测试终端IP策略对象
|
||
${list1} Create List
|
||
${obj1} Create Dictionary objectId=${testClentSubID} protocolFields=${list1}
|
||
Append To List ${emptyList} ${obj1}
|
||
|
||
AnalysisReferenceObject
|
||
# 解析引用对象
|
||
[Arguments] ${referenceObject}
|
||
${objList} Create List
|
||
${list} Evaluate re.split('[,]', '${referenceObject}') re
|
||
FOR ${var} IN @{list}
|
||
${emptyList} Create List
|
||
${emptyObj} Create Dictionary
|
||
${key} Evaluate '${var}'[0:'${var}'.find('|')]
|
||
${values} Evaluate '${var}'['${var}'.find('|')+1:]
|
||
${valueList} InnerForEach ${values}
|
||
${key} Run Keyword If '${key}'.isdigit() Evaluate int('${key}')
|
||
... ELSE Set Variable ${key}
|
||
Set To Dictionary ${emptyObj} objectId=${key}
|
||
Set To Dictionary ${emptyObj} protocolFields=${valueList}
|
||
Append To List ${objList} ${emptyObj}
|
||
END
|
||
[Return] ${objList}
|
||
|
||
InnerForEach
|
||
# 循环嵌套
|
||
[Arguments] ${values}
|
||
${emptyList} Create List
|
||
${list} Evaluate re.split('[&]', '${values}') re
|
||
FOR ${var} IN @{list}
|
||
Append To List ${emptyList} ${var}
|
||
END
|
||
[Return] ${list}
|
||
|