378 lines
21 KiB
Plaintext
378 lines
21 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 ***
|
||
ObjectParamsOpertion
|
||
[Documentation]
|
||
... 描述:入口,opAction参数固定为'add'
|
||
... 其它参数默认值见../../03-Variable/PolicyObjectDefault.txt
|
||
|
||
[Arguments] ${returnData} ${objectList} ${opAction}
|
||
${emptyList} Create List
|
||
${returnDict} Create Dictionary
|
||
# 断言必传参数
|
||
# Should Not Be Empty ${objectList}[objectType]
|
||
# Set To Dictionary ${returnDict} objectType=${objectList}[objectType]
|
||
Should Not Be Empty ${objectList}[addItemList]
|
||
# 取可选参数,为传入设置默认值
|
||
${return} ${objectType} Run Keyword And Ignore Error Set Variable ${objectList}[objectType]
|
||
${objectTypeV} Run Keyword If "${return}"!="FAIL" and "${objectType}"!="${EMPTY}" Evaluate '${objectType}'.lower()
|
||
... ELSE Evaluate '${Default_ObjectType}'.lower()
|
||
Set To Dictionary ${objectList} objectType=${objectTypeV}
|
||
Set To Dictionary ${returnDict} objectType=${objectTypeV}
|
||
${return} ${objectSubType} Run Keyword And Ignore Error Set Variable ${objectList}[objectSubType]
|
||
Run Keyword If "${return}"!="FAIL" and "${objectSubType}"!="${EMPTY}" Set To Dictionary ${returnDict} objectSubType=${objectSubType}
|
||
... ELSE Set To Dictionary ${returnDict} objectSubType=${Default_ObjectSubType}
|
||
${return} ${isValid} Run Keyword And Ignore Error Set Variable ${objectList}[isValid]
|
||
Run Keyword If "${return}"=="FAIL" or "${isValid}"=="${EMPTY}" Set To Dictionary ${returnDict} isValid=${Default_IsValid}
|
||
... ELSE Set To Dictionary ${returnDict} isValid=${isValid}
|
||
${return} ${isInitialize} Run Keyword And Ignore Error Set Variable ${objectList}[isInitialize]
|
||
Run Keyword If "${return}"=="FAIL" or "${isInitialize}"=="${EMPTY}" Set To Dictionary ${returnDict} isInitialize=${Default_IsInitialize}
|
||
... ELSE Set To Dictionary ${returnDict} isInitialize=${isInitialize}
|
||
${return} ${isExclusion} Run Keyword And Ignore Error Set Variable ${objectList}[isExclusion]
|
||
Run Keyword If "${return}"=="FAIL" or "${isExclusion}"=="${EMPTY}" Set To Dictionary ${returnDict} isExclusion=${Default_IsExclusion}
|
||
... ELSE Set To Dictionary ${returnDict} isExclusion=${isExclusion}
|
||
${return} ${objectName} Run Keyword And Ignore Error Set Variable ${objectList}[objectName]
|
||
Run Keyword If "${return}"=="FAIL" or "${objectName}"=="${EMPTY}" Set To Dictionary ${returnDict} objectName=${Default_ObjectName}
|
||
... ELSE Set To Dictionary ${returnDict} objectName=${objectName}
|
||
${return} ${objectDesc} Run Keyword And Ignore Error Set Variable ${objectList}[objectDesc]
|
||
Run Keyword If "${return}"!="FAIL" and "${objectDesc}"!="${EMPTY}" Set To Dictionary ${returnDict} objectDesc=${objectDesc}
|
||
... ELSE Set To Dictionary ${returnDict} objectDesc=${Default_ObjectDesc}
|
||
${return} ${subObjectIds} Run Keyword And Ignore Error Set Variable ${objectList}[subObjectIds]
|
||
${subObjectIdsV} Run Keyword If "${return}"!="FAIL" and "${subObjectIds}"!="${EMPTY}" and "${subObjectIds}"!="${None}" Evaluate list(map(int, re.split('[,]', '${subObjectIds}'))) re
|
||
... ELSE Set Variable ${emptyList}
|
||
${return} ${objectId} Run Keyword And Ignore Error Set Variable ${objectList}[objectId]
|
||
Run Keyword If "${return}"=="FAIL" or "${objectId}"=="${EMPTY}" Set To Dictionary ${returnDict} objectId=${EMPTY}
|
||
... ELSE Set To Dictionary ${returnDict} objectId=${objectId}
|
||
Set To Dictionary ${returnDict} subObjectIds=${subObjectIdsV}
|
||
|
||
# 处理AddItemList
|
||
ManageAddItemList ${objectList} ${returnDict}
|
||
|
||
# 转为json结构并返回
|
||
${dict} Create Dictionary opAction=${opAction} returnData=${returnData} objectList=${returnDict}
|
||
${json} json.Dumps ${dict} ensure_ascii=False
|
||
Log Object_Request_Body-${json}
|
||
[Return] ${json}
|
||
|
||
ManageAddItemList
|
||
# 处理addItemList数组
|
||
[Arguments] ${objectList} ${returnDict}
|
||
${itemList} Run Keyword If '${objectList}[objectType]'=='ip' ManageIpItemList ${objectList}[addItemList]
|
||
... ELSE IF '${objectList}[objectType]'=='http_signature' ManageStrItemList ${objectList}[addItemList] ${True}
|
||
... ELSE ManageStrItemList ${objectList}[addItemList] ${False}
|
||
Set To Dictionary ${returnDict} addItemList=${itemList}
|
||
|
||
ManageIpItemList
|
||
# 处理IP对象
|
||
[Arguments] ${str}
|
||
${returnList} Create List
|
||
# ${list} Evaluate re.split('[,]', '${str}') re
|
||
log ${str}
|
||
FOR ${var} IN @{str}
|
||
# Continue For Loop If '${var}' == '${EMPTY}'
|
||
# 区分入参的类型,分别处理
|
||
Append To List ${returnList} ${var}
|
||
END
|
||
[Return] ${returnList}
|
||
|
||
ManageStrItemList
|
||
# 处理除IP外其它字符串对象
|
||
[Arguments] ${str} ${flag}
|
||
${returnList} Create List
|
||
${list} Evaluate re.split('[,]', '${str}') re
|
||
FOR ${var} IN @{list}
|
||
Continue For Loop If '${var}' == '${EMPTY}'
|
||
${obj} AnalysisStrItem ${var} ${flag}
|
||
Append To List ${returnList} ${obj}
|
||
END
|
||
[Return] ${returnList}
|
||
IpItemType11
|
||
[Arguments] ${str}
|
||
${obj} Create Dictionary
|
||
${values} Evaluate re.split('[|]', '${str}') re
|
||
${isSession} Convert To Integer ${values}[0]
|
||
${ip} Convert To Integer ${values}[1]
|
||
${port} Convert To Integer ${values}[2]
|
||
${direction} Convert To Integer ${values}[3]
|
||
${protocol} Convert To Integer ${values}[4]
|
||
${return} ${isInitialize} Run Keyword And Ignore Error Convert To Integer ${list}[${index+1}]
|
||
Run Keyword If "${return}"!="FAIL" and "${isInitialize}"!="${EMPTY}" Set To Dictionary ${obj} isInitialize=${isInitialize}
|
||
IpItemType1
|
||
# IP类型1:4|0|0|endpoint#range|192.168.40.1|192.168.40.50|80/88&range|192.168.40.1|192.168.40.50|80/88|1|itemName|itemDesc,...
|
||
[Arguments] ${str}
|
||
${obj} Create Dictionary
|
||
${left} Evaluate '${str}'[0:'${str}'.find('#')]
|
||
${right} Evaluate '${str}'['${str}'.find('#')+1:]
|
||
${values} Evaluate re.split('[|]', '${left}') re
|
||
${addrType} Convert To Integer ${values}[0]
|
||
${protocol} Convert To Integer ${values}[1]
|
||
${direction} Convert To Integer ${values}[2]
|
||
Set To Dictionary ${obj} addrType=${addrType} protocol=${protocol} direction=${direction} isSession=${values}[3]
|
||
|
||
${cfgs} Evaluate re.split('[&]', '${right}') re
|
||
${client} Set Variable ${cfgs}[0]
|
||
${server} Set Variable ${cfgs}[1]
|
||
|
||
${cValues} Evaluate re.split('[|]', '${client}') re
|
||
${sValues} Evaluate re.split('[|]', '${server}') re
|
||
${clientPort1} Evaluate int(re.split('[/]', '${cValues}[3]')[0]) re
|
||
${clientPort2} Evaluate int(re.split('[/]', '${cValues}[3]')[1]) re
|
||
${serverPort1} Evaluate int(re.split('[/]', '${sValues}[3]')[0]) re
|
||
${serverPort2} Evaluate int(re.split('[/]', '${sValues}[3]')[1]) re
|
||
Set To Dictionary ${obj} clientIpFormat=${cValues}[0] clientIp1=${cValues}[1] clientIp2=${cValues}[2] clientPortFormat=range clientPort1=${clientPort1} clientPort2=${clientPort2}
|
||
Set To Dictionary ${obj} serverIpFormat=${sValues}[0] serverIp1=${sValues}[1] serverIp2=${sValues}[2] serverPortFormat=range serverPort1=${serverPort1} serverPort2=${serverPort2}
|
||
|
||
OtherParams ${sValues} ${obj}
|
||
[Return] ${obj}
|
||
|
||
IpItemType2
|
||
# IP类型2:4|0|0|endpoint#range|192.168.40.1|192.168.40.50|80/88|1|itemName|itemDesc,...
|
||
[Arguments] ${str}
|
||
${obj} Create Dictionary
|
||
${left} Evaluate '${str}'[0:'${str}'.find('#')]
|
||
${client} Evaluate '${str}'['${str}'.find('#')+1:]
|
||
${values} Evaluate re.split('[|]', '${left}') re
|
||
${addrType} Convert To Integer ${values}[0]
|
||
${protocol} Convert To Integer ${values}[1]
|
||
${direction} Convert To Integer ${values}[2]
|
||
Set To Dictionary ${obj} addrType=${addrType} protocol=${protocol} direction=${direction} isSession=${values}[3]
|
||
|
||
${cValues} Evaluate re.split('[|]', '${client}') re
|
||
${clientPort1} Evaluate int(re.split('[/]', '${cValues}[3]')[0]) re
|
||
${clientPort2} Evaluate int(re.split('[/]', '${cValues}[3]')[1]) re
|
||
Set To Dictionary ${obj} clientIpFormat=${cValues}[0] clientIp1=${cValues}[1] clientIp2=${cValues}[2] clientPortFormat=range clientPort1=${clientPort1} clientPort2=${clientPort2}
|
||
# 设置默认值
|
||
Set To Dictionary ${obj} serverIpFormat=range serverIp1= serverIp2= serverPortFormat=range serverPort1=${0} serverPort2=${0}
|
||
OtherParams ${cValues} ${obj}
|
||
[Return] ${obj}
|
||
|
||
IpItemType3
|
||
# IP类型3:range|192.168.40.1|192.168.40.50|80/88&range|192.168.40.1|192.168.40.50|80/88|1|itemName|itemDesc,...
|
||
[Arguments] ${str}
|
||
${obj} Create Dictionary
|
||
# 设置默认值
|
||
Run Keyword If ':' in '${str}' Set To Dictionary ${obj} addrType=${6}
|
||
... ELSE Set To Dictionary ${obj} addrType=${Default_AddItem_AddrType}
|
||
Set To Dictionary ${obj} protocol=${Default_AddItem_Protocol} direction=${Default_AddItem_Direction} isSession=${Default_AddItem_IsSession}
|
||
|
||
${cfgs} Evaluate re.split('[&]', '${str}') re
|
||
${client} Set Variable ${cfgs}[0]
|
||
${server} Set Variable ${cfgs}[1]
|
||
|
||
${cValues} Evaluate re.split('[|]', '${client}') re
|
||
${sValues} Evaluate re.split('[|]', '${server}') re
|
||
${clientPort1} Evaluate int(re.split('[/]', '${cValues}[3]')[0]) re
|
||
${clientPort2} Evaluate int(re.split('[/]', '${cValues}[3]')[1]) re
|
||
${serverPort1} Evaluate int(re.split('[/]', '${sValues}[3]')[0]) re
|
||
${serverPort2} Evaluate int(re.split('[/]', '${sValues}[3]')[1]) re
|
||
Set To Dictionary ${obj} clientIpFormat=${cValues}[0] clientIp1=${cValues}[1] clientIp2=${cValues}[2] clientPortFormat=range clientPort1=${clientPort1} clientPort2=${clientPort2}
|
||
Set To Dictionary ${obj} serverIpFormat=${sValues}[0] serverIp1=${sValues}[1] serverIp2=${sValues}[2] serverPortFormat=range serverPort1=${serverPort1} serverPort2=${serverPort2}
|
||
|
||
OtherParams ${sValues} ${obj}
|
||
[Return] ${obj}
|
||
|
||
IpItemType4
|
||
# IP类型4:range|192.168.40.1|192.168.40.50|80/88|1|itemName|itemDesc,...
|
||
[Arguments] ${str}
|
||
${obj} Create Dictionary
|
||
# 设置默认值
|
||
Run Keyword If ':' in '${str}' Set To Dictionary ${obj} addrType=${6}
|
||
... ELSE Set To Dictionary ${obj} addrType=${4}
|
||
Set To Dictionary ${obj} protocol=${0} direction=${0} isSession=endpoint
|
||
|
||
${cValues} Evaluate re.split('[|]', '${str}') re
|
||
${clientPort1} Evaluate int(re.split('[/]', '${cValues}[3]')[0]) re
|
||
${clientPort2} Evaluate int(re.split('[/]', '${cValues}[3]')[1]) re
|
||
Set To Dictionary ${obj} clientIpFormat=${cValues}[0] clientIp1=${cValues}[1] clientIp2=${cValues}[2] clientPortFormat=range clientPort1=${clientPort1} clientPort2=${clientPort2}
|
||
# 设置默认值
|
||
Set To Dictionary ${obj} serverIpFormat=range serverIp1= serverIp2= serverPortFormat=range serverPort1=${0} serverPort2=${0}
|
||
|
||
OtherParams ${cValues} ${obj}
|
||
[Return] ${obj}
|
||
|
||
AnalysisStrItem
|
||
[Arguments] ${str} ${flag}
|
||
${obj} Create Dictionary
|
||
${list} Evaluate re.split('[|]', '${str}') re
|
||
# keywordArray
|
||
${keywords} KeywordsForEach ${list}[0]
|
||
Set To Dictionary ${obj} keywordArray=${keywords}
|
||
# district
|
||
Run Keyword If '${flag}'=='${True}' Set To Dictionary ${obj} district=${list}[1]
|
||
${index} Run Keyword If '${flag}'=='${True}' Set Variable ${2}
|
||
... ELSE Set Variable ${1}
|
||
# isHexbin
|
||
${return} ${isHexBin} Run Keyword And Ignore Error Convert To Integer ${list}[${index}]
|
||
Run Keyword If "${return}"!="FAIL" and "${isHexBin}"!="${EMPTY}" Set To Dictionary ${obj} isHexbin=${isHexBin}
|
||
... ELSE Set To Dictionary ${obj} isHexbin=${0}
|
||
|
||
# isInitialize、itemName、itemDesc
|
||
${return} ${isInitialize} Run Keyword And Ignore Error Convert To Integer ${list}[${index+1}]
|
||
Run Keyword If "${return}"!="FAIL" and "${isInitialize}"!="${EMPTY}" Set To Dictionary ${obj} isInitialize=${isInitialize}
|
||
${return} ${itemName} Run Keyword And Ignore Error Set Variable ${list}[${index+2}]
|
||
Run Keyword If "${return}"!="FAIL" and "${itemName}"!="${EMPTY}" Set To Dictionary ${obj} itemName=${itemName}
|
||
${return} ${itemDesc} Run Keyword And Ignore Error Set Variable ${list}[${index+3}]
|
||
Run Keyword If "${return}"!="FAIL" and "${itemDesc}"!="${EMPTY}" Set To Dictionary ${obj} itemDesc=${itemDesc}
|
||
[Return] ${obj}
|
||
|
||
KeywordsForEach
|
||
# 处理多关键字keyword1&keyword2&...
|
||
[Arguments] ${str}
|
||
${returnList} Create List
|
||
${list} Evaluate re.split('[&]', '${str}') re
|
||
FOR ${var} IN @{list}
|
||
Append To List ${returnList} ${var}
|
||
END
|
||
[Return] ${returnList}
|
||
|
||
OtherParams
|
||
[Documentation]
|
||
... 处理isInitialize、itemName、itemDesc参数
|
||
[Arguments] ${values} ${obj}
|
||
${return} ${isInitialize} Run Keyword And Ignore Error Convert To Integer ${values}[4]
|
||
Run Keyword If "${return}"!="FAIL" and "${isInitialize}"!="${EMPTY}" Set To Dictionary ${obj} isInitialize=${isInitialize}
|
||
${return} ${itemName} Run Keyword And Ignore Error Set Variable ${values}[5]
|
||
Run Keyword If "${return}"!="FAIL" and "${itemName}"!="${EMPTY}" Set To Dictionary ${obj} itemName=${itemName}
|
||
${return} ${itemDesc} Run Keyword And Ignore Error Set Variable ${values}[6]
|
||
Run Keyword If "${return}"!="FAIL" and "${itemDesc}"!="${EMPTY}" Set To Dictionary ${obj} itemDesc=${itemDesc}
|
||
|
||
WanVpn
|
||
[Arguments] ${wanvpnlist}
|
||
${data} Set Variable "opAction":"add","returnData":1
|
||
${dict}= Evaluate eval ('{${data}}')
|
||
${data2} set to dictionary ${dict} list=${wanvpnlist}
|
||
${json} json.Dumps ${data2} ensure_ascii=False
|
||
[Return] ${json}
|
||
|
||
IP_list
|
||
[Arguments] ${Iplist}
|
||
${list} Create List
|
||
FOR ${k} ${v} IN ENUMERATE @{Iplist}
|
||
Append To List ${list} ${v}
|
||
END
|
||
${list2} Set Variable ${list}[2]
|
||
${list3} Set Variable ${list}[3]
|
||
${link_id} evaluate int(${Iplist}[${list2}])
|
||
${src_mac} evaluate int(${Iplist}[${list3}])
|
||
${list_info} Create Dictionary ${list}[2]=${link_id} ${list}[3]=${src_mac}
|
||
${Ip_list} Create Dictionary ip=${Iplist}[ip] relative_location=${Iplist}[relative_location] link_info=${list_info}
|
||
log 123213213213213123
|
||
log ${Ip_list}
|
||
# log ${link_info}
|
||
[Return] ${Ip_list}
|
||
WanNatIpPood
|
||
[Arguments] ${must_parameter} ${wan_nat_ip_iplist}
|
||
# 编写iplist json格式
|
||
${wan_nat_ip_iplist} Create Dictionary profileId=${must_parameter}[profileId] profileName=${must_parameter}[profileName] ipList=${wan_nat_ip_iplist} isValid=1
|
||
#编写二层list内地格式
|
||
${wan_nat_ip_list} Create List ${wan_nat_ip_iplist}
|
||
# 判断sjon是用于修改还是新增
|
||
${opAction} run keyword if '${must_parameter}[profileId]'=="" Set Variable add
|
||
... ELSE Set Variable update
|
||
#编写最外面的格式
|
||
${returnData} evaluate int(1)
|
||
${wan_nat_ip_pood_data} Create Dictionary opAction=${opAction} returnData=${returnData} list=${wan_nat_ip_list}
|
||
# 返回请求json
|
||
log ${wan_nat_ip_pood_data}
|
||
${json} json.Dumps ${wan_nat_ip_pood_data} ensure_ascii=False
|
||
log ${json}
|
||
[Return] ${json}
|
||
|
||
|
||
index
|
||
[Arguments] ${list} ${value}
|
||
${index} evaluate int(0)
|
||
${1} evaluate int(1)
|
||
FOR ${a} IN @{list}
|
||
#${a} Set Variable ${a}
|
||
log ${a}
|
||
${index} run Keyword if '${a}'=='${value}' log ${index}
|
||
... ELSE Evaluate ${index}+${1}
|
||
log ${a}
|
||
END
|
||
|
||
abcd
|
||
[Arguments] ${effectiveRange_list} ${DataCenter}
|
||
${ab} create list
|
||
FOR ${a} IN @{DataCenter}
|
||
${i} index ${effectiveRange_list} ${a}
|
||
Append To List ${ab} ${i}
|
||
END
|
||
[Return] ${ab}
|
||
|
||
isp_json
|
||
[Arguments] ${isp_json}
|
||
${1} Create List ${isp_json}
|
||
[Return] ${1}
|
||
|
||
location_json
|
||
[Arguments] ${location_json}
|
||
${2} Create List ${location_json}
|
||
[Return] ${2}
|
||
|
||
loccation_And_isp_json
|
||
[Arguments] ${location_json} ${isp_json}
|
||
${3} Create List ${location_json} ${isp_json}
|
||
[Return] ${3}
|
||
|
||
|
||
|
||
PacketCapture
|
||
[Arguments] ${PacketCapturedata} ${DataCenter}
|
||
# 构建effectiveRange_tsg_sets
|
||
${effectiveRange_list_manu} Create List Almaty
|
||
${DataCenter_length} = Get Length ${DataCenter}
|
||
# ${isp_length} = Get Length ${isp}
|
||
|
||
${DataCenter_ids} run keyword if ${DataCenter_length}==0 abcd ${effectiveRange_list_manu} ${DataCenter}
|
||
... ELSE abcd ${effectiveRange_list_manu} ${DataCenter}
|
||
log ${DataCenter_ids}
|
||
${DataCenter_json} Create Dictionary tag=data_center value=${DataCenter} ids=${DataCenter_ids}
|
||
|
||
# ${isp_ids} run keyword if ${isp_length}==0 abcd ${effectiveRange_list_manu} ${isp}
|
||
# ... ELSE abcd ${effectiveRange_list_manu} ${isp}
|
||
# log ${isp}
|
||
# ${isp_json} Create Dictionary tag=isp value=${isp} ids=${isp_ids}
|
||
|
||
${tag_sets_2} Create List ${DataCenter_json}
|
||
${tag_sets} Create List ${tag_sets_2}
|
||
${effectiveRange} Create Dictionary tag_sets=${tag_sets}
|
||
# 编写iplist json格式
|
||
log ${PacketCapturedata}
|
||
# 构建PolicyList
|
||
${addrType} evaluate int(${PacketCapturedata}[addrType])
|
||
${protocol} evaluate int(${PacketCapturedata}[protocol])
|
||
${second} Set Variable ${3600}
|
||
${captureDuration1} evaluate int(${PacketCapturedata}[captureDuration])
|
||
${captureDuration} evaluate ${captureDuration1}*${second}
|
||
log ${captureDuration}
|
||
${policyListDict} Create Dictionary
|
||
... policyId=${PacketCapturedata}[policyId]
|
||
... policyName=${PacketCapturedata}[policyName]
|
||
... addrType=${addrType}
|
||
... protocol=${protocol}
|
||
... clientIp=${PacketCapturedata}[clientIp]
|
||
... clientPort=${PacketCapturedata}[clientPort]
|
||
... serverIp=${PacketCapturedata}[serverIp]
|
||
... serverPort=${PacketCapturedata}[serverPort]
|
||
... maxPacket=${PacketCapturedata}[maxPacket]
|
||
... captureDuration=${captureDuration}
|
||
... effectiveRange=${effectiveRange}
|
||
log ${policyListDict}
|
||
${policyList} Create List ${policyListDict}
|
||
# 判断json是用于修改还是新增
|
||
${opAction} run keyword if '${PacketCapturedata}[policyId]'=="" Set Variable add
|
||
... ELSE Set Variable update
|
||
#编写最外面的格式
|
||
${returnData} evaluate int(1)
|
||
${PacketCapture} Create Dictionary opAction=${opAction} returnData=${returnData} policyList=${policyList}
|
||
# 返回请求json
|
||
log ${PacketCapture}
|
||
${json} json.Dumps ${PacketCapture} ensure_ascii=False
|
||
log 111111111111${json}
|
||
[Return] ${json} |