Adding option to specify headers in Utils
[integration/test.git] / csit / libraries / GBP / RestconfUtils.robot
1 *** Settings ***
2 Documentation     Utils for Restconf operations for GBP
3 Library           RequestsLibrary
4 Library           OperatingSystem
5 Library           json
6 Variables         ../../variables/Variables.py
7 Resource          ../Utils.robot
8
9 *** Variables ***
10 ${ENDPOINT_UNREG_PATH}    ${GBP_UNREGEP_API}
11 ${ENDPOINTS_OPER_PATH}    /restconf/operational/endpoint:endpoints
12
13 *** Keywords ***
14 Unregister Endpoints
15     [Documentation]    Unregister Endpoints Endpoints from ODL
16     ${result} =    RequestsLibrary.Get    session    ${ENDPOINTS_OPER_PATH}
17     ${json_result} =    json.loads    ${result.text}
18     Pass Execution If    ${json_result['endpoints']}=={}    No Endpoints available
19     ${L2_ENDPOINTS} =    Set Variable    ${json_result['endpoints']['endpoint']}
20     ${L3_ENDPOINTS} =    Set Variable    ${json_result['endpoints']['endpoint-l3']}
21     Log    ${L2_ENDPOINTS}
22     Unregister L2Endpoints    ${L2_ENDPOINTS}
23     Log    ${L3_ENDPOINTS}
24     Unregister L3Endpoints    ${L3_ENDPOINTS}
25     ${result} =    RequestsLibrary.Get    session    ${ENDPOINTS_OPER_PATH}
26     ${json_result} =    json.loads    ${result.text}
27     Should Be Empty    ${json_result['endpoints']}
28
29 Unregister L2Endpoints
30     [Arguments]    ${l2_eps}
31     [Documentation]    Unregister Endpoints L2Endpoints from ODL
32     : FOR    ${endpoint}    IN    @{l2_eps}
33     \    ${l2_data} =    Create L2 Endpoint JSON Data    ${endpoint}
34     \    Post Elements To URI    ${ENDPOINT_UNREG_PATH}    ${l2_data}    ${HEADERS_YANG_JSON}
35
36 Unregister L3Endpoints
37     [Arguments]    ${l3_eps}
38     [Documentation]    Unregister Endpoints L3Endpoints from ODL
39     : FOR    ${endpoint}    IN    @{l3_eps}
40     \    ${l3_data} =    Create L3 Endpoint JSON Data    ${endpoint}
41     \    Post Elements To URI    ${ENDPOINT_UNREG_PATH}    ${l3_data}    ${HEADERS_YANG_JSON}
42
43 Create L2 Endpoint JSON Data
44     [Arguments]    ${endpoint}
45     [Documentation]    Generate the JSON data required for unregistering L2 Endpoints
46     ${data}    Set Variable    {"input": {"l2": [{"mac-address": "${endpoint['mac-address']}", "l2-context": "${endpoint['l2-context']}"}]}}
47     [Return]    ${data}
48
49 Create L3 Endpoint JSON Data
50     [Arguments]    ${endpoint}
51     [Documentation]    Generate the JSON data required for unregistering L3 Endpoints
52     ${data}    Set Variable    {"input": {"l3": [{"l3-context": "${endpoint['l3-context']}", "ip-address": "${endpoint['ip-address']}"}]}}
53     [Return]    ${data}