Migrate Get Requests invocations(libraries)
[integration/test.git] / csit / suites / bgpcep / pcepuser / pcepuser.robot
1 *** Settings ***
2 Documentation       Basic tests for odl-bgpcep-pcep-all feature.
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 Library             OperatingSystem
11 Library             SSHLibrary
12 Library             RequestsLibrary
13 Library             ../../../libraries/norm_json.py
14 Resource            ../../../libraries/NexusKeywords.robot
15 Resource            ../../../libraries/PcepOperations.robot
16 Resource            ../../../libraries/Utils.robot
17 Resource            ../../../libraries/RemoteBash.robot
18 Resource            ../../../libraries/TemplatedRequests.robot
19 Resource            ../../../variables/Variables.robot
20 Variables           ../../../variables/pcepuser/${ODL_STREAM}/variables.py    ${TOOLS_SYSTEM_IP}
21
22 Suite Setup         Set_It_Up
23 Suite Teardown      Tear_It_Down
24
25
26 *** Variables ***
27 ${CONFIG_SESSION}           session
28 ${PATH_SESSION_URI}         node=pcc:%2F%2F${TOOLS_SYSTEM_IP}/network-topology-pcep:path-computation-client
29 ${PCEP_VARIABLES_FOLDER}    ${CURDIR}/../../../variables/pcepuser/${ODL_STREAM}
30
31
32 *** Test Cases ***
33 Topology_Precondition
34     [Documentation]    Compare current pcep-topology to off_json variable.
35     ...    Timeout is long enough to ODL boot, to see that pcep is ready, with no PCC is connected.
36     [Tags]    critical
37     Wait_Until_Keyword_Succeeds    300s    1s    Compare_Topology    ${off_json}
38
39 Start_Pcc_Mock
40     [Documentation]    Execute pcc-mock on Mininet, fail is Open is not sent, keep it running for next tests.
41     ${command}=    NexusKeywords.Compose_Full_Java_Command
42     ...    -jar ${filename} --reconnect 1 --local-address ${TOOLS_SYSTEM_IP} --remote-address ${ODL_SYSTEM_IP} 2>&1 | tee pccmock.log
43     Log    ${command}
44     Write    ${command}
45     Read_Until    started, sent proposal Open
46     # Sleep required because of BGPCEP-890
47     Sleep    1s
48
49 Configure_Speaker_Entity_Identifier
50     [Documentation]    Additional PCEP Speaker configuration for at least oxygen streams.
51     ...    Allows PCEP speaker to determine if state synchronization can be skipped when a PCEP session is restarted.
52     &{mapping}=    BuiltIn.Create_Dictionary    IP=${ODL_SYSTEM_IP}
53     TemplatedRequests.Put_As_Xml_Templated
54     ...    ${PCEP_VARIABLES_FOLDER}${/}node_speaker_entity_identifier
55     ...    mapping=${mapping}
56     ...    session=${CONFIG_SESSION}
57
58 Topology_Default
59     [Documentation]    Compare pcep-topology to default_json, which includes a tunnel from pcc-mock.
60     ...    Timeout is lower than in Precondition, as state from pcc-mock should be updated quickly.
61     [Tags]    critical
62     Wait_Until_Keyword_succeeds    10s    1s    Compare_Topology    ${default_json}    ${PATH_SESSION_URI}
63
64 Update_Delegated
65     [Documentation]    Perform update-lsp on the mocked tunnel, check response is success.
66     [Tags]    critical
67     ${text}=    Update_Xml_Lsp_Return_Json    ${update_delegated_xml}
68
69 Topology_Updated
70     [Documentation]    Compare pcep-topology to default_json, which includes the updated tunnel.
71     [Tags]    critical
72     Wait_Until_Keyword_succeeds    10s    1s    Compare_Topology    ${updated_json}    ${PATH_SESSION_URI}
73
74 Refuse_Remove_Delegated
75     [Documentation]    Perform remove-lsp on the mocked tunnel, check that mock-pcc has refused to remove it.
76     [Tags]    critical
77     ${text}=    Remove_Xml_Lsp_Return_Json    ${remove_delegated_xml}
78     Pcep_Json_Is_Refused    ${text}
79
80 Topology_Still_Updated
81     [Documentation]    Compare pcep-topology to default_json, which includes the updated tunnel, to verify that refusal did not break topology.
82     [Tags]    critical
83     Wait_Until_Keyword_succeeds    10s    1s    Compare_Topology    ${updated_json}    ${PATH_SESSION_URI}
84
85 Add_Instantiated
86     [Documentation]    Perform add-lsp to create new tunnel, check that response is success.
87     [Tags]    critical
88     ${text}=    Add_Xml_Lsp_Return_Json    ${add_instantiated_xml}
89
90 Topology_Second_Default
91     [Documentation]    Compare pcep-topology to default_json, which includes the updated delegated and default instantiated tunnel.
92     [Tags]    critical
93     Wait_Until_Keyword_succeeds    10s    1s    Compare_Topology    ${updated_default_json}    ${PATH_SESSION_URI}
94
95 Update_Instantiated
96     [Documentation]    Perform update-lsp on the newly instantiated tunnel, check that response is success.
97     [Tags]    critical
98     ${text}=    Update_Xml_Lsp_Return_Json    ${update_instantiated_xml}
99
100 Topology_Second_Updated
101     [Documentation]    Compare pcep-topology to default_json, which includes the updated delegated and updated instantiated tunnel.
102     [Tags]    critical
103     Wait_Until_Keyword_succeeds    10s    1s    Compare_Topology    ${updated_updated_json}    ${PATH_SESSION_URI}
104
105 Remove_Instantiated
106     [Documentation]    Perform remove-lsp on the instantiated tunnel, check that response is success.
107     [Tags]    critical
108     ${text}=    Remove_Xml_Lsp_Return_Json    ${remove_instantiated_xml}
109
110 Topology_Again_Updated
111     [Documentation]    Compare pcep-topology to default_json, which includes the updated tunnel, to verify that instantiated tunnel was removed.
112     [Tags]    critical
113     Wait_Until_Keyword_succeeds    10s    1s    Compare_Topology    ${updated_json}    ${PATH_SESSION_URI}
114
115 Stop_Pcc_Mock
116     [Documentation]    Send ctrl+c to pcc-mock, fails if no prompt is seen
117     ...    after 3 seconds (the default for SSHLibrary)
118     RemoteBash.Write_Bare_Ctrl_C
119     ${output}=    SSHLibrary.Read_Until_Prompt
120     BuiltIn.Log    ${output}
121
122 Topology_Postcondition
123     [Documentation]    Compare curent pcep-topology to "off_json" again.
124     [Tags]    critical
125     Wait_Until_Keyword_Succeeds    10s    1s    Compare_Topology    ${off_json}
126
127
128 *** Keywords ***
129 Set_It_Up
130     [Documentation]    Create SSH session to Mininet machine, prepare HTTP client session to Controller.
131     ...    Figure out latest pcc-mock version and download it from Nexus to Mininet.
132     NexusKeywords.Initialize_Artifact_Deployment_And_Usage
133     RequestsLibrary.Create_Session    ${CONFIG_SESSION}    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}
134     ${name}=    NexusKeywords.Deploy_Test_Tool    bgpcep    pcep-pcc-mock
135     BuiltIn.Set_Suite_Variable    ${filename}    ${name}
136     PcepOperations.Setup_Pcep_Operations
137
138 Tear_It_Down
139     [Documentation]    Download pccmock.log and Log its contents.
140     ...    Compute and Log the diff between expected and actual normalized responses.
141     ...    Close both HTTP client session and SSH connection to Mininet.
142     SSHLibrary.Get_File    pccmock.log
143     ${pccmocklog}=    OperatingSystem.Run    cat pccmock.log
144     BuiltIn.Log    ${pccmocklog}
145     PcepOperations.Teardown_Pcep_Operations
146     Delete_All_Sessions
147     Close_All_Connections
148
149 Compare_Topology
150     [Documentation]    Get current pcep-topology as json, compare both expected and actual json.
151     ...    Error codes and normalized jsons should match exactly.
152     [Arguments]    ${exp}    ${uri}=${EMPTY}
153     # TODO: Add Node Session State Check For Oxygen, see tcpmd5user
154     # TODO: Possibly remake all tests with TemplatedRequests
155     ${topology_uri}=    BuiltIn.Set_Variable_If
156     ...    '${uri}'=='${EMPTY}'
157     ...    ${REST_API}/${TOPOLOGY_URL}=pcep-topology?content=nonconfig
158     ...    ${REST_API}/${TOPOLOGY_URL}=pcep-topology/${uri}?content=nonconfig
159     ${response}=    RequestsLibrary.GET On Session    ${CONFIG_SESSION}    url=${topology_uri}    expected_status=200
160     TemplatedRequests.Normalize_Jsons_And_Compare    ${exp}    ${response.text}