Migrate Get Requests invocations(libraries)
[integration/test.git] / csit / libraries / PcepOperations.robot
1 *** Settings ***
2 Documentation       Robot keyword library (Resource) for performing PCEP operations via restconf calls.
3 ...
4 ...                 Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
5 ...
6 ...                 This program and the accompanying materials are made available under the
7 ...                 terms of the Eclipse Public License v1.0 which accompanies this distribution,
8 ...                 and is available at http://www.eclipse.org/legal/epl-v10.html
9 ...
10 ...                 TODO: Remove all old keywords, update pcepuser.robot accordingly
11 ...                 TODO: Add new KWs, update all pcep tests to use them.
12
13 Library             RequestsLibrary
14 Library             norm_json.py
15 Resource            ../variables/Variables.robot
16 Resource            TemplatedRequests.robot
17
18
19 *** Variables ***
20 ${PCEP_VAR_FOLDER}      ${CURDIR}/../variables/tcpmd5user
21
22
23 *** Keywords ***
24 Setup_Pcep_Operations
25     [Documentation]    Creates Requests session to be used by subsequent keywords.
26     RequestsLibrary.Create_Session
27     ...    pcep_session
28     ...    url=http://${ODL_SYSTEM_IP}:${RESTCONFPORT}
29     ...    headers=${HEADERS_XML}
30     ...    auth=${AUTH}
31
32 Teardown_Pcep_Operations
33     [Documentation]    Teardown to pair with Setup (otherwise no-op).
34     RequestsLibrary.Delete_All_Sessions
35
36 Add_Xml_Lsp_Return_Json
37     [Documentation]    Instantiate LSP according to XML data and return response (json) text.
38     [Arguments]    ${xml_data}
39     # Also no slash here
40     ${response}=    Operate_Xml_Lsp_Return_Json    network-topology-pcep:add-lsp    ${xml_data}
41     RETURN    ${response}
42
43 Update_Xml_Lsp_Return_Json
44     [Documentation]    Update LSP according to XML data and return response (json) text.
45     [Arguments]    ${xml_data}
46     # Also no slash here
47     ${response}=    Operate_Xml_Lsp_Return_Json    network-topology-pcep:update-lsp    ${xml_data}
48     RETURN    ${response}
49
50 Remove_Xml_Lsp_Return_Json
51     [Documentation]    Remove LSP according to XML data and return response (json) text.
52     [Arguments]    ${xml_data}
53     # Also no slash here
54     ${response}=    Operate_Xml_Lsp_Return_Json    network-topology-pcep:remove-lsp    ${xml_data}
55     RETURN    ${response}
56
57 Operate_Xml_Lsp_Return_Json
58     [Documentation]    Post XML data to given pcep-operations URI, check status_code is 200 and return response text (JSON).
59     [Arguments]    ${uri_part}    ${xml_data}
60     ${uri_path}=    BuiltIn.Set_Variable    /rests/operations/${uri_part}
61     ${response}=    RequestsLibrary.POST On Session
62     ...    pcep_session
63     ...    url=${uri_path}
64     ...    data=${xml_data}
65     ...    expected_status=anything
66     Log    ${xml_data}
67     Should Contain    ${ALLOWED_STATUS_CODES}    ${response.status_code}
68     RETURN    ${response.text}
69
70 Pcep_Json_Is_Success
71     [Documentation]    Given text should be equal to successfull json response.
72     [Arguments]    ${text}
73     Should_Be_Equal_As_Strings    ${text}    {"output":{}}
74
75 Pcep_Json_Is_Refused
76     [Documentation]    Given text should be equal to json response when device refuses tunnel removal.
77     [Arguments]    ${actual_raw}
78     ${expected_raw}=    BuiltIn.Set_Variable
79     ...    {"network-topology-pcep:output":{"error":[{"error-object":{"ignore":false,"processing-rule":false,"type":19,"value":9}}],"failure":"failed"}}
80     # TODO: Is that JSON worth referencing pcepuser variables from this library?
81     ${expected_normalized}=    norm_json.normalize_json_text    ${expected_raw}
82     ${actual_normalized}=    norm_json.normalize_json_text    ${actual_raw}
83     BuiltIn.Should_Be_Equal    ${actual_normalized}    ${expected_normalized}
84     # TODO: Would the diff approach be more useful?
85
86 Pcep_Topology_Precondition
87     [Documentation]    Compare current pcep-topology to empty one.
88     ...    Timeout is long enough to see that pcep is ready.
89     [Arguments]    ${session}
90     BuiltIn.Wait_Until_Keyword_Succeeds
91     ...    300s
92     ...    1s
93     ...    TemplatedRequests.Get_As_Json_Templated
94     ...    ${PCEP_VAR_FOLDER}/default_off
95     ...    session=${session}
96     ...    verify=True