Pcepuser fixes: Better handling of prompt and json ordering
[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 Library           RequestsLibrary
10 Library           ${CURDIR}/HsfJson/hsf_json.py
11 Variables         ${CURDIR}/../variables/Variables.py
12
13 *** Keywords ***
14 Setup_Pcep_Operations
15     [Documentation]    Creates Requests session to be used by subsequent keywords.
16     # Do not append slash at the end uf URL, Requests would add another, resulting in error.
17     Create_Session    pcep_session    http://${CONTROLLER}:${RESTCONFPORT}/restconf/operations    headers=${HEADERS_XML}    auth=${AUTH}
18
19 Teardown_Pcep_Operations
20     [Documentation]    Teardown to pair with Setup (otherwise no-op).
21     Log    TODO: The following line does not seem to be implemented by RequestsLibrary. Look for a workaround.
22     # Delete_Session    pcep_session
23
24 Add_Xml_Lsp_Return_Json
25     [Arguments]    ${xml_data}
26     [Documentation]    Instantiate LSP according to XML data and return response (json) text.
27     # Also no slash here
28     ${response}=    Operate_Xml_Lsp_Return_Json    network-topology-pcep:add-lsp    ${xml_data}
29     [Return]    ${response}
30
31 Update_Xml_Lsp_Return_Json
32     [Arguments]    ${xml_data}
33     [Documentation]    Update 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:update-lsp    ${xml_data}
36     [Return]    ${response}
37
38 Remove_Xml_Lsp_Return_Json
39     [Arguments]    ${xml_data}
40     [Documentation]    Remove 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:remove-lsp    ${xml_data}
43     [Return]    ${response}
44
45 Operate_Xml_Lsp_Return_Json
46     [Arguments]    ${uri_part}    ${xml_data}
47     [Documentation]    Post XML data to given pcep-operations URI, check status_code is 200 and return response text (JSON).
48     ${response}=    RequestsLibrary.Post    pcep_session    ${uri_part}    data=${xml_data}
49     Should_Be_Equal_As_Strings    ${response.status_code}    200
50     [Return]    ${response.text}
51
52 Pcep_Json_Is_Success
53     [Arguments]    ${text}
54     [Documentation]    Given text should be equal to successfull json response.
55     Should_Be_Equal_As_Strings    ${text}    {"output":{}}
56
57 Pcep_Json_Is_Refused
58     [Arguments]    ${actual_raw}
59     [Documentation]    Given text should be equal to json response when device refuses tunnel removal.
60     ${expected_raw}=    BuiltIn.Set_Variable    {"output":{"error":[{"error-object":{"ignore":false,"processing-rule":false,"type":19,"value":9}}],"failure":"failed"}}
61     # TODO: Is that JSON worth referencing pcepuser variables from this library?
62     ${expected_normalized}=    hsf_json.hsf_json    ${expected_raw}
63     ${actual_normalized}=    hsf_json.hsf_json    ${actual_raw}
64     BuiltIn.Should_Be_Equal    ${actual_normalized}    ${expected_normalized}
65     # TODO: Would the diff approach be more useful?