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