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