summaryrefslogtreecommitdiff
path: root/keyword/objects/ip_objects.robot
blob: 19a4b55abdccacab2818892ccea051999bd51ca7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
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}