Step 1: Move vm scripts to the right place
[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 Variables         ${CURDIR}/../variables/Variables.py
11
12 *** Keywords ***
13 Setup_Pcep_Operations
14     [Documentation]    Creates Requests session to be used by subsequent keywords.
15     # Do not append slash at the end uf URL, Requests would add another, resulting in error.
16     Create_Session    pcep_session    http://${CONTROLLER}:${RESTCONFPORT}/restconf/operations    headers=${HEADERS_XML}    auth=${AUTH}
17
18 Teardown_Pcep_Operations
19     [Documentation]    Teardown to pair with Setup (otherwise no-op).
20     Log    TODO: The following line does not seem to be implemented by RequestsLibrary. Look for a workaround.
21     # Delete_Session    pcep_session
22
23 Add_Xml_Lsp_Return_Json
24     [Arguments]    ${xml_data}
25     [Documentation]    Instantiate LSP according to XML data and return response (json) text.
26     # Also no slash here
27     ${response}=    Operate_Xml_Lsp_Return_Json    network-topology-pcep:add-lsp    ${xml_data}
28     [Return]    ${response}
29
30 Update_Xml_Lsp_Return_Json
31     [Arguments]    ${xml_data}
32     [Documentation]    Update LSP according to XML data and return response (json) text.
33     # Also no slash here
34     ${response}=    Operate_Xml_Lsp_Return_Json    network-topology-pcep:update-lsp    ${xml_data}
35     [Return]    ${response}
36
37 Remove_Xml_Lsp_Return_Json
38     [Arguments]    ${xml_data}
39     [Documentation]    Remove LSP according to XML data and return response (json) text.
40     # Also no slash here
41     ${response}=    Operate_Xml_Lsp_Return_Json    network-topology-pcep:remove-lsp    ${xml_data}
42     [Return]    ${response}
43
44 Operate_Xml_Lsp_Return_Json
45     [Arguments]    ${uri_part}    ${xml_data}
46     [Documentation]    Post XML data to given pcep-operations URI, check status_code is 200 and return response text (JSON).
47     ${response}=    RequestsLibrary.Post    pcep_session    ${uri_part}    data=${xml_data}
48     Should_Be_Equal_As_Strings    ${response.status_code}    200
49     [Return]    ${response.text}
50
51 Pcep_Json_Is_Success
52     [Arguments]    ${text}
53     [Documentation]    Given text should be equal to successfull json response.
54     Should_Be_Equal_As_Strings    ${text}    {"output":{}}
55
56 Pcep_Json_Is_Refused
57     [Arguments]    ${text}
58     [Documentation]    Given text should be equal to json response when device refuses tunnel removal.
59     # FIXME: We probably should normalize text as json (and by that, test whether it is a json at all).
60     Should_Be_Equal_As_Strings    ${text}    {"output":{"error":[{"error-object":{"ignore":false,"processing-rule":false,"type":19,"value":9}}],"failure":"failed"}}