This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
dongxiaoyan-tsg-autotest/02-Keyword/tsg_bfapi/policy_object/ProcessObjectBody.robot

189 lines
12 KiB
Plaintext
Raw Normal View History

*** Settings ***
Library json
Library Collections
Resource ../../../03-Variable/BifangApiVariable.txt
Resource ../../../03-Variable/PolicyObjectDefault.txt
Resource ../../tsg_common/ManageObjectBody.robot
*** Keywords ***
ObjectListOperation
[Documentation]
... 描述入口opAction参数可为'add','update','disable','enable'
... 参数returnData: 必传,是否返回请求数据。可选${0}(不返回)/${1}(返回)。
... objectList: 必传,字典类型。字典内可选参数信息:
... 其它参数默认值见../../03-Variable/PolicyObjectDefault.txt
... 多个对象处理
[Arguments] ${returnData} ${objectList} ${opAction}
Log To Console Call ObjectListOperation
${objectListJson} Set Variable [
FOR ${object} IN @{objectList}
${json} ObjectOrganize ${object} ${opAction}
${objectListJson} Set Variable ${objectListJson}${json},
END
${objectListJson}= Replace String Using Regexp ${objectListJson} ,$ ]
# 转为json结构并返回
${dict} Create Dictionary opAction=${opAction} returnData=${returnData} objectList=replace:objectList
${bodyJson} json.Dumps ${dict} ensure_ascii=False
${json} Replace String ${bodyJson} "replace:objectList" ${objectListJson}
Log Object_Request_Body-${json}
[Return] ${json}
ObjectOperation
[Documentation]
... 描述入口opAction参数可为'add','update','disable','enable'
... 参数returnData: 必传,是否返回请求数据。可选${0}(不返回)/${1}(返回)。
... object: 必传,字典类型。字典内可选参数信息:
... 其它参数默认值见../../03-Variable/PolicyObjectDefault.txt
... 单个策略处理
[Arguments] ${returnData} ${object} ${opAction}
Log To Console Call ObjectOperation
${json} ObjectOrganize ${object} ${opAction}
# 转为json结构并返回
${dict} Create Dictionary opAction=${opAction} returnData=${returnData} objectList=replace:objectList
${bodyJson} json.Dumps ${dict} ensure_ascii=False
${json} Replace String ${bodyJson} "replace:objectList" ${json}
Log Object_Request_Body-${json}
[Return] ${json}
2020-07-23 16:21:20 +08:00
listorone
[Arguments] ${object}
${addItemList} Evaluate str('addItemList'in${object}.keys())
log ${addItemList}
${subObjectIds} Evaluate str('subObjectIds'in${object}.keys())
log ${subObjectIds}
${objectparm} set variable ${addItemList} ${subObjectIds}
should contain x times ${objectparm} True 1
# Should Not Be Empty ${object}[addItemList] or Should Not Be Empty ${object}[subObjectIds]
ObjectOrganize
[Documentation]
... 描述入口opAction参数可为'add','update','disable','enable'
... object: 必传,字典类型。字典内可选参数信息:
... 其它参数默认值见../../03-Variable/PolicyObjectDefault.txt
... 单个策略转换为json
[Arguments] ${object} ${opAction}
Log To Console Call ObjectOrganize
${emptyList} Create List
${returnDict} Create Dictionary
# 断言必传参数
# Should Not Be Empty ${object}[objectType]
# Set To Dictionary ${returnDict} objectType=${object}[objectType]
#新增时addItemList不能为空
2020-07-23 16:21:20 +08:00
Run Keyword If "${opAction}"=="add" listorone ${object}
Run Keyword If "${opAction}"=="update" Should Not Be Empty ${object}[objectId]
Run Keyword If "${opAction}"=="enable" Should Not Be Empty ${object}[objectId]
Run Keyword If "${opAction}"=="disable" Should Not Be Empty ${object}[objectId]
${return} ${objectId} Run Keyword And Ignore Error Get From Dictionary ${object} objectId
Run Keyword If "${return}"=="FAIL" or "${objectId}"=="${EMPTY}" Set To Dictionary ${returnDict} objectId=${EMPTY}
... ELSE Set To Dictionary ${returnDict} objectId=${objectId}
${return} ${objectType} Run Keyword And Ignore Error Get From Dictionary ${object} objectType
${objectTypeV} Run Keyword If "${return}"!="FAIL" and "${objectType}"!="${EMPTY}" Evaluate '${objectType}'.lower()
... ELSE Evaluate '${Default_ObjectType}'.lower()
Set To Dictionary ${returnDict} objectType=${objectTypeV}
#enable disable直接返回json
Run Keyword And Return If "${opAction}"=="enable" or "${opAction}"=="disable" ManageEnableAndDisable ${object} ${returnDict} ${opAction}
# 取可选参数,为传入设置默认值
Set To Dictionary ${returnDict} objectType=${objectTypeV}
${return} ${objectSubType} Run Keyword And Ignore Error Get From Dictionary ${object} 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 Get From Dictionary ${object} 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 Get From Dictionary ${object} 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 Get From Dictionary ${object} 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 Get From Dictionary ${object} 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 Get From Dictionary ${object} 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 Get From Dictionary ${object} subObjectIds
2020-07-23 16:21:20 +08:00
Run Keyword If "${return}"!="FAIL" and "${subObjectIds}"!="${EMPTY}" and "${subObjectIds}"!="${None}" Set To Dictionary ${returnDict} subObjectIds=${subObjectIds}
... ELSE Set Variable ${emptyList}
#补充ip learning对象
${return} ${fromFqdns} Run Keyword And Ignore Error Get From Dictionary ${object} fromFqdns
Run Keyword If "${return}"!="FAIL" Set To Dictionary ${returnDict} fromFqdns=${fromFqdns}
#... ELSE Set To Dictionary ${returnDict} fromFqdns=${emptyList}
log ${fromFqdns}
${return} ${fromProtocol} Run Keyword And Ignore Error Get From Dictionary ${object} fromProtocol
Run Keyword If "${return}"!="FAIL" and "${fromProtocol}"!="${EMPTY}" Set To Dictionary ${returnDict} fromProtocol=${fromProtocol}
#... ELSE Set To Dictionary ${returnDict} fromProtocol=${Default_fromProtocol}
${return} ${learningDepth} Run Keyword And Ignore Error Get From Dictionary ${object} learningDepth
Run Keyword If "${return}"!="FAIL" and "${learningDepth}"!="${EMPTY}" Set To Dictionary ${returnDict} learningDepth=${learningDepth}
#... ELSE Set To Dictionary ${returnDict} learningDepth=${Default_learningDepth}
${return} ${agingTime} Run Keyword And Ignore Error Get From Dictionary ${object} agingTime
Run Keyword If "${return}"!="FAIL" and "${fromProtocol}"!="${EMPTY}" Set To Dictionary ${returnDict} agingTime=${agingTime}
#... ELSE Set To Dictionary ${returnDict} agingTime=${Default_agingTime}
${return} ${voteClientNum} Run Keyword And Ignore Error Get From Dictionary ${object} voteClientNum
Run Keyword If "${return}"!="FAIL" and "${fromProtocol}"!="${EMPTY}" Set To Dictionary ${returnDict} voteClientNum=${voteClientNum}
#... ELSE Set To Dictionary ${returnDict} voteClientNum=${Default_voteClientNum}
${return} ${learnedIpLimit} Run Keyword And Ignore Error Get From Dictionary ${object} learnedIpLimit
Run Keyword If "${return}"!="FAIL" and "${fromProtocol}"!="${EMPTY}" Set To Dictionary ${returnDict} learnedIpLimit=${learnedIpLimit}
#... ELSE Set To Dictionary ${returnDict} learnedIpLimit=${Default_learnedIpLimit}
# 处理AddItemList
${return} ${addItemList} Run Keyword And Ignore Error Get From Dictionary ${object} addItemList
Run Keyword If "${return}"!="FAIL" and "${addItemList}"!="${EMPTY}" ManageAddItemList ${object} ${returnDict}
# 处理UpdateItemList
${return} ${updateItemList} Run Keyword And Ignore Error Get From Dictionary ${object} updateItemList
Run Keyword If "${opAction}"=="update" and "${return}"!="FAIL" and "${updateItemList}"!="${EMPTY}" ManageUpdateItemList ${updateItemList} ${returnDict}
# 处理deleteItemIds
${return} ${deleteItemIds} Run Keyword And Ignore Error Get From Dictionary ${object} deleteItemIds
Run Keyword If "${opAction}"=="update" and "${return}"!="FAIL" and "${deleteItemIds}"!="${EMPTY}" ManageDeleteItemIds ${deleteItemIds} ${returnDict}
# 转为json结构并返回
${json} json.Dumps ${returnDict} ensure_ascii=False
Log Object-${json}
[Return] ${json}
ManageEnableAndDisable
[Documentation]
... 启用与禁用时调用
[Arguments] ${object} ${returnDict} ${opAction}
Run Keyword If "${opAction}"=="enable" Set To Dictionary ${returnDict} isValid=1
Run Keyword If "${opAction}"=="disable" Set To Dictionary ${returnDict} isValid=0
${json} json.Dumps ${returnDict} ensure_ascii=False
Log Object-${json}
[Return] ${json}
ManageUpdateItemList
[Documentation]
... 处理updateItemList
[Arguments] ${updateItemList} ${returnDict}
Set To Dictionary ${returnDict} updateItemList=${updateItemList}
ManageDeleteItemIds
[Documentation]
... 处理deleteItemIds
... ${1},${2},${3} -> [1,2,3]
[Arguments] ${deleteItemIds} ${returnDict}
${list} Evaluate re.split('[,]', '${deleteItemIds}') re
${list1} Create List
FOR ${var} IN @{list}
${var} Run Keyword If '${var}'.isdigit() Evaluate int('${var}')
... ELSE Set Variable ${var}
Append To List ${list1} ${var}
END
Set To Dictionary ${returnDict} deleteItemIds=${list1}
Get-ObjectIds
[Documentation]
... 获取结果中的对象ID
[Arguments] ${value}
Log Call Get-ObjectIds
${objectIds} Create List
${objectIdsTemp} Set Variable ${EMPTY}
${return} ${data} Run Keyword And Ignore Error Get From Dictionary ${value} data
Return From Keyword If "${return}"=="FAIL" ${objectIdsTemp}
FOR ${object} IN @{value['data']['objectList']}
Append To List ${objectIds} ${object['objectId']}
END
${json} json.Dumps ${objectIds} ensure_ascii=False
${json} Remove String ${json} [
${json} Remove String ${json} ]
[Return] ${json}