Fix BGPCEP TCPMD5 tests
[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/norm_json.py
22 Resource          ${CURDIR}/../../../libraries/FailFast.robot
23 Resource          ${CURDIR}/../../../libraries/KarafKeywords.robot
24 Resource          ${CURDIR}/../../../libraries/NexusKeywords.robot
25 Resource          ${CURDIR}/../../../libraries/PcepOperations.robot
26 Resource          ${CURDIR}/../../../libraries/TemplatedRequests.robot
27 Resource          ${CURDIR}/../../../libraries/WaitForFailure.robot
28 Variables         ${CURDIR}/../../../variables/Variables.py
29 Variables         ${CURDIR}/../../../variables/pcepuser/variables.py    ${TOOLS_SYSTEM_IP}
30
31 *** Variables ***
32 ${directory_for_actual_responses}    ${TEMPDIR}${/}actual
33 ${directory_for_expected_responses}    ${TEMPDIR}${/}expected
34 ${directory_with_template_folders}    ${CURDIR}/../../../variables/tcpmd5user/
35 ${CONNECTOR_FEATURE}    odl-netconf-connector-all
36 ${PCEP_FEATURE}    odl-bgpcep-pcep
37 ${RESTCONF_FEATURE}    odl-restconf-all
38
39 *** Test Cases ***
40 Topology_Precondition
41     [Documentation]    Compare current pcep-topology to empty one.
42     ...    Timeout is long enough to see that pcep is ready, with no PCC is connected.
43     [Tags]    critical
44     BuiltIn.Wait_Until_Keyword_Succeeds    300    1    Compare_Topology    ${off_json}    010_Precondition.json
45
46 Start_Secure_Pcc_Mock
47     [Documentation]    Execute pcc-mock on Mininet with password set, fail if pcc-mock promptly exits. Keep pcc-mock running for next test cases.
48     ${command}=    NexusKeywords.Compose_Full_Java_Command    -jar ${filename} --password topsecret --reconnect 1 --local-address ${TOOLS_SYSTEM_IP} --remote-address ${ODL_SYSTEM_IP} 2>&1 | tee pccmock.log
49     BuiltIn.Log    ${command}
50     SSHLibrary.Write    ${command}
51     Read_And_Fail_If_Prompt_Is_Seen
52
53 Topology_Unauthorized_1
54     [Documentation]    Try to catch a glimpse of pcc-mock in pcep-topology. Pass if no change from Precondition is detected over 1 minute.
55     [Tags]    critical
56     WaitForFailure.Verify_Keyword_Does_Not_Fail_Within_Timeout    10s    1s    Compare_Topology    ${off_json}    020_Unauthorized_1.json
57
58 Set_Wrong_Password
59     [Documentation]    Configure password in pcep dispatcher for client with Mininet IP address.
60     ...    This password does not match what pcc-mock uses.
61     ${password_line}=    Construct_Password_Element_Line_Using_Password    changeme
62     BuiltIn.Log    ${password_line}
63     Replace_Password_Xml_Element_In_Pcep_Client_Module    ${password_line}
64
65 Topology_Unauthorized_2
66     [Documentation]    The same logic as Topology_Unauthorized_1 as incorrect password was provided to ODL.
67     [Tags]    critical
68     WaitForFailure.Verify_Keyword_Does_Not_Fail_Within_Timeout    10s    1s    Compare_Topology    ${off_json}    040_Unauthorized_3.json
69
70 Set_Correct_Password
71     [Documentation]    Configure password in pcep dispatcher for client with Mininet IP address.
72     ...    This password finally matches what pcc-mock uses.
73     ${password_line}=    Construct_Password_Element_Line_Using_Password    topsecret
74     BuiltIn.Log    ${password_line}
75     Replace_Password_Xml_Element_In_Pcep_Client_Module    ${password_line}
76
77 Topology_Intercondition
78     [Documentation]    Compare pcep-topology to filled one, which includes a tunnel from pcc-mock.
79     BuiltIn.Wait_Until_Keyword_Succeeds    10s    1s    Compare_Topology    ${default_json}    050_Intercondition.json
80
81 Update_Delegated
82     [Documentation]    Perform update-lsp on the mocked tunnel, check response is success.
83     ${text}=    PcepOperations.Update_Xml_Lsp_Return_Json    ${update_delegated_xml}
84     Pcep_Json_Is_Success    ${text}
85
86 Topology_Updated
87     [Documentation]    Compare pcep-topology to default_json, which includes the updated tunnel.
88     [Tags]    critical
89     BuiltIn.Wait_Until_Keyword_succeeds    5s    1s    Compare_Topology    ${updated_json}    060_Topology_Updated.json
90
91 Unset_Password
92     [Documentation]    De-configure password for pcep dispatcher for client with Mininet IP address.
93     [Setup]    FailFast.Run_Even_When_Failing_Fast
94     Replace_Password_Xml_Element_In_Pcep_Client_Module    ${EMPTY}
95     FailFast.Do_Not_Fail_Fast_From_Now_On
96     # NOTE: It is still possible to remain failing, if both previous and this test failed.
97     [Teardown]    FailFast.Do_Not_Start_Failing_If_This_Failed
98
99 Topology_Unauthorized_3
100     [Documentation]    Wait for pcep-topology to become empty again.
101     [Tags]    critical
102     BuiltIn.Wait_Until_Keyword_Succeeds    10s    1s    Compare_Topology    ${offjson}    070_Unauthorized_4.json
103
104 Stop_Pcc_Mock
105     [Documentation]    Send ctrl+c to pcc-mock, fails if no prompt is seen
106     ...    after 3 seconds (the default for SSHLibrary)
107     [Setup]    FailFast.Run_Even_When_Failing_Fast
108     # FIXME: Bgpcepuser has Write_Ctrl_C keyword. Re-use it.
109     ${command}=    BuiltIn.Evaluate    chr(int(3))
110     BuiltIn.Log    ${command}
111     SSHLibrary.Write    ${command}
112     SSHLibrary.Read_Until_Prompt
113     FailFast.Do_Not_Fail_Fast_From_Now_On
114     # NOTE: It is still possible to remain failing, if both previous and this test failed.
115     [Teardown]    FailFast.Do_Not_Start_Failing_If_This_Failed
116
117 Topology_Postcondition
118     [Documentation]    Verify that pcep-topology stays empty.
119     [Tags]    critical
120     WaitForFailure.Verify_Keyword_Does_Not_Fail_Within_Timeout    10    1    Compare_Topology    ${offjson}    080_Postcondition.json
121     # FIXME: We should delete config changes to not affect next suite.
122
123 Delete_Pcep_Client_Module
124     [Documentation]    Delete Pcep client module.
125     &{mapping}    BuiltIn.Create_Dictionary    IP=${TOOLS_SYSTEM_IP}
126     TemplatedRequests.Delete_Templated    ${directory_with_template_folders}${/}pcep_topology_client_module    mapping=${mapping}
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     ...    Also, delete and create directories for json diff handling.
133     KarafKeywords.Setup_Karaf_Keywords
134     TemplatedRequests.Create_Default_Session
135     BuiltIn.Run_Keyword_If    """${USE_NETCONF_CONNECTOR}""" == """False"""    Install_Netconf_Connector
136     NexusKeywords.Initialize_Artifact_Deployment_And_Usage
137     ${current_connection}=    SSHLibrary.Get_Connection
138     ${current_prompt}=    BuiltIn.Set_Variable    ${current_connection.prompt}
139     BuiltIn.Log    ${current_prompt}
140     BuiltIn.Set_Suite_Variable    ${prompt}    ${current_prompt}
141     RequestsLibrary.Create_Session    ses    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}${OPERATIONAL_TOPO_API}    auth=${AUTH}
142     ${name}=    NexusKeywords.Deploy_Test_Tool    bgpcep    pcep-pcc-mock
143     BuiltIn.Set_Suite_Variable    ${filename}    ${name}
144     OperatingSystem.Remove_Directory    ${directory_for_expected_responses}    recursive=True
145     OperatingSystem.Remove_Directory    ${directory_for_actual_responses}    recursive=True
146     # The previous suite may have been using the same directories.
147     OperatingSystem.Create_Directory    ${directory_for_expected_responses}
148     OperatingSystem.Create_Directory    ${directory_for_actual_responses}
149     PcepOperations.Setup_Pcep_Operations
150     FailFast.Do_Not_Fail_Fast_From_Now_On
151
152 Tear_It_Down
153     [Documentation]    Download pccmock.log and Log its contents.
154     ...    Compute and Log the diff between expected and actual normalized responses.
155     ...    Close both HTTP client session and SSH connection to Mininet.
156     SSHLibrary.Get_File    pccmock.log
157     ${pccmocklog}=    OperatingSystem.Run    cat pccmock.log
158     BuiltIn.Log    ${pccmocklog}
159     ${diff}=    OperatingSystem.Run    diff -dur ${directory_for_expected_responses} ${directory_for_actual_responses}
160     BuiltIn.Log    ${diff}
161     PcepOperations.Teardown_Pcep_Operations
162     BuiltIn.Run_Keyword_If    """${USE_NETCONF_CONNECTOR}""" == """False"""    Uninstall_Netconf_Connector
163     RequestsLibrary.Delete_All_Sessions
164     SSHLibrary.Close_All_Connections
165
166 Install_Netconf_Connector
167     [Documentation]    Installs ${CONNECTOR_FEATURE} feature.
168     # During the netconf connector installation the karaf's ssh is restarted and connection to karaf console is droped. This is causing an error
169     # which is ignored, because the feature should be installed anyway.
170     ${status}    ${results} =    BuiltIn.Run_Keyword_And_Ignore_Error    KarafKeywords.Install_A_Feature    ${CONNECTOR_FEATURE}
171     ${status}    ${results} =    BuiltIn.Run_Keyword_And_Ignore_Error    KarafKeywords.Install_A_Feature    ${PCEP_FEATURE}
172     ${status}    ${results} =    BuiltIn.Run_Keyword_And_Ignore_Error    KarafKeywords.Install_A_Feature    ${RESTCONF_FEATURE}
173     BuiltIn.Log    ${results}
174     BuiltIn.Wait_Until_Keyword_Succeeds    240    3    Check_Netconf_Up_And_Running
175
176 Check_Netconf_Up_And_Running
177     [Documentation]    Make a request to netconf connector's mounted pcep module and expect it is mounted.
178     TemplatedRequests.Get_From_Uri    restconf/config/network-topology:network-topology/topology/topology-netconf/node/controller-config/yang-ext:mount/config:modules/module/odl-pcep-topology-provider-cfg:pcep-topology-provider/pcep-topology
179
180 Uninstall_Netconf_Connector
181     [Documentation]    Uninstalls ${CONNECTOR_FEATURE} feature.
182     ${status}    ${results} =    BuiltIn.Run_Keyword_And_Ignore_Error    KarafKeywords.Uninstall_A_Feature    ${CONNECTOR_FEATURE}
183     BuiltIn.Log    ${results}
184
185 Read_And_Fail_If_Prompt_Is_Seen
186     [Documentation]    Try to read SSH to see prompt, but expect to see no prompt within SSHLibrary's timeout.
187     BuiltIn.Run_Keyword_And_Expect_Error    No match found for '${prompt}' in *.    Read_Text_Before_Prompt
188
189 Read_Text_Before_Prompt
190     [Documentation]    Log text gathered by SSHLibrary.Read_Until_Prompt.
191     ...    This needs to be a separate keyword just because how Read_And_Fail_If_Prompt_Is_Seen is implemented.
192     ${text}=    SSHLibrary.Read_Until_Prompt
193     BuiltIn.Log    ${text}
194
195 Compare_Topology
196     [Arguments]    ${expected}    ${name}
197     [Documentation]    Get current pcep-topology as json, normalize both expected and actual json.
198     ...    Save normalized jsons to files for later processing.
199     ...    Error codes and normalized jsons should match exactly.
200     # FIXME: See bgpuser to move handling of expected outside WUKS loop, as in bgpuser suite.
201     ${normexp}=    norm_json.normalize_json_text    ${expected}
202     BuiltIn.Log    ${normexp}
203     OperatingSystem.Create_File    ${directory_for_expected_responses}${/}${name}    ${normexp}
204     ${resp}=    RequestsLibrary.Get_Request    ses    topology/pcep-topology
205     BuiltIn.Log    ${resp}
206     BuiltIn.Log    ${resp.text}
207     ${normresp}=    norm_json.normalize_json_text    ${resp.text}
208     BuiltIn.Log    ${normresp}
209     OperatingSystem.Create_File    ${directory_for_actual_responses}${/}${name}    ${normresp}
210     BuiltIn.Should_Be_Equal_As_Strings    ${resp.status_code}    200
211     BuiltIn.Should_Be_Equal    ${normresp}    ${normexp}
212
213 Construct_Password_Element_Line_Using_Password
214     [Arguments]    ${password}
215     [Documentation]    Return line with password XML element containing given password, whitespace is there so that data to send looks neat.
216     ${element}=    String.Replace_String    ${SPACE}${SPACE}<password>$PASSWORD</password>${\n}    $PASSWORD    ${password}
217     BuiltIn.Log    ${element}
218     [Return]    ${element}
219
220 Replace_Password_Xml_Element_In_Pcep_Client_Module
221     [Arguments]    ${password_element}
222     [Documentation]    Send restconf PUT to replace the config module specifying PCEP password element (may me empty=missing).
223     &{mapping}    BuiltIn.Create_Dictionary    IP=${TOOLS_SYSTEM_IP}    PASSWD=${password_element}
224     TemplatedRequests.Put_As_Xml_Templated    ${directory_with_template_folders}${/}pcep_topology_client_module    mapping=${mapping}