2020-04-07 14:11:59 +08:00
*** Settings ***
Library json
Library Collections
Resource ../../03-Variable/BifangApiVariable.txt
2020-04-15 18:23:16 +08:00
Resource ../../03-Variable/PolicyObjectDefault.txt
2020-04-09 17:43:22 +08:00
Resource ../../02-Keyword/tsg_bfapi/PolicyObject.robot
2020-04-07 14:11:59 +08:00
*** 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}、${...}
2020-04-08 19:16:24 +08:00
PolicyParamsOpertion
2020-04-07 14:11:59 +08:00
[Documentation]
... 描述: 入口, opAction参数固定为'add'
... 参数: returnData: 必传,是否返回请求数据。可选${0}(不返回)/${1}(返回)。
... policyList: 必传,字典类型。字典内可选参数信息:
2020-04-15 18:23:16 +08:00
... 其它参数默认值见../../03-Variable/PolicyObjectDefault.txt
2020-04-07 14:11:59 +08:00
[Arguments] ${returnData} ${policyList}
${emptyList} Create List
# 断言必传参数
2020-04-15 18:23:16 +08:00
# Should Not Be Empty ${policyList}[policyType]
# Should Not Be Empty ${policyList}[action]
2020-04-07 14:11:59 +08:00
# 取可选参数,为传入设置默认值
${return} ${policyName} Run Keyword And Ignore Error Set Variable ${policyList}[policyName]
2020-04-15 18:23:16 +08:00
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}
2020-04-07 14:11:59 +08:00
${return} ${policyDesc} Run Keyword And Ignore Error Set Variable ${policyList}[policyDesc]
2020-04-15 18:23:16 +08:00
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}
2020-04-07 14:11:59 +08:00
${return} ${userTags} Run Keyword And Ignore Error Set Variable ${policyList}[userTags]
2020-04-15 18:23:16 +08:00
Run Keyword If "${return}"=="FAIL" or "${userTags}"=="${EMPTY}" Set To Dictionary ${policyList} userTags=${Default_UserTags}
2020-04-07 14:11:59 +08:00
${return} ${doLog} Run Keyword And Ignore Error Set Variable ${policyList}[doLog]
2020-04-15 18:23:16 +08:00
Run Keyword If "${return}"=="FAIL" or "${doLog}"=="${EMPTY}" Set To Dictionary ${policyList} doLog=${Default_DoLog}
2020-04-07 14:11:59 +08:00
${return} ${isValid} Run Keyword And Ignore Error Set Variable ${policyList}[isValid]
2020-04-15 18:23:16 +08:00
Run Keyword If "${return}"=="FAIL" or "${isValid}"=="${EMPTY}" Set To Dictionary ${policyList} isValid=${Default_IsValid}
2020-04-07 14:11:59 +08:00
${return} ${scheduleId} Run Keyword And Ignore Error Set Variable ${policyList}[scheduleId]
2020-04-15 18:23:16 +08:00
${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
2020-04-07 14:11:59 +08:00
${return} ${appObjectIdArray} Run Keyword And Ignore Error Set Variable ${policyList}[appObjectIdArray]
2020-04-15 18:23:16 +08:00
${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}
2020-04-07 14:11:59 +08:00
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
2020-04-15 18:23:16 +08:00
Log Policy_Request_Body-${json}
2020-04-07 14:11:59 +08:00
[Return] ${json}
ManageEffectiveRange
# 处理EffectiveRange
[Arguments] ${policyList}
${emptyList} Create List
${emptyListDouble} Create List ${emptyList}
${return} ${effectiveRange} Run Keyword And Ignore Error Set Variable ${policyList}[effectiveRange]
2020-04-15 18:23:16 +08:00
${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}
2020-04-07 14:11:59 +08:00
... 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]
2020-04-15 18:23:16 +08:00
${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
2020-04-07 14:11:59 +08:00
... 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}
2020-04-21 13:30:41 +08:00
${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}
2020-04-16 14:27:54 +08:00
# Run Keyword If "${clientHostObj}"!="${None}" Append To List ${emptyList} ${clientHostObj}
2020-04-07 14:11:59 +08:00
${defaultObj} Create Dictionary
${return} ${referenceObject} Run Keyword And Ignore Error Set Variable ${policyList}[referenceObject]
2020-04-15 18:23:16 +08:00
${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}
2020-04-07 14:11:59 +08:00
... ELSE AnalysisReferenceObject ${referenceObject}
# 若参数为空,设置默认结构
FOR ${var} IN @{value}
Run Keyword If ${var}!={} Append To List ${emptyList} ${var}
END
Set To Dictionary ${policyList} referenceObject=${emptyList}
2020-04-21 13:30:41 +08:00
ManageClientIPObject
2020-04-16 14:27:54 +08:00
[Arguments] ${emptyList}
2020-04-07 14:11:59 +08:00
# 增加引用测试终端IP策略对象
2020-04-16 14:27:54 +08:00
${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}
2020-04-21 13:30:41 +08:00
ManageClientSubIDObject
[Arguments] ${emptyList}
# 增加引用测试终端IP策略对象
${list1} Create List
${obj1} Create Dictionary objectId=${testClentSubID} protocolFields=${list1}
Append To List ${emptyList} ${obj1}
2020-04-07 14:11:59 +08:00
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}