2 Documentation Utils for Restconf operations for GBP
3 Library RequestsLibrary
4 Library OperatingSystem
7 Variables ../../variables/Variables.py
8 Resource ../Utils.robot
11 ${ENDPOINT_UNREG_PATH} ${GBP_UNREGEP_API}
12 ${ENDPOINTS_OPER_PATH} /restconf/operational/endpoint:endpoints
16 [Documentation] Unregister Endpoints Endpoints from ODL
17 ${result} = RequestsLibrary.Get Request session ${ENDPOINTS_OPER_PATH}
18 ${json_result} = json.loads ${result.text}
19 Pass Execution If ${json_result['endpoints']}=={} No Endpoints available
20 ${L2_ENDPOINTS} = Set Variable ${json_result['endpoints']['endpoint']}
21 ${L3_ENDPOINTS} = Set Variable ${json_result['endpoints']['endpoint-l3']}
23 Unregister L2Endpoints ${L2_ENDPOINTS}
25 Unregister L3Endpoints ${L3_ENDPOINTS}
26 ${result} = RequestsLibrary.Get Request session ${ENDPOINTS_OPER_PATH}
27 ${json_result} = json.loads ${result.text}
28 Should Be Empty ${json_result['endpoints']}
30 Unregister L2Endpoints
32 [Documentation] Unregister Endpoints L2Endpoints from ODL
33 FOR ${endpoint} IN @{l2_eps}
34 ${l2_data} = Create L2 Endpoint JSON Data ${endpoint}
35 Post Elements To URI ${ENDPOINT_UNREG_PATH} ${l2_data} ${HEADERS_YANG_JSON}
38 Unregister L3Endpoints
40 [Documentation] Unregister Endpoints L3Endpoints from ODL
41 FOR ${endpoint} IN @{l3_eps}
42 ${l3_data} = Create L3 Endpoint JSON Data ${endpoint}
43 Post Elements To URI ${ENDPOINT_UNREG_PATH} ${l3_data} ${HEADERS_YANG_JSON}
46 Create L2 Endpoint JSON Data
47 [Arguments] ${endpoint}
48 [Documentation] Generate the JSON data required for unregistering L2 Endpoints
49 ${data} Set Variable {"input": {"l2": [{"mac-address": "${endpoint['mac-address']}", "l2-context": "${endpoint['l2-context']}"}]}}
52 Create L3 Endpoint JSON Data
53 [Arguments] ${endpoint}
54 [Documentation] Generate the JSON data required for unregistering L3 Endpoints
55 ${data} Set Variable {"input": {"l3": [{"l3-context": "${endpoint['l3-context']}", "ip-address": "${endpoint['ip-address']}"}]}}
59 [Arguments] ${l2-context} ${mac_address}
60 [Documentation] Returns path for a registered endpoint based on key in arguments
61 ${mac_address} Convert To Uppercase ${mac_address}
62 [Return] restconf/operational/endpoint:endpoints/endpoint/${l2-context}/${mac_address}
65 [Arguments] ${l3-context} ${ip_address}
66 [Documentation] Returns path for a registered endpoint-l3 based on key in arguments
67 [Return] restconf/operational/endpoint:endpoints/endpoint-l3/${l3-context}/${ip_address}
70 [Arguments] ${tenant_id}
71 [Documentation] Returns path for a tenant based on key in arguments
72 [Return] ${TENANTS_CONF_PATH}/policy:tenant/${tenant_id}
75 [Arguments] ${tenant_id}
76 [Documentation] Returns policy path for a particular tenant
77 ${tenant_path} Get Tenant Path ${tenant_id}
78 [Return] ${tenant_path}/policy
81 [Arguments] ${tenant_id} ${contract_id}
82 [Documentation] Returns path for a contract based on key and tenant-id in arguments
83 ${policy_path} Get Policy Path ${tenant_id}
84 [Return] ${policy_path}/contract/${contract_id}
86 Get Endpoint Group Path
87 [Arguments] ${tenant_id} ${endpoint_group_id}
88 [Documentation] Returns path for an EPG based on key and tenant-id in arguments
89 ${policy_path} Get Policy Path ${tenant_id}
90 [Return] ${policy_path}/endpoint-group/${endpoint_group_id}
92 Get Classifier Instance Path
93 [Arguments] ${tenant_id} ${classif_instance_id}
94 [Documentation] Returns path for a classifier-instance based on key and tenant-id in arguments
95 ${policy_path} Get Policy Path ${tenant_id}
96 [Return] ${policy_path}/subject-feature-instances/classifier-instance/${classif_instance_id}
98 Get Forwarding Context Path
99 [Arguments] ${tenant_id}
100 [Documentation] Returns forwarding path for a particular tenant
101 ${tenant_path} Get Tenant Path ${tenant_id}
102 [Return] ${tenant_path}/forwarding-context
105 [Arguments] ${tenant_id} ${l3_ctx_id}
106 [Documentation] Returns l3-context path based on key and tenant-id in arguments
107 ${fwd_ctx_path} Get Forwarding Context Path ${tenant_id}
108 [Return] ${fwd_ctx_path}/l3-context/${l3_ctx_id}
110 Get L2 Bridge Domain Path
111 [Arguments] ${tenant_id} ${l2_br_domain_id}
112 [Documentation] Returns l2-bridge-domain path based on key and tenant-id in arguments
113 ${fwd_ctx_path} Get Forwarding Context Path ${tenant_id}
114 [Return] ${fwd_ctx_path}/l2-bridge-domain/${l2_br_domain_id}
116 Get L2 Flood Domain Path
117 [Arguments] ${tenant_id} ${l2_flood_domain_id}
118 [Documentation] Returns l2-flood-domain path based on key and tenant-id in arguments
119 ${fwd_ctx_path} Get Forwarding Context Path ${tenant_id}
120 [Return] ${fwd_ctx_path}/l2-flood-domain/${l2_flood_domain_id}
123 [Arguments] ${tenant_id} ${subnet_id}
124 [Documentation] Returns path for a subnet based on key and tenant-id in arguments
125 ${fwd_ctx_path} Get Forwarding Context Path ${tenant_id}
126 [Return] ${fwd_ctx_path}/subnet/${subnet_id}
128 Get Prefix Constraint of Single Rule Contract
129 [Arguments] ${contract}
130 [Documentation] Returns first prefix-constraint from a single rule contract
131 ${contract_json} To Json ${contract}
132 ${eic} Set Variable ${contract_json['contract'][0]['clause'][0]['consumer-matchers']['endpoint-identification-constraints']}
133 [Return] ${eic['l3-endpoint-identification-constraints']['prefix-constraint'][0]}
135 Get Action of Single Rule Contract
136 [Arguments] ${contract}
137 [Documentation] Returns first action-ref from a single rule contract
138 ${contract_json} To Json ${contract}
139 [Return] ${contract_json['contract'][0]['subject'][0]['rule'][0]['action-ref'][0]}
141 Get Ip Prefix of Subnet
142 [Arguments] ${subnet}
143 [Documentation] Returns ip-prefix from a given subnet
144 ${subnet_json} To Json ${subnet}
145 [Return] ${subnet_json['subnet'][0]['ip-prefix']}
147 Get Action Instance Name of Single Rule Contract
148 [Arguments] ${contract}
149 [Documentation] Returns action-instance name from a single rule contract
150 ${contract_json} To Json ${contract}
151 [Return] ${contract_json['contract'][0]['subject'][0]['rule'][0]['classifier-ref'][0]['instance-name']}
153 Get Groups of Endpoint
154 [Arguments] ${endpoint}
155 [Documentation] Returns endpoint-groups from a given endpoint
156 ${endpoint_json} To Json ${endpoint}
157 [Return] ${endpoint_json['endpoint'][0]['endpoint-groups']}
159 Get Groups of Endpoint-L3
160 [Arguments] ${endpoint-l3}
161 [Documentation] Returns endpoint-groups from a given endpoint-l3
162 ${endpoint_json} To Json ${endpoint-l3}
163 [Return] ${endpoint_json['endpoint-l3'][0]['endpoint-groups']}
165 Get L3-Addresses of Endpoint
166 [Arguments] ${endpoint}
167 [Documentation] Returns l3-addresses from a given endpoint
168 ${endpoint_json} To Json ${endpoint}
169 [Return] ${endpoint_json['endpoint'][0]['l3-address']}
171 Get Tenant of Endpoint
172 [Arguments] ${endpoint}
173 [Documentation] Returns tenant-id from a given endpoint
174 ${endpoint_json} To Json ${endpoint}
175 [Return] ${endpoint_json['endpoint'][0]['tenant']}
177 Get Tenant of Endpoint-L3
178 [Arguments] ${endpoint-l3}
179 [Documentation] Returns tenant-id from a given endpoint-l3
180 ${endpoint_json} To Json ${endpoint-l3}
181 [Return] ${endpoint_json['endpoint-l3'][0]['tenant']}
183 Get Network Containment of Endpoint
184 [Arguments] ${endpoint}
185 [Documentation] Returns network-containment from a given endpoint
186 ${endpoint_json} To Json ${endpoint}
187 [Return] ${endpoint_json['endpoint'][0]['network-containment']}
189 Get Network Containment of Endpoint-L3
190 [Arguments] ${endpoint-l3}
191 [Documentation] Returns network-containment from a given endpoint-l3
192 ${endpoint_json} To Json ${endpoint-l3}
193 [Return] ${endpoint_json['endpoint-l3'][0]['network-containment']}
195 Get Mac Address of Endpoint
196 [Arguments] ${endpoint}
197 [Documentation] Returns mac-address from a given endpoint
198 ${endpoint_json} To Json ${endpoint}
199 [Return] ${endpoint_json['endpoint'][0]['mac-address']}
201 Get Mac Address of Endpoint-L3
202 [Arguments] ${endpoint-l3}
203 [Documentation] Returns mac-address from a given endpoint-l3
204 ${endpoint_json} To Json ${endpoint-l3}
205 [Return] ${endpoint_json['endpoint-l3'][0]['mac-address']}
207 Get L2 Context of Endpoint-L3
208 [Arguments] ${endpoint-l3}
209 [Documentation] Returns l2-context from a given endpoint-l3
210 ${endpoint_json} To Json ${endpoint-l3}
211 [Return] ${endpoint_json['endpoint-l3'][0]['l2-context']}