Clean up PcepOperations
[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     # Do not append slash at the end uf URL, Requests would add another, resulting in error.
27     Create_Session
28     ...    pcep_session
29     ...    url=http://${ODL_SYSTEM_IP}:${RESTCONFPORT}/rests/operations/
30     ...    headers=${HEADERS_XML}
31     ...    auth=${AUTH}
32
33 Teardown_Pcep_Operations
34     [Documentation]    Teardown to pair with Setup (otherwise no-op).
35     Log    TODO: The following line does not seem to be implemented by RequestsLibrary. Look for a workaround.
36     # Delete_Session    pcep_session
37
38 Add_Xml_Lsp_Return_Json
39     [Documentation]    Instantiate LSP according to XML data and return response (json) text.
40     [Arguments]    ${xml_data}
41     # Also no slash here
42     ${response}=    Operate_Xml_Lsp_Return_Json    network-topology-pcep:add-lsp    ${xml_data}
43     RETURN    ${response}
44
45 Update_Xml_Lsp_Return_Json
46     [Documentation]    Update LSP according to XML data and return response (json) text.
47     [Arguments]    ${xml_data}
48     # Also no slash here
49     ${response}=    Operate_Xml_Lsp_Return_Json    network-topology-pcep:update-lsp    ${xml_data}
50     RETURN    ${response}
51
52 Remove_Xml_Lsp_Return_Json
53     [Documentation]    Remove LSP according to XML data and return response (json) text.
54     [Arguments]    ${xml_data}
55     # Also no slash here
56     ${response}=    Operate_Xml_Lsp_Return_Json    network-topology-pcep:remove-lsp    ${xml_data}
57     RETURN    ${response}
58
59 Operate_Xml_Lsp_Return_Json
60     [Documentation]    Post XML data to given pcep-operations URI, check status_code is 200 and return response text (JSON).
61     [Arguments]    ${uri_part}    ${xml_data}
62     ${response}=    RequestsLibrary.POST On Session    pcep_session    uri=${uri_part}    data=${xml_data}    expect_status=any
63     Log    ${xml_data}
64     Should Contain    ${ALLOWED_STATUS_CODES}    ${response.status_code}
65     RETURN    ${response.text}
66
67 Pcep_Json_Is_Success
68     [Documentation]    Given text should be equal to successfull json response.
69     [Arguments]    ${text}
70     Should_Be_Equal_As_Strings    ${text}    {"output":{}}
71
72 Pcep_Json_Is_Refused
73     [Documentation]    Given text should be equal to json response when device refuses tunnel removal.
74     [Arguments]    ${actual_raw}
75     ${expected_raw}=    BuiltIn.Set_Variable
76     ...    {"network-topology-pcep:output":{"error":[{"error-object":{"ignore":false,"processing-rule":false,"type":19,"value":9}}],"failure":"failed"}}
77     # TODO: Is that JSON worth referencing pcepuser variables from this library?
78     ${expected_normalized}=    norm_json.normalize_json_text    ${expected_raw}
79     ${actual_normalized}=    norm_json.normalize_json_text    ${actual_raw}
80     BuiltIn.Should_Be_Equal    ${actual_normalized}    ${expected_normalized}
81     # TODO: Would the diff approach be more useful?
82
83 Pcep_Topology_Precondition
84     [Documentation]    Compare current pcep-topology to empty one.
85     ...    Timeout is long enough to see that pcep is ready.
86     [Arguments]    ${session}
87     BuiltIn.Wait_Until_Keyword_Succeeds
88     ...    300s
89     ...    1s
90     ...    TemplatedRequests.Get_As_Json_Templated
91     ...    ${PCEP_VAR_FOLDER}/default_off
92     ...    session=${session}
93     ...    verify=True