Update tcpmd5 suite with installation of netconf connector if needed
[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 *** Keywords ***
122 Set_It_Up
123     [Documentation]    Create SSH session to Mininet machine, prepare HTTP client session to Controller.
124     ...    Figure out latest pcc-mock version and download it from Nexus to Mininet.
125     ...    Also, delete and create directories for json diff handling.
126     KarafKeywords.Setup_Karaf_Keywords
127     TemplatedRequests.Create_Default_Session
128     BuiltIn.Run_Keyword_If    """${USE_NETCONF_CONNECTOR}""" == """False"""    Install_Netconf_Connector
129     NexusKeywords.Initialize_Artifact_Deployment_And_Usage
130     ${current_connection}=    SSHLibrary.Get_Connection
131     ${current_prompt}=    BuiltIn.Set_Variable    ${current_connection.prompt}
132     BuiltIn.Log    ${current_prompt}
133     BuiltIn.Set_Suite_Variable    ${prompt}    ${current_prompt}
134     RequestsLibrary.Create_Session    ses    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}${OPERATIONAL_TOPO_API}    auth=${AUTH}
135     ${name}=    NexusKeywords.Deploy_Test_Tool    bgpcep    pcep-pcc-mock
136     BuiltIn.Set_Suite_Variable    ${filename}    ${name}
137     OperatingSystem.Remove_Directory    ${directory_for_expected_responses}    recursive=True
138     OperatingSystem.Remove_Directory    ${directory_for_actual_responses}    recursive=True
139     # The previous suite may have been using the same directories.
140     OperatingSystem.Create_Directory    ${directory_for_expected_responses}
141     OperatingSystem.Create_Directory    ${directory_for_actual_responses}
142     PcepOperations.Setup_Pcep_Operations
143     FailFast.Do_Not_Fail_Fast_From_Now_On
144
145 Tear_It_Down
146     [Documentation]    Download pccmock.log and Log its contents.
147     ...    Compute and Log the diff between expected and actual normalized responses.
148     ...    Close both HTTP client session and SSH connection to Mininet.
149     SSHLibrary.Get_File    pccmock.log
150     ${pccmocklog}=    OperatingSystem.Run    cat pccmock.log
151     BuiltIn.Log    ${pccmocklog}
152     ${diff}=    OperatingSystem.Run    diff -dur ${directory_for_expected_responses} ${directory_for_actual_responses}
153     BuiltIn.Log    ${diff}
154     PcepOperations.Teardown_Pcep_Operations
155     BuiltIn.Run_Keyword_If    """${USE_NETCONF_CONNECTOR}""" == """False"""    Uninstall_Netconf_Connector
156     RequestsLibrary.Delete_All_Sessions
157     SSHLibrary.Close_All_Connections
158
159 Install_Netconf_Connector
160     [Documentation]    Installs ${CONNECTOR_FEATURE} feature.
161     # During the netconf connector installation the karaf's ssh is restarted and connection to karaf console is droped. This is causing an error
162     # which is ignored, because the feature should be installed anyway.
163     ${status}    ${results} =    BuiltIn.Run_Keyword_And_Ignore_Error    KarafKeywords.Install_A_Feature    ${CONNECTOR_FEATURE}
164     BuiltIn.Log    ${results}
165     BuiltIn.Wait_Until_Keyword_Succeeds    240    3    Check_Netconf_Up_And_Running
166
167 Check_Netconf_Up_And_Running
168     [Documentation]    Make a request to netconf connector's mounted pcep module and expect it is mounted.
169     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
170
171 Uninstall_Netconf_Connector
172     [Documentation]    Uninstalls ${CONNECTOR_FEATURE} feature.
173     ${status}    ${results} =    BuiltIn.Run_Keyword_And_Ignore_Error    KarafKeywords.Uninstall_A_Feature    ${CONNECTOR_FEATURE}
174     BuiltIn.Log    ${results}
175
176 Read_And_Fail_If_Prompt_Is_Seen
177     [Documentation]    Try to read SSH to see prompt, but expect to see no prompt within SSHLibrary's timeout.
178     BuiltIn.Run_Keyword_And_Expect_Error    No match found for '${prompt}' in *.    Read_Text_Before_Prompt
179
180 Read_Text_Before_Prompt
181     [Documentation]    Log text gathered by SSHLibrary.Read_Until_Prompt.
182     ...    This needs to be a separate keyword just because how Read_And_Fail_If_Prompt_Is_Seen is implemented.
183     ${text}=    SSHLibrary.Read_Until_Prompt
184     BuiltIn.Log    ${text}
185
186 Compare_Topology
187     [Arguments]    ${expected}    ${name}
188     [Documentation]    Get current pcep-topology as json, normalize both expected and actual json.
189     ...    Save normalized jsons to files for later processing.
190     ...    Error codes and normalized jsons should match exactly.
191     # FIXME: See bgpuser to move handling of expected outside WUKS loop, as in bgpuser suite.
192     ${normexp}=    norm_json.normalize_json_text    ${expected}
193     BuiltIn.Log    ${normexp}
194     OperatingSystem.Create_File    ${directory_for_expected_responses}${/}${name}    ${normexp}
195     ${resp}=    RequestsLibrary.Get_Request    ses    topology/pcep-topology
196     BuiltIn.Log    ${resp}
197     BuiltIn.Log    ${resp.text}
198     ${normresp}=    norm_json.normalize_json_text    ${resp.text}
199     BuiltIn.Log    ${normresp}
200     OperatingSystem.Create_File    ${directory_for_actual_responses}${/}${name}    ${normresp}
201     BuiltIn.Should_Be_Equal_As_Strings    ${resp.status_code}    200
202     BuiltIn.Should_Be_Equal    ${normresp}    ${normexp}
203
204 Construct_Password_Element_Line_Using_Password
205     [Arguments]    ${password}
206     [Documentation]    Return line with password XML element containing given password, whitespace is there so that data to send looks neat.
207     ${element}=    String.Replace_String    ${SPACE}${SPACE}<password>$PASSWORD</password>${\n}    $PASSWORD    ${password}
208     BuiltIn.Log    ${element}
209     [Return]    ${element}
210
211 Replace_Password_Xml_Element_In_Pcep_Client_Module
212     [Arguments]    ${password_element}
213     [Documentation]    Send restconf PUT to replace the config module specifying PCEP password element (may me empty=missing).
214     &{mapping}    BuiltIn.Create_Dictionary    IP=${TOOLS_SYSTEM_IP}    PASSWD=${password_element}
215     TemplatedRequests.Put_As_Xml_Templated    ${directory_with_template_folders}${/}pcep_topology_client_module    mapping=${mapping}