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