Switch PrefixCounting to RFC8040
[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 Library           RequestsLibrary
13 Library           norm_json.py
14 Resource          ../variables/Variables.robot
15 Resource          TemplatedRequests.robot
16
17 *** Variables ***
18 ${PCEP_VAR_FOLDER}    ${CURDIR}/../variables/tcpmd5user
19
20 *** Keywords ***
21 Setup_Pcep_Operations
22     [Documentation]    Creates Requests session to be used by subsequent keywords.
23     # Do not append slash at the end uf URL, Requests would add another, resulting in error.
24     Create_Session    pcep_session    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}/restconf/operations    headers=${HEADERS_XML}    auth=${AUTH}
25
26 Teardown_Pcep_Operations
27     [Documentation]    Teardown to pair with Setup (otherwise no-op).
28     Log    TODO: The following line does not seem to be implemented by RequestsLibrary. Look for a workaround.
29     # Delete_Session    pcep_session
30
31 Add_Xml_Lsp_Return_Json
32     [Arguments]    ${xml_data}
33     [Documentation]    Instantiate LSP according to XML data and return response (json) text.
34     # Also no slash here
35     ${response}=    Operate_Xml_Lsp_Return_Json    network-topology-pcep:add-lsp    ${xml_data}
36     [Return]    ${response}
37
38 Update_Xml_Lsp_Return_Json
39     [Arguments]    ${xml_data}
40     [Documentation]    Update LSP according to XML data and return response (json) text.
41     # Also no slash here
42     ${response}=    Operate_Xml_Lsp_Return_Json    network-topology-pcep:update-lsp    ${xml_data}
43     [Return]    ${response}
44
45 Remove_Xml_Lsp_Return_Json
46     [Arguments]    ${xml_data}
47     [Documentation]    Remove LSP according to XML data and return response (json) text.
48     # Also no slash here
49     ${response}=    Operate_Xml_Lsp_Return_Json    network-topology-pcep:remove-lsp    ${xml_data}
50     [Return]    ${response}
51
52 Operate_Xml_Lsp_Return_Json
53     [Arguments]    ${uri_part}    ${xml_data}
54     [Documentation]    Post XML data to given pcep-operations URI, check status_code is 200 and return response text (JSON).
55     ${response}=    RequestsLibrary.Post Request    pcep_session    ${uri_part}    data=${xml_data}
56     Log    ${xml_data}
57     Should Contain    ${ALLOWED_STATUS_CODES}    ${response.status_code}
58     [Return]    ${response.text}
59
60 Pcep_Json_Is_Success
61     [Arguments]    ${text}
62     [Documentation]    Given text should be equal to successfull json response.
63     Should_Be_Equal_As_Strings    ${text}    {"output":{}}
64
65 Pcep_Json_Is_Refused
66     [Arguments]    ${actual_raw}
67     [Documentation]    Given text should be equal to json response when device refuses tunnel removal.
68     ${expected_raw}=    BuiltIn.Set_Variable    {"output":{"error":[{"error-object":{"ignore":false,"processing-rule":false,"type":19,"value":9}}],"failure":"failed"}}
69     # TODO: Is that JSON worth referencing pcepuser variables from this library?
70     ${expected_normalized}=    norm_json.normalize_json_text    ${expected_raw}
71     ${actual_normalized}=    norm_json.normalize_json_text    ${actual_raw}
72     BuiltIn.Should_Be_Equal    ${actual_normalized}    ${expected_normalized}
73     # TODO: Would the diff approach be more useful?
74
75 Pcep_Topology_Precondition
76     [Arguments]    ${session}
77     [Documentation]    Compare current pcep-topology to empty one.
78     ...    Timeout is long enough to see that pcep is ready.
79     BuiltIn.Wait_Until_Keyword_Succeeds    300s    1s    TemplatedRequests.Get_As_Json_Templated    ${PCEP_VAR_FOLDER}/default_off    session=${session}    verify=True