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