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}
37 Unregister L3Endpoints
39 [Documentation] Unregister Endpoints L3Endpoints from ODL
40 : FOR ${endpoint} IN @{l3_eps}
41 \ ${l3_data} = Create L3 Endpoint JSON Data ${endpoint}
42 \ Post Elements To URI ${ENDPOINT_UNREG_PATH} ${l3_data} ${HEADERS_YANG_JSON}
44 Create L2 Endpoint JSON Data
45 [Arguments] ${endpoint}
46 [Documentation] Generate the JSON data required for unregistering L2 Endpoints
47 ${data} Set Variable {"input": {"l2": [{"mac-address": "${endpoint['mac-address']}", "l2-context": "${endpoint['l2-context']}"}]}}
50 Create L3 Endpoint JSON Data
51 [Arguments] ${endpoint}
52 [Documentation] Generate the JSON data required for unregistering L3 Endpoints
53 ${data} Set Variable {"input": {"l3": [{"l3-context": "${endpoint['l3-context']}", "ip-address": "${endpoint['ip-address']}"}]}}
57 [Documentation] Returns path for a registered endpoint based on key in arguments
58 [Arguments] ${l2-context} ${mac_address}
59 ${mac_address} Convert To Uppercase ${mac_address}
60 [Return] restconf/operational/endpoint:endpoints/endpoint/${l2-context}/${mac_address}
63 [Documentation] Returns path for a registered endpoint-l3 based on key in arguments
64 [Arguments] ${l3-context} ${ip_address}
65 [Return] restconf/operational/endpoint:endpoints/endpoint-l3/${l3-context}/${ip_address}
68 [Documentation] Returns path for a tenant based on key in arguments
69 [Arguments] ${tenant_id}
70 [Return] ${TENANTS_CONF_PATH}/policy:tenant/${tenant_id}
73 [Documentation] Returns policy path for a particular tenant
74 [Arguments] ${tenant_id}
75 ${tenant_path} Get Tenant Path ${tenant_id}
76 [Return] ${tenant_path}/policy
79 [Documentation] Returns path for a contract based on key and tenant-id in arguments
80 [Arguments] ${tenant_id} ${contract_id}
81 ${policy_path} Get Policy Path ${tenant_id}
82 [Return] ${policy_path}/contract/${contract_id}
84 Get Endpoint Group Path
85 [Documentation] Returns path for an EPG based on key and tenant-id in arguments
86 [Arguments] ${tenant_id} ${endpoint_group_id}
87 ${policy_path} Get Policy Path ${tenant_id}
88 [Return] ${policy_path}/endpoint-group/${endpoint_group_id}
90 Get Classifier Instance Path
91 [Documentation] Returns path for a classifier-instance based on key and tenant-id in arguments
92 [Arguments] ${tenant_id} ${classif_instance_id}
93 ${policy_path} Get Policy Path ${tenant_id}
94 [Return] ${policy_path}/subject-feature-instances/classifier-instance/${classif_instance_id}
96 Get Forwarding Context Path
97 [Documentation] Returns forwarding path for a particular tenant
98 [Arguments] ${tenant_id}
99 ${tenant_path} Get Tenant Path ${tenant_id}
100 [Return] ${tenant_path}/forwarding-context
103 [Documentation] Returns l3-context path based on key and tenant-id in arguments
104 [Arguments] ${tenant_id} ${l3_ctx_id}
105 ${fwd_ctx_path} Get Forwarding Context Path ${tenant_id}
106 [Return] ${fwd_ctx_path}/l3-context/${l3_ctx_id}
108 Get L2 Bridge Domain Path
109 [Documentation] Returns l2-bridge-domain path based on key and tenant-id in arguments
110 [Arguments] ${tenant_id} ${l2_br_domain_id}
111 ${fwd_ctx_path} Get Forwarding Context Path ${tenant_id}
112 [Return] ${fwd_ctx_path}/l2-bridge-domain/${l2_br_domain_id}
114 Get L2 Flood Domain Path
115 [Documentation] Returns l2-flood-domain path based on key and tenant-id in arguments
116 [Arguments] ${tenant_id} ${l2_flood_domain_id}
117 ${fwd_ctx_path} Get Forwarding Context Path ${tenant_id}
118 [Return] ${fwd_ctx_path}/l2-flood-domain/${l2_flood_domain_id}
121 [Documentation] Returns path for a subnet based on key and tenant-id in arguments
122 [Arguments] ${tenant_id} ${subnet_id}
123 ${fwd_ctx_path} Get Forwarding Context Path ${tenant_id}
124 [Return] ${fwd_ctx_path}/subnet/${subnet_id}
126 Get Prefix Constraint of Single Rule Contract
127 [Documentation] Returns first prefix-constraint from a single rule contract
128 [Arguments] ${contract}
129 ${contract_json} To Json ${contract}
131 ... ${contract_json['contract'][0]['clause'][0]['consumer-matchers']['endpoint-identification-constraints']}
132 [Return] ${eic['l3-endpoint-identification-constraints']['prefix-constraint'][0]}
134 Get Action of Single Rule Contract
135 [Documentation] Returns first action-ref from a single rule contract
136 [Arguments] ${contract}
137 ${contract_json} To Json ${contract}
138 [Return] ${contract_json['contract'][0]['subject'][0]['rule'][0]['action-ref'][0]}
140 Get Ip Prefix of Subnet
141 [Documentation] Returns ip-prefix from a given subnet
142 [Arguments] ${subnet}
143 ${subnet_json} To Json ${subnet}
144 [Return] ${subnet_json['subnet'][0]['ip-prefix']}
146 Get Action Instance Name of Single Rule Contract
147 [Documentation] Returns action-instance name from a single rule contract
148 [Arguments] ${contract}
149 ${contract_json} To Json ${contract}
150 [Return] ${contract_json['contract'][0]['subject'][0]['rule'][0]['classifier-ref'][0]['instance-name']}
152 Get Groups of Endpoint
153 [Documentation] Returns endpoint-groups from a given endpoint
154 [Arguments] ${endpoint}
155 ${endpoint_json} To Json ${endpoint}
156 [Return] ${endpoint_json['endpoint'][0]['endpoint-groups']}
158 Get Groups of Endpoint-L3
159 [Documentation] Returns endpoint-groups from a given endpoint-l3
160 [Arguments] ${endpoint-l3}
161 ${endpoint_json} To Json ${endpoint-l3}
162 [Return] ${endpoint_json['endpoint-l3'][0]['endpoint-groups']}
164 Get L3-Addresses of Endpoint
165 [Documentation] Returns l3-addresses from a given endpoint
166 [Arguments] ${endpoint}
167 ${endpoint_json} To Json ${endpoint}
168 [Return] ${endpoint_json['endpoint'][0]['l3-address']}
170 Get Tenant of Endpoint
171 [Documentation] Returns tenant-id from a given endpoint
172 [Arguments] ${endpoint}
173 ${endpoint_json} To Json ${endpoint}
174 [Return] ${endpoint_json['endpoint'][0]['tenant']}
176 Get Tenant of Endpoint-L3
177 [Documentation] Returns tenant-id from a given endpoint-l3
178 [Arguments] ${endpoint-l3}
179 ${endpoint_json} To Json ${endpoint-l3}
180 [Return] ${endpoint_json['endpoint-l3'][0]['tenant']}
182 Get Network Containment of Endpoint
183 [Documentation] Returns network-containment from a given endpoint
184 [Arguments] ${endpoint}
185 ${endpoint_json} To Json ${endpoint}
186 [Return] ${endpoint_json['endpoint'][0]['network-containment']}
188 Get Network Containment of Endpoint-L3
189 [Documentation] Returns network-containment from a given endpoint-l3
190 [Arguments] ${endpoint-l3}
191 ${endpoint_json} To Json ${endpoint-l3}
192 [Return] ${endpoint_json['endpoint-l3'][0]['network-containment']}
194 Get Mac Address of Endpoint
195 [Documentation] Returns mac-address from a given endpoint
196 [Arguments] ${endpoint}
197 ${endpoint_json} To Json ${endpoint}
198 [Return] ${endpoint_json['endpoint'][0]['mac-address']}
200 Get Mac Address of Endpoint-L3
201 [Documentation] Returns mac-address from a given endpoint-l3
202 [Arguments] ${endpoint-l3}
203 ${endpoint_json} To Json ${endpoint-l3}
204 [Return] ${endpoint_json['endpoint-l3'][0]['mac-address']}
206 Get L2 Context of Endpoint-L3
207 [Documentation] Returns l2-context from a given endpoint-l3
208 [Arguments] ${endpoint-l3}
209 ${endpoint_json} To Json ${endpoint-l3}
210 [Return] ${endpoint_json['endpoint-l3'][0]['l2-context']}