Migrate Get Requests invocations(libraries)
[integration/test.git] / csit / suites / bgpcep / tcpmd5user / tcpmd5user.robot
1 *** Settings ***
2 Documentation       TCPMD5 user-facing feature system tests, using PCEP.
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 ...                 Test suite performs basic pcep md5 password authorization test cases:
11 ...                 (Run entire basic PCEP suite without passwords.)
12 ...                 Start pcc-mock (reconnecting mode): 1 pcc, 1 lsp, password set, check pcep-topology stays empty.
13 ...                 Use restconf to change PCEP configuration to use a wrong password, check pcep-topology stays empty.
14 ...                 Change ODL PCEP configuration to use the correct password, check pcep-topology shows the lsp.
15 ...                 Stop pcc-mock, check pcep-topology stays empty.
16 ...                 Start pcc-mock with new password, check pcep-topology stays empty.
17 ...                 Change ODL PCEP configuration to use the correct password, check pcep-topology shows the lsp.
18 ...                 Update the lsp, check a change in pcep-topology.
19 ...                 Change ODL PCEP configuration to not use password, pcep-topology empties, kill pcep-pcc-mock.
20 ...
21 ...                 Test cases no longer need netconf-connector-ssh, and they include comparison of
22 ...                 pcep-session-state.
23
24 Library             OperatingSystem
25 Library             RequestsLibrary
26 Library             SSHLibrary    prompt=]>
27 Resource            ../../../libraries/FailFast.robot
28 Resource            ../../../libraries/KarafKeywords.robot
29 Resource            ../../../libraries/NexusKeywords.robot
30 Resource            ../../../libraries/TemplatedRequests.robot
31 Resource            ../../../libraries/RemoteBash.robot
32 Resource            ../../../libraries/WaitForFailure.robot
33 Resource            ../../../variables/Variables.robot
34 Variables           ../../../variables/tcpmd5user/${ODL_STREAM}/variables.py    ${TOOLS_SYSTEM_IP}
35
36 Suite Setup         Set_It_Up
37 Suite Teardown      Tear_It_Down
38 Test Setup          FailFast.Fail_This_Fast_On_Previous_Error
39 Test Teardown       FailFast.Start_Failing_Fast_If_This_Failed
40
41
42 *** Variables ***
43 ${DIR_WITH_TEMPLATES}       ${CURDIR}/../../../variables/tcpmd5user/${ODL_STREAM}
44 ${CONFIG_SESSION}           session
45 ${ERROR_ARGS}               ${EMPTY}
46
47
48 *** Test Cases ***
49 Topology_Precondition
50     [Documentation]    Compare current pcep-topology to empty one.
51     ...    Timeout is long enough to see that pcep is ready, with no PCC connected.
52     [Tags]    critical
53     BuiltIn.Wait_Until_Keyword_Succeeds
54     ...    300s
55     ...    1s
56     ...    TemplatedRequests.Get_As_Json_Templated
57     ...    ${DIR_WITH_TEMPLATES}${/}default_off
58     ...    session=${CONFIG_SESSION}
59     ...    verify=True
60
61 Start_Secure_Pcc_Mock
62     [Documentation]    Execute pcc-mock on Mininet with password set, fail if pcc-mock promptly exits. Keep pcc-mock running for next test cases.
63     Start_Pcc_Mock_Tool_With_Password    password=topsecret
64
65 Topology_Unauthorized_1
66     [Documentation]    Try to catch a glimpse of pcc-mock in pcep-topology. Pass if no change from Precondition is detected over 10 seconds.
67     [Tags]    critical
68     WaitForFailure.Verify_Keyword_Does_Not_Fail_Within_Timeout    10s    1s    Test_Unauthorized
69
70 Set_Wrong_Password
71     [Documentation]    Configure password in pcep dispatcher for client with Mininet IP address.
72     ...    This password does not match what pcc-mock uses.
73     Replace_Password_On_Pcep_Node    password=changeme
74
75 Topology_Unauthorized_2
76     [Documentation]    The same logic as Topology_Unauthorized_1 as incorrect password was provided to ODL.
77     [Tags]    critical
78     WaitForFailure.Verify_Keyword_Does_Not_Fail_Within_Timeout    10s    1s    Test_Unauthorized
79
80 Set_Correct_Password
81     [Documentation]    Configure password in pcep dispatcher for client with Mininet IP address.
82     ...    This password finally matches what pcc-mock uses.
83     Replace_Password_On_Pcep_Node    password=topsecret
84
85 Topology_Intercondition
86     [Documentation]    Compare pcep-topology/path-computation-client to filled one, which includes a tunnel from pcc-mock.
87     &{mapping}    BuiltIn.Create_Dictionary
88     ...    IP=${TOOLS_SYSTEM_IP}
89     ...    CODE=${pcc_name_code}
90     ...    NAME=${pcc_name}
91     ...    IP_ODL=${ODL_SYSTEM_IP}
92     ...    ERRORS=${ERROR_ARGS}
93     BuiltIn.Wait_Until_Keyword_Succeeds
94     ...    30s
95     ...    1s
96     ...    TemplatedRequests.Get_As_Json_Templated
97     ...    ${DIR_WITH_TEMPLATES}${/}default_on_state
98     ...    ${mapping}
99     ...    ${CONFIG_SESSION}
100     ...    verify=True
101
102 Stop_Pcc_Mock_1
103     [Documentation]    Stops First instance of pcc-mock.
104     [Setup]    FailFast.Run_Even_When_Failing_Fast
105     Stop_Pcc_Mock_Tool
106     FailFast.Do_Not_Fail_Fast_From_Now_On
107     # NOTE: It is still possible to remain failing, if both previous and this test failed.
108     [Teardown]    FailFast.Do_Not_Start_Failing_If_This_Failed
109
110 Topology_Unauthorized_3
111     [Documentation]    The same logic as Topology_Unauthorized_1, with no pcc-mock running.
112     [Tags]    critical
113     BuiltIn.Wait_Until_Keyword_Succeeds    10s    1s    Test_Unauthorized
114
115 Start_Secure_Pcc_Mock_2
116     [Documentation]    Execute pcc-mock on Mininet with new password set, fail if pcc-mock promptly exits. Keep pcc-mock running for next test cases.
117     Start_Pcc_Mock_Tool_With_Password    password=newtopsecret
118
119 Topology_Unauthorized_4
120     [Documentation]    The same logic as Topology_Unauthorized_1, but ODL password became incorrect with new pcc-mock running.
121     [Tags]    critical
122     WaitForFailure.Verify_Keyword_Does_Not_Fail_Within_Timeout    10s    1s    Test_Unauthorized
123
124 Set_Correct_Password_2
125     [Documentation]    Configure password in pcep dispatcher for client with Mininet IP address.
126     ...    This password again matches what second pcc-mock instance uses.
127     Replace_Password_On_Pcep_Node    password=newtopsecret
128
129 Topology_Intercondition_2
130     [Documentation]    Compare pcep-topology/path-computation-client to filled one, which includes a tunnel from pcc-mock.
131     &{mapping}    BuiltIn.Create_Dictionary
132     ...    IP=${TOOLS_SYSTEM_IP}
133     ...    CODE=${pcc_name_code}
134     ...    NAME=${pcc_name}
135     ...    IP_ODL=${ODL_SYSTEM_IP}
136     ...    ERRORS=${ERROR_ARGS}
137     BuiltIn.Wait_Until_Keyword_Succeeds
138     ...    30s
139     ...    1s
140     ...    TemplatedRequests.Get_As_Json_Templated
141     ...    ${DIR_WITH_TEMPLATES}${/}default_on_state
142     ...    ${mapping}
143     ...    ${CONFIG_SESSION}
144     ...    verify=True
145
146 Update_Delegated
147     [Documentation]    Perform update-lsp on the mocked tunnel, check response is success.
148     &{mapping}    BuiltIn.Create_Dictionary    IP=${TOOLS_SYSTEM_IP}    NAME=${pcc_name}
149     ${response}    TemplatedRequests.Post_As_Xml_Templated
150     ...    ${DIR_WITH_TEMPLATES}${/}update_delegated
151     ...    ${mapping}
152     ...    ${CONFIG_SESSION}
153     ...    verify=False
154     Log    ${response}
155
156 Topology_Updated
157     [Documentation]    Compare pcep-topology/path-computation-client to default_on_updated, which includes the updated tunnel.
158     [Tags]    critical
159     &{mapping}    BuiltIn.Create_Dictionary
160     ...    IP=${TOOLS_SYSTEM_IP}
161     ...    CODE=${pcc_name_code}
162     ...    NAME=${pcc_name}
163     ...    IP_ODL=${ODL_SYSTEM_IP}
164     ...    ERRORS=${ERROR_ARGS}
165     BuiltIn.Wait_Until_Keyword_Succeeds
166     ...    30s
167     ...    1s
168     ...    TemplatedRequests.Get_As_Json_Templated
169     ...    ${DIR_WITH_TEMPLATES}${/}default_on_updated_state
170     ...    ${mapping}
171     ...    ${CONFIG_SESSION}
172     ...    verify=True
173
174 Unset_Password
175     [Documentation]    De-configure password for pcep dispatcher for client with Mininet IP address.
176     [Setup]    FailFast.Run_Even_When_Failing_Fast
177     Unset_Password_On_Pcep_Node
178     FailFast.Do_Not_Fail_Fast_From_Now_On
179     # NOTE: It is still possible to remain failing, if both previous and this test failed.
180     [Teardown]    FailFast.Do_Not_Start_Failing_If_This_Failed
181
182 Topology_Unauthorized_5
183     [Documentation]    Wait for pcep-topology to become empty again.
184     [Tags]    critical
185     BuiltIn.Wait_Until_Keyword_Succeeds    10s    1s    Test_Unauthorized
186
187 Stop_Pcc_Mock_2
188     [Documentation]    Stops second instance of pcc-mock
189     [Setup]    FailFast.Run_Even_When_Failing_Fast
190     Stop_Pcc_Mock_Tool
191     FailFast.Do_Not_Fail_Fast_From_Now_On
192     # NOTE: It is still possible to remain failing, if both previous and this test failed.
193     [Teardown]    FailFast.Do_Not_Start_Failing_If_This_Failed
194
195 Topology_Postcondition
196     [Documentation]    Verify that pcep-topology stays empty.
197     [Tags]    critical
198     WaitForFailure.Verify_Keyword_Does_Not_Fail_Within_Timeout    10s    1s    Test_Unauthorized
199
200 Delete_Pcep_Client_Module
201     [Documentation]    Delete Pcep client module.
202     &{mapping}    BuiltIn.Create_Dictionary    IP=${TOOLS_SYSTEM_IP}
203     TemplatedRequests.Delete_Templated    ${DIR_WITH_TEMPLATES}${/}pcep_topology_node    ${mapping}
204
205
206 *** Keywords ***
207 Set_It_Up
208     [Documentation]    Create SSH session to Mininet machine, prepare HTTP client session to Controller.
209     ...    Figure out latest pcc-mock version and download it from Nexus to Mininet.
210     ...    Also, delete and create directories for json diff handling.
211     KarafKeywords.Setup_Karaf_Keywords
212     TemplatedRequests.Create_Default_Session
213     NexusKeywords.Initialize_Artifact_Deployment_And_Usage
214     ${current_connection}    SSHLibrary.Get_Connection
215     ${current_prompt}    BuiltIn.Set_Variable    ${current_connection.prompt}
216     BuiltIn.Log    ${current_prompt}
217     BuiltIn.Set_Suite_Variable    ${prompt}    ${current_prompt}
218     RequestsLibrary.Create_Session    ${CONFIG_SESSION}    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}
219     ${name}    NexusKeywords.Deploy_Test_Tool    bgpcep    pcep-pcc-mock
220     BuiltIn.Set_Suite_Variable    ${filename}    ${name}
221     #Setting Pcc Name and its code for mapping for templates
222     FailFast.Do_Not_Fail_Fast_From_Now_On
223
224 Tear_It_Down
225     [Documentation]    Download pccmock.log and Log its contents.
226     ...    Compute and Log the diff between expected and actual normalized responses.
227     ...    Close both HTTP client session and SSH connection to Mininet.
228     SSHLibrary.Get_File    pccmock.log
229     ${pccmocklog}    OperatingSystem.Run    cat pccmock.log
230     BuiltIn.Log    ${pccmocklog}
231     RequestsLibrary.Delete_All_Sessions
232     SSHLibrary.Close_All_Connections
233
234 Test_Unauthorized
235     [Documentation]    Try to access pcep topology with wrong password, should get empty topology
236     TemplatedRequests.Get_As_Json_Templated
237     ...    ${DIR_WITH_TEMPLATES}${/}default_off
238     ...    session=${CONFIG_SESSION}
239     ...    verify=True
240
241 Read_Text_Before_Prompt
242     [Documentation]    Log text gathered by SSHLibrary.Read_Until_Prompt.
243     ...    This needs to be a separate keyword just because how Read_And_Fail_If_Prompt_Is_Seen is implemented.
244     ${text}    SSHLibrary.Read_Until_Prompt
245     BuiltIn.Log    ${text}
246
247 Replace_Password_On_Pcep_Node
248     [Documentation]    Send restconf PUT to replace the config module specifying PCEP password element.
249     [Arguments]    ${password}
250     &{mapping}    BuiltIn.Create_Dictionary    IP=${TOOLS_SYSTEM_IP}    PASSWD=${password}
251     TemplatedRequests.Put_As_Xml_Templated    ${DIR_WITH_TEMPLATES}${/}pcep_topology_node    mapping=${mapping}
252
253 Unset_Password_On_Pcep_Node
254     [Documentation]    Send restconf PUT to unset the config module.
255     &{mapping}    BuiltIn.Create_Dictionary    IP=${TOOLS_SYSTEM_IP}
256     TemplatedRequests.Put_As_Xml_Templated    ${DIR_WITH_TEMPLATES}${/}pcep_topology_node_empty    mapping=${mapping}
257
258 Stop_Pcc_Mock_Tool
259     [Documentation]    Send ctrl+c to pcc-mock, fails if no prompt is seen
260     ...    after 3 seconds (the default for SSHLibrary)
261     RemoteBash.Write_Bare_Ctrl_C
262     ${output}    SSHLibrary.Read_Until_Prompt
263     BuiltIn.Log    ${output}
264
265 Start_Pcc_Mock_Tool_With_Password
266     [Documentation]    Starts pcc-mock with password argument.
267     [Arguments]    ${password}
268     ${command}    NexusKeywords.Compose_Full_Java_Command
269     ...    -jar ${filename} --password ${password} --reconnect 1 --local-address ${TOOLS_SYSTEM_IP} --remote-address ${ODL_SYSTEM_IP} 2>&1 | tee pccmock.log
270     BuiltIn.Log    ${command}
271     SSHLibrary.Write    ${command}