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