Step 2: Move test folder to root
[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 ...
11 ...               The original brief description of this suite is at
12 ...               https://wiki.opendaylight.org/view/TCPMD5:Lithium_Feature_Tests#How_to_test
13 Suite Setup       Set_It_Up
14 Suite Teardown    Tear_It_Down
15 Test Setup        FailFast.Fail_This_Fast_On_Previous_Error
16 Test Teardown     FailFast.Start_Failing_Fast_If_This_Failed
17 Library           OperatingSystem
18 Library           RequestsLibrary
19 Library           SSHLibrary    prompt=]>
20 Library           String
21 Library           ${CURDIR}/../../../libraries/HsfJson/hsf_json.py
22 Resource          ${CURDIR}/../../../libraries/ConfigViaRestconf.robot
23 Resource          ${CURDIR}/../../../libraries/FailFast.robot
24 Resource          ${CURDIR}/../../../libraries/PcepOperations.robot
25 Resource          ${CURDIR}/../../../libraries/WaitForFailure.robot
26 Variables         ${CURDIR}/../../../variables/Variables.py
27 Variables         ${CURDIR}/../../../variables/pcepuser/variables.py    ${MININET}
28
29 *** Variables ***
30 ${directory_for_actual_responses}    ${TEMPDIR}${/}actual
31 ${directory_for_expected_responses}    ${TEMPDIR}${/}expected
32 ${directory_with_template_folders}    ${CURDIR}/../../../variables/tcpmd5user/
33
34 *** Test Cases ***
35 Topology_Precondition
36     [Documentation]    Compare current pcep-topology to empty one.
37     ...    Timeout is long enough to see that pcep is ready, with no PCC is connected.
38     [Tags]    critical
39     BuiltIn.Wait_Until_Keyword_Succeeds    300    1    Compare_Topology    ${off_json}    010_Precondition.json
40
41 Start_Secure_Pcc_Mock
42     [Documentation]    Execute pcc-mock on Mininet with password set, fail if pcc-mock promptly exits. Keep pcc-mock running for next test cases.
43     ${command}=    BuiltIn.Set_Variable    java -jar ${filename} --password topsecret --reconnect 1 --local-address ${MININET} --remote-address ${CONTROLLER} 2>&1 | tee pccmock.log
44     BuiltIn.Log    ${command}
45     SSHLibrary.Write    ${command}
46     Read_And_Fail_If_Prompt_Is_Seen
47
48 Topology_Unauthorized_1
49     [Documentation]    Try to catch a glimpse of pcc-mock in pcep-topology. Pass if no change from Precondition is detected over 1 minute.
50     [Tags]    critical
51     WaitForFailure.Verify_Keyword_Does_Not_Fail_Within_Timeout    10s    1s    Compare_Topology    ${off_json}    020_Unauthorized_1.json
52
53 Enable_Tcpmd5_No_Password_Yet
54     [Documentation]    Send series of restconf puts derived from https://wiki.opendaylight.org/view/BGP_LS_PCEP:TCP_MD5_Guide#RESTCONF_Configuration
55     ...    Every put should return empty text with allwed status code.
56     # No ${mapping_as_string} is given, as there are no placeholders present in the following folders.
57     ConfigViaRestconf.Put_Xml_Template_Folder_Config_Via_Restconf    ${directory_with_template_folders}${/}key_access_module
58     ConfigViaRestconf.Put_Xml_Template_Folder_Config_Via_Restconf    ${directory_with_template_folders}${/}key_access_service
59     ConfigViaRestconf.Put_Xml_Template_Folder_Config_Via_Restconf    ${directory_with_template_folders}${/}md5_client_channel_module
60     ConfigViaRestconf.Put_Xml_Template_Folder_Config_Via_Restconf    ${directory_with_template_folders}${/}md5_client_channel_service
61     ConfigViaRestconf.Put_Xml_Template_Folder_Config_Via_Restconf    ${directory_with_template_folders}${/}md5_server_channel_module
62     ConfigViaRestconf.Put_Xml_Template_Folder_Config_Via_Restconf    ${directory_with_template_folders}${/}md5_server_channel_service
63     ConfigViaRestconf.Put_Xml_Template_Folder_Config_Via_Restconf    ${directory_with_template_folders}${/}pcep_client_channel_module
64     ConfigViaRestconf.Put_Xml_Template_Folder_Config_Via_Restconf    ${directory_with_template_folders}${/}pcep_server_channel_module
65     # TODO: Is it worth changing ConfigViaRestconf to read ${directory_with_template_folders} variable by default?
66
67 Topology_Unauthorized_2
68     [Documentation]    The same logic as Topology_Unauthorized_1 as no password was provided to ODL.
69     [Tags]    critical
70     WaitForFailure.Verify_Keyword_Does_Not_Fail_Within_Timeout    10s    1s    Compare_Topology    ${off_json}    030_Unauthorized_2.json
71
72 Set_Wrong_Password
73     [Documentation]    Configure password in pcep dispatcher for client with Mininet IP address.
74     ...    This password does not match what pcc-mock uses.
75     ${password_line}=    Construct_Password_Element_Line_Using_Password    changeme
76     BuiltIn.Log    ${password_line}
77     Replace_Password_Xml_Element_In_Pcep_Client_Module    ${password_line}
78
79 Topology_Unauthorized_3
80     [Documentation]    The same logic as Topology_Unauthorized_1 as incorrect password was provided to ODL.
81     [Tags]    critical
82     WaitForFailure.Verify_Keyword_Does_Not_Fail_Within_Timeout    10s    1s    Compare_Topology    ${off_json}    040_Unauthorized_3.json
83
84 Set_Correct_Password
85     [Documentation]    Configure password in pcep dispatcher for client with Mininet IP address.
86     ...    This password finally matches what pcc-mock uses.
87     ${password_line}=    Construct_Password_Element_Line_Using_Password    topsecret
88     BuiltIn.Log    ${password_line}
89     Replace_Password_Xml_Element_In_Pcep_Client_Module    ${password_line}
90
91 Topology_Intercondition
92     [Documentation]    Compare pcep-topology to filled one, which includes a tunnel from pcc-mock.
93     [Tags]    xfail
94     BuiltIn.Wait_Until_Keyword_Succeeds    10s    1s    Compare_Topology    ${default_json}    050_Intercondition.json
95
96 Update_Delegated
97     [Documentation]    Perform update-lsp on the mocked tunnel, check response is success.
98     ${text}=    PcepOperations.Update_Xml_Lsp_Return_Json    ${update_delegated_xml}
99     Pcep_Json_Is_Success    ${text}
100
101 Topology_Updated
102     [Documentation]    Compare pcep-topology to default_json, which includes the updated tunnel.
103     [Tags]    critical
104     BuiltIn.Wait_Until_Keyword_succeeds    5s    1s    Compare_Topology    ${updated_json}    060_Topology_Updated.json
105
106 Unset_Password
107     [Documentation]    De-configure password for pcep dispatcher for client with Mininet IP address.
108     [Setup]    FailFast.Run_Even_When_Failing_Fast
109     Replace_Password_Xml_Element_In_Pcep_Client_Module    ${EMPTY}
110     FailFast.Do_Not_Fail_Fast_From_Now_On
111     # NOTE: It is still possible to remain failing, if both previous and this test failed.
112     [Teardown]    FailFast.Do_Not_Start_Failing_If_This_Failed
113
114 Topology_Unauthorized_4
115     [Documentation]    Wait for pcep-topology to become empty again.
116     [Tags]    critical
117     BuiltIn.Wait_Until_Keyword_Succeeds    10s    1s    Compare_Topology    ${offjson}    070_Unauthorized_4.json
118
119 Stop_Pcc_Mock
120     [Documentation]    Send ctrl+c to pcc-mock, fails if no prompt is seen
121     ...    after 3 seconds (the default for SSHLibrary)
122     [Setup]    FailFast.Run_Even_When_Failing_Fast
123     # FIXME: Bgpcepuser has Write_Ctrl_C keyword. Re-use it.
124     ${command}=    BuiltIn.Evaluate    chr(int(3))
125     BuiltIn.Log    ${command}
126     SSHLibrary.Write    ${command}
127     SSHLibrary.Read_Until_Prompt
128     FailFast.Do_Not_Fail_Fast_From_Now_On
129     # NOTE: It is still possible to remain failing, if both previous and this test failed.
130     [Teardown]    FailFast.Do_Not_Start_Failing_If_This_Failed
131
132 Topology_Postcondition
133     [Documentation]    Verify that pcep-topology stays empty.
134     [Tags]    critical
135     WaitForFailure.Verify_Keyword_Does_Not_Fail_Within_Timeout    10    1    Compare_Topology    ${offjson}    080_Postcondition.json
136     # FIXME: We should delete config changes to not affect next suite.
137
138 *** Keywords ***
139 Set_It_Up
140     [Documentation]    Create SSH session to Mininet machine, prepare HTTP client session to Controller.
141     ...    Figure out latest pcc-mock version and download it from Nexus to Mininet.
142     ...    Also, delete and create directories for json diff handling.
143     SSHLibrary.Open_Connection    ${MININET}
144     SSHLibrary.Login_With_Public_Key    ${MININET_USER}    ${USER_HOME}/.ssh/${SSH_KEY}    any
145     ${current_connection}=    SSHLibrary.Get_Connection
146     ${current_prompt}=    BuiltIn.Set_Variable    ${current_connection.prompt}
147     BuiltIn.Log    ${current_prompt}
148     BuiltIn.Set_Suite_Variable    ${prompt}    ${current_prompt}
149     RequestsLibrary.Create_Session    ses    http://${CONTROLLER}:${RESTCONFPORT}${OPERATIONAL_TOPO_API}    auth=${AUTH}
150     # TODO: See corresponding bgpuser TODO.
151     ${urlbase}=    BuiltIn.Set_Variable    ${NEXUSURL_PREFIX}/content/repositories/opendaylight.snapshot/org/opendaylight/bgpcep/pcep-pcc-mock
152     ${version}=    SSHLibrary.Execute_Command    curl ${urlbase}/maven-metadata.xml | grep latest | cut -d '>' -f 2 | cut -d '<' -f 1
153     # TODO: Use RequestsLibrary and String instead of curl and bash utilities?
154     BuiltIn.Log    ${version}
155     ${namepart}=    SSHLibrary.Execute_Command    curl ${urlbase}/${version}/maven-metadata.xml | grep value | head -n 1 | cut -d '>' -f 2 | cut -d '<' -f 1
156     BuiltIn.Log    ${namepart}
157     BuiltIn.Set_Suite_Variable    ${filename}    pcep-pcc-mock-${namepart}-executable.jar
158     BuiltIn.Log    ${filename}
159     ${response}=    SSHLibrary.Execute_Command    wget -q -N ${urlbase}/${version}/${filename} 2>&1
160     BuiltIn.Log    ${response}
161     OperatingSystem.Remove_Directory    ${directory_for_expected_responses}    recursive=True
162     OperatingSystem.Remove_Directory    ${directory_for_actual_responses}    recursive=True
163     # The previous suite may have been using the same directories.
164     OperatingSystem.Create_Directory    ${directory_for_expected_responses}
165     OperatingSystem.Create_Directory    ${directory_for_actual_responses}
166     ConfigViaRestconf.Setup_Config_Via_Restconf
167     PcepOperations.Setup_Pcep_Operations
168     FailFast.Do_Not_Fail_Fast_From_Now_On
169
170 Tear_It_Down
171     [Documentation]    Download pccmock.log and Log its contents.
172     ...    Compute and Log the diff between expected and actual normalized responses.
173     ...    Close both HTTP client session and SSH connection to Mininet.
174     SSHLibrary.Get_File    pccmock.log
175     ${pccmocklog}=    OperatingSystem.Run    cat pccmock.log
176     BuiltIn.Log    ${pccmocklog}
177     ${diff}=    OperatingSystem.Run    diff -dur ${directory_for_expected_responses} ${directory_for_actual_responses}
178     BuiltIn.Log    ${diff}
179     PcepOperations.Teardown_Pcep_Operations
180     ConfigViaRestconf.Teardown_Config_Via_Restconf
181     RequestsLibrary.Delete_All_Sessions
182     SSHLibrary.Close_All_Connections
183
184 Read_And_Fail_If_Prompt_Is_Seen
185     [Documentation]    Try to read SSH to see prompt, but expect to see no prompt within SSHLibrary's timeout.
186     BuiltIn.Run_Keyword_And_Expect_Error    No match found for '${prompt}' in *.    Read_Text_Before_Prompt
187
188 Read_Text_Before_Prompt
189     [Documentation]    Log text gathered by SSHLibrary.Read_Until_Prompt.
190     ...    This needs to be a separate keyword just because how Read_And_Fail_If_Prompt_Is_Seen is implemented.
191     ${text}=    SSHLibrary.Read_Until_Prompt
192     BuiltIn.Log    ${text}
193
194 Compare_Topology
195     [Arguments]    ${expected}    ${name}
196     [Documentation]    Get current pcep-topology as json, normalize both expected and actual json.
197     ...    Save normalized jsons to files for later processing.
198     ...    Error codes and normalized jsons should match exactly.
199     # FIXME: See bgpuser to move handling of expected outside WUKS loop, as in bgpuser suite.
200     ${normexp}=    hsf_json.Hsf_Json    ${expected}
201     BuiltIn.Log    ${normexp}
202     OperatingSystem.Create_File    ${directory_for_expected_responses}${/}${name}    ${normexp}
203     ${resp}=    RequestsLibrary.Get_Request    ses    topology/pcep-topology
204     BuiltIn.Log    ${resp}
205     BuiltIn.Log    ${resp.text}
206     ${normresp}=    hsf_json.Hsf_Json    ${resp.text}
207     BuiltIn.Log    ${normresp}
208     OperatingSystem.Create_File    ${directory_for_actual_responses}${/}${name}    ${normresp}
209     BuiltIn.Should_Be_Equal_As_Strings    ${resp.status_code}    200
210     BuiltIn.Should_Be_Equal    ${normresp}    ${normexp}
211
212 Construct_Password_Element_Line_Using_Password
213     [Arguments]    ${password}
214     [Documentation]    Return line with password XML element containing given password, whitespace is there so that data to send looks neat.
215     ${element}=    String.Replace_String    ${SPACE}${SPACE}<password>$PASSWORD</password>${\n}    $PASSWORD    ${password}
216     BuiltIn.Log    ${element}
217     [Return]    ${element}
218
219 Replace_Password_Xml_Element_In_Pcep_Client_Module
220     [Arguments]    ${password_element}
221     [Documentation]    Send restconf PUT to replace the config module specifying PCEP password element (may me empty=missing).
222     ${mapping_as_string}=    BuiltIn.Set_Variable    {'IP': '${MININET}', 'PASSWD': '''${password_element}'''}
223     BuiltIn.Log    ${mapping_as_string}
224     ConfigViaRestconf.Put_Xml_Template_Folder_Config_Via_Restconf    ${directory_with_template_folders}${/}pcep_topology_client_module    ${mapping_as_string}