summaryrefslogtreecommitdiff
path: root/keyword/objects/ip_objects.robot
diff options
context:
space:
mode:
Diffstat (limited to 'keyword/objects/ip_objects.robot')
-rw-r--r--keyword/objects/ip_objects.robot176
1 files changed, 176 insertions, 0 deletions
diff --git a/keyword/objects/ip_objects.robot b/keyword/objects/ip_objects.robot
new file mode 100644
index 0000000..19a4b55
--- /dev/null
+++ b/keyword/objects/ip_objects.robot
@@ -0,0 +1,176 @@
+*** Settings ***
+Library yaml
+Resource ../../../variable/common_variable.txt
+Resource object.robot
+Resource ../../common/common.robot
+Library Collections
+Library json
+Library String
+#Resource ip.yaml
+*** Variables ***
+${objectUrl} /policy/object
+${objectids} ${EMPTY}
+
+*** Keywords ***
+AllowDns001ObjectV4
+ [Tags]
+ [Arguments] ${filepath} ${filename} ${keywords}
+ Comment 参数 ${filepath}读取文件路径 ${filename}读取文件名 ${keywords}获取数据关键字
+ Comment 创建IP
+ #yaml在线格式化:https://www.bejson.com/validators/yaml_editor/
+ ${YAML}= Get File ${filepath}${/}${filename}
+ ${LOADED}= yaml.Safe Load ${YAML}
+ ${ip_secuirty_allow_dns_001} Get From Dictionary ${LOADED} ${keywords}
+ ${retkeys} evaluate [one for one in ${ip_secuirty_allow_dns_001}]
+ ${dictType} = Evaluate type(${retkeys})
+ ${returnData} Get From Dictionary ${ip_secuirty_allow_dns_001} returnData
+ ${bodyJson} json.Dumps ${ip_secuirty_allow_dns_001}
+
+ #Set To Dictionary ${LOADED}[patch_id_bw_data][pronghornResponseBody][responseBody][0][value][0] value=200
+ #${addItemList1} Create Dictionary isSession=endpoint ip=${testClentIP} port=0-65535 direction=0 protocol=0 isInitialize=0
+ #${addItemLists} Create list ${addItemList1}
+ #${objectDict} Create Dictionary objectType=ip objectSubType=endpoint isValid=${1} addItemList=${addItemLists}
+ #${rescode} ${objectId} AddObjects ${1} ${objectDict}
+ #${objectids} set Variable ${objectId}
+
+ ${response} BasePostRequestForV2 ${objectUrl} ${bodyJson} ${version}
+ ${objectIds} Run Keyword If "${returnData}" == "1" GetObjectIds ${response}
+ ... ELSE Create List
+ ${rescode} Set Variable ${response['code']}
+ Should Be Equal As Strings ${rescode} 200
+ [Return] ${rescode} ${objectIds}
+
+IpObject
+ [Tags]
+ [Arguments] ${filepath} ${filename} ${keywords}
+ Comment 参数 ${filepath}读取文件路径 ${filename}读取文件名 ${keywords}获取数据关键字
+ Comment 创建IP
+ #yaml在线格式化:https://www.bejson.com/validators/yaml_editor/
+ ${YAML}= Get File ${filepath}${/}${filename}
+ ${LOADED}= yaml.Safe Load ${YAML}
+ ${ipList} Get From Dictionary ${LOADED} ${keywords}
+ ${rescode} ${objectIds} IpRequest ${ipList}
+ [Return] ${rescode} ${objectIds}
+
+BatchCreateIps
+ [Tags]
+ [Arguments] ${filepath} ${filename} ${keywords}
+ Comment 参数 ${filepath}读取文件路径 ${filename}读取文件名 ${keywords}获取数据关键字
+ Comment 创建IP
+ #yaml在线格式化:https://www.bejson.com/validators/yaml_editor/
+ ${YAML}= Get File ${filepath}${/}${filename}
+ ${LOADED}= yaml.Safe Load ${YAML}
+ ${ipList} Get From Dictionary ${LOADED} ${keywords}
+ ${ipListType} = Evaluate type(${ipList})
+ #${retkeys} evaluate [one for one in ${ipList}]
+ #${dictType} = Evaluate type(${retkeys})
+ ${objectIds} Run Keyword If "${ipListType}" == "<class 'list'>" IpObjectBatch ${ipList}
+ ... ELSE Set Variable ${EMPTY}
+ ${ipListType} = Evaluate type(${objectIds})
+ ${json} json.Dumps ${objectIds} ensure_ascii=False
+ ${json} = Replace String ${json} ["", [
+ ${objectIds} json.loads ${json}
+ [Return] ${objectIds}
+
+IpObjectBatch
+ [Tags]
+ [Arguments] ${objDictList}
+ Comment 参数${objDictList}多个象字典列表
+ Comment 创建IP
+ ${objids} Create List ${EMPTY}
+ ${ipListType} = Evaluate type(${objDictList})
+ FOR ${objDict} IN @{objDictList}
+ ${rescode} ${objectIds} CreateObject ${objDict}
+ AppendListToList ${objids} ${objectIds}
+ END
+ [Return] ${objids}
+
+
+#####################################################################################################################
+
+OrangeFilter
+ [Documentation] filer对象处理,把一个filter的list处理为一个filter
+ #[Arguments] ${filterList} ${objectList}
+ [Arguments] ${objectList}
+ ${list} Create List ${objectList}
+ ${filter} Create Dictionary filter=${list}
+ #${filterList} Append To List ${filter}
+ [Return] ${filter}
+
+CreateObjectList
+ [Documentation] 处理对象
+ [Arguments] ${objectData}
+ Comment 针对位置进行处理
+ ${protocolField} Get From Dictionary ${objectData} protocolField
+ #${objList} Get From Dictionary ${objectData} objList
+
+ ${objectIds} ${objectList} CreateObjects ${objectData}
+ ${objectList} Run Keyword If "${protocolField}" == "TSG_SECURITY_SOURCE_ADDR" or "${protocolField}" == "None" or "${protocolField}" == "TSG_SECURITY_SOURCE_LOCATION" or "${protocolField}" == "TSG_SECURITY_SOURCE_ASN" or "${protocolField}" == "TSG_FILED_GTP_IMSI" or "${protocolField}" == "TSG_FILED_GTP_PHONE_NUMBER" or "${protocolField}" == "TSG_FILED_GTP_APN" Set Variable ${objectList}
+ ##############destination
+ ... ELSE IF "${protocolField}" == "TSG_SECURITY_DESTINATION_ADDR" or "${protocolField}" == "TSG_SECURITY_DESTINATION_LOCATION" or "${protocolField}" == "TSG_SECURITY_DESTINATION_ASN" Set Variable ${objectList}
+ #filter
+ ... ELSE OrangeFilter ${objectList}
+ [Return] ${objectIds} ${objectList}
+CreateObjects
+ [Documentation] 处理对象
+ [Arguments] ${objectData}
+ Comment 针对位置进行处理
+ #${YAML}= Get File ${path}/data/mode.yaml
+ #${LOADED}= yaml.Safe Load ${YAML}
+ #${ipMode} Get From Dictionary ${LOADED} ip_batch_mode
+ ${protocolField} Get From Dictionary ${objectData} protocolField
+ ${objList} Get From Dictionary ${objectData} objList
+
+ Comment ${objJson}对象模板取自全局变量
+ ${objJson} Set Variable ${objModeJson}
+ ${objectJson} Set Variable ${objListMode}
+ #JSON处理
+ ${return} ${objectType} Run Keyword And Ignore Error Get From Dictionary ${objectData} objectType
+ ${objectJson} = Run Keyword If "${return}"!="FAIL" and "${objectType}" != "None" Replace String ${objectJson} "objectType": "ip" "objectType":"${objectType}"
+ ... ELSE Set Variable ${objectJson}
+ ${return} ${objectSubType} Run Keyword And Ignore Error Get From Dictionary ${objectData} objectSubType
+ #${objectSubType} Run Keyword If "${return}"!="FAIL" Set Variable ${objectSubType} ELSE Set Variable ${EMPTY}
+ ${objectJson} = Run Keyword If "${return}"!="FAIL" and "${objectSubType}" != "None" Replace String ${objectJson} "objectSubType": "endpoint" "objectSubType":"${objectSubType}"
+ ... ELSE Set Variable ${objectJson}
+ ${return} ${objectId} Run Keyword And Ignore Error Get From Dictionary ${objectData} objectId
+ ${objectJson} = Run Keyword If "${return}"!="FAIL" and "${objectId}" != "None" Replace String ${objectJson} "objectId": null "objectId":${objectId}
+ ... ELSE Set Variable ${objectJson}
+ ${objectJson} = Run Keyword If "${return}"!="FAIL" and "${objectId}" != "None" Replace String ${objectJson} "opAction": "add" "option": "update"
+ ... ELSE Set Variable ${objectJson}
+ #${objectId} Run Keyword If "${return}"!="FAIL" Set Variable ${objectId} ELSE Set Variable ${EMPTY}
+ #JSON处理
+ ${objectJsonList} Create List
+ ${objListType} = Evaluate type(${objList})
+ FOR ${obj} IN @{objList}
+ ${return} ${addItemList} Run Keyword And Ignore Error Get From Dictionary ${obj} addItemList
+ #${objectJson} Convert To String ${objectJson}
+ #${addItemList} Convert To String ${addItemList}
+ #${objectJson} josn.loads ${objectJson}
+ ${addItemList} json.Dumps ${addItemList}
+ #${objectJson} = Replace String ${objectJson} "addItemList": "addItemList":${itemList}
+ ${addItemList} = Run Keyword If "${return}"!="FAIL" and "${objectSubType}" == "ip_learning" Replace String ${addItemList} [{" "
+ ... ELSE Set Variable ${addItemList}
+ ${addItemList} = Run Keyword If "${return}"!="FAIL" and "${objectSubType}" == "ip_learning" Replace String ${addItemList} "}] "
+ ... ELSE Set Variable ${addItemList}
+ ${objectJson} = Run Keyword If "${return}"!="FAIL" and "${objectSubType}" == "ip_learning" Replace String ${objectJson} "addItemList": [null] "addItemList": [], ${addItemList}
+ ... ELSE IF "${return}"!="FAIL" Replace String ${objectJson} "addItemList": [null] "addItemList": ${addItemList}
+ ... ELSE Set Variable ${objectJson}
+ ${objectJson} = Replace String ${objectJson} [null] []
+ #提交接口返回id拼接
+
+ #Create File ${path}/test.txt ${objectJson}
+ #Append To File ${path}/test.txt ${objectJson}
+ ${objDictionary} json.loads ${objectJson}
+ AppendListToList ${objectJsonList} ${objDictionary}
+ END
+ ${objectData} Create Dictionary opAction=add returnData=1 objectList=${objectJsonList}
+ ${rescode} ${objectIds} createObject ${objectData}
+ Should Be Equal As Strings ${rescode} 200
+
+ ${protocolField} Run Keyword If "${protocolField}" != "None" Set Variable ${protocolField}
+ ${objectsList} Create List
+ FOR ${obj} IN @{objectIds}
+ ${objectList} Create Dictionary objectId=${objectIds}[0] protocolField=${protocolField}
+ Append To List ${objectsList} ${objectList}
+ END
+ [Return] ${objectIds} ${objectList}