tcpmd5user test update
[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 ...               Test suite performs basic pcep md5 password authorization test cases:
11 ...               (Run entire basic PCEP suite without passwords.)
12 ...               Start pcc-mock (reconnecting mode): 1 pcc, 1 lsp, password set, check pcep-topology stays empty.
13 ...               Use restconf to change PCEP configuration to use a wrong password, check pcep-topology stays empty.
14 ...               Change ODL PCEP configuration to use the correct password, check pcep-topology shows the lsp.
15 ...               Update the lsp, check a change in pcep-topology.
16 ...               Change ODL PCEP configuration to not use password, pcep-topology empties, kill pcep-pcc-mock.
17 ...
18 ...               Stable/carbon and stable/nitrogen are using netconf-connector-ssh to send restconf requests.
19 ...               Oxygen test cases no longer need netconf-connector-ssh, and they include comparison of
20 ...               pcep-session-state, which is exclusive to oxygen.
21 Suite Setup       Set_It_Up
22 Suite Teardown    Tear_It_Down
23 Test Setup        FailFast.Fail_This_Fast_On_Previous_Error
24 Test Teardown     FailFast.Start_Failing_Fast_If_This_Failed
25 Library           OperatingSystem
26 Library           RequestsLibrary
27 Library           SSHLibrary    prompt=]>
28 Resource          ../../../libraries/FailFast.robot
29 Resource          ../../../libraries/KarafKeywords.robot
30 Resource          ../../../libraries/NexusKeywords.robot
31 Resource          ../../../libraries/TemplatedRequests.robot
32 Resource          ../../../libraries/WaitForFailure.robot
33 Resource          ../../../libraries/RemoteBash.robot
34 Resource          ../../../libraries/CompareStream.robot
35
36 *** Variables ***
37 ${DIR_WITH_TEMPLATES}    ${CURDIR}/../../../variables/tcpmd5user/
38 ${CONFIG_SESSION}    session
39 ${CONNECTOR_FEATURE}    odl-netconf-connector-all
40 ${PCEP_FEATURE}    odl-bgpcep-pcep
41 ${RESTCONF_FEATURE}    odl-restconf-all
42
43 *** Test Cases ***
44 Topology_Precondition
45     [Documentation]    Compare current pcep-topology to empty one.
46     ...    Timeout is long enough to see that pcep is ready, with no PCC connected.
47     [Tags]    critical
48     BuiltIn.Wait_Until_Keyword_Succeeds    300s    1s    TemplatedRequests.Get_As_Json_Templated    ${DIR_WITH_TEMPLATES}${/}default_off    session=${CONFIG_SESSION}    verify=True
49
50 Start_Secure_Pcc_Mock
51     [Documentation]    Execute pcc-mock on Mininet with password set, fail if pcc-mock promptly exits. Keep pcc-mock running for next test cases.
52     ${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
53     BuiltIn.Log    ${command}
54     SSHLibrary.Write    ${command}
55     Read_And_Fail_If_Prompt_Is_Seen
56
57 Topology_Unauthorized_1
58     [Documentation]    Try to catch a glimpse of pcc-mock in pcep-topology. Pass if no change from Precondition is detected over 10 seconds.
59     [Tags]    critical
60     WaitForFailure.Verify_Keyword_Does_Not_Fail_Within_Timeout    10s    1s    Test_Unauthorized
61
62 Set_Wrong_Password
63     [Documentation]    Configure password in pcep dispatcher for client with Mininet IP address.
64     ...    This password does not match what pcc-mock uses.
65     CompareStream.Run_Keyword_If_At_Least_Oxygen    Replace_Password_On_Pcep_Node    password=changeme
66     CompareStream.Run_Keyword_If_Less_Than_Oxygen    Set_Password_Less_Than_Oxygen    password=changeme
67
68 Topology_Unauthorized_2
69     [Documentation]    The same logic as Topology_Unauthorized_1 as incorrect password was provided to ODL.
70     [Tags]    critical
71     WaitForFailure.Verify_Keyword_Does_Not_Fail_Within_Timeout    10s    1s    Test_Unauthorized
72
73 Set_Correct_Password
74     [Documentation]    Configure password in pcep dispatcher for client with Mininet IP address.
75     ...    This password finally matches what pcc-mock uses.
76     CompareStream.Run_Keyword_If_At_Least_Oxygen    Replace_Password_On_Pcep_Node    password=topsecret
77     CompareStream.Run_Keyword_If_Less_Than_Oxygen    Set_Password_Less_Than_Oxygen    password=topsecret
78
79 Topology_Intercondition
80     [Documentation]    Compare pcep-topology/path-computation-client to filled one, which includes a tunnel from pcc-mock.
81     ...    For oxygen compares full pcep-topology including pcep-session-state
82     &{mapping}    BuiltIn.Create_Dictionary    IP=${TOOLS_SYSTEM_IP}    CODE=${pcc_name_code}    NAME=${pcc_name}    IP_ODL=${ODL_SYSTEM_IP}
83     BuiltIn.Wait_Until_Keyword_Succeeds    10s    1s    TemplatedRequests.Get_As_Json_Templated    ${DIR_WITH_TEMPLATES}${/}default_on    ${mapping}    ${CONFIG_SESSION}
84     ...    verify=True
85     CompareStream.Run_Keyword_If_At_Least_Oxygen    BuiltIn.Wait_Until_Keyword_Succeeds    30s    1s    TemplatedRequests.Get_As_Json_Templated    ${DIR_WITH_TEMPLATES}${/}default_on_state    ${mapping}
86     ...    ${CONFIG_SESSION}    verify=True
87
88 Update_Delegated
89     [Documentation]    Perform update-lsp on the mocked tunnel, check response is success.
90     &{mapping}    BuiltIn.Create_Dictionary    IP=${TOOLS_SYSTEM_IP}    NAME=${pcc_name}
91     ${response}=    TemplatedRequests.Post_As_Xml_Templated    ${DIR_WITH_TEMPLATES}${/}update_delegated    ${mapping}    ${CONFIG_SESSION}    verify=True
92     Log    ${response}
93
94 Topology_Updated
95     [Documentation]    Compare pcep-topology/path-computation-client to default_on_updated, which includes the updated tunnel.
96     ...    For oxygen compares full pcep-topology including pcep-session-state
97     [Tags]    critical
98     &{mapping}    BuiltIn.Create_Dictionary    IP=${TOOLS_SYSTEM_IP}    CODE=${pcc_name_code}    NAME=${pcc_name}    IP_ODL=${ODL_SYSTEM_IP}
99     BuiltIn.Wait_Until_Keyword_Succeeds    10s    1s    TemplatedRequests.Get_As_Json_Templated    ${DIR_WITH_TEMPLATES}${/}default_on_updated    ${mapping}    ${CONFIG_SESSION}
100     ...    verify=True
101     CompareStream.Run_Keyword_If_At_Least_Oxygen    BuiltIn.Wait_Until_Keyword_Succeeds    30s    1s    TemplatedRequests.Get_As_Json_Templated    ${DIR_WITH_TEMPLATES}${/}default_on_updated_state    ${mapping}
102     ...    ${CONFIG_SESSION}    verify=True
103
104 Unset_Password
105     [Documentation]    De-configure password for pcep dispatcher for client with Mininet IP address.
106     [Setup]    FailFast.Run_Even_When_Failing_Fast
107     CompareStream.Run_Keyword_If_At_Least_Oxygen    Unset_Password_On_Pcep_Node
108     CompareStream.Run_Keyword_If_Less_Than_Oxygen    Replace_Password_Xml_Element_In_Pcep_Client_Module_Less_Than_Oxygen
109     FailFast.Do_Not_Fail_Fast_From_Now_On
110     # NOTE: It is still possible to remain failing, if both previous and this test failed.
111     [Teardown]    FailFast.Do_Not_Start_Failing_If_This_Failed
112
113 Topology_Unauthorized_3
114     [Documentation]    Wait for pcep-topology to become empty again.
115     [Tags]    critical
116     BuiltIn.Wait_Until_Keyword_Succeeds    10s    1s    Test_Unauthorized
117
118 Stop_Pcc_Mock
119     [Documentation]    Send ctrl+c to pcc-mock, fails if no prompt is seen
120     ...    after 3 seconds (the default for SSHLibrary)
121     [Setup]    FailFast.Run_Even_When_Failing_Fast
122     RemoteBash.Write_Bare_Ctrl_C
123     ${output}=    SSHLibrary.Read_Until_Prompt
124     BuiltIn.Log    ${output}
125     FailFast.Do_Not_Fail_Fast_From_Now_On
126     # NOTE: It is still possible to remain failing, if both previous and this test failed.
127     [Teardown]    FailFast.Do_Not_Start_Failing_If_This_Failed
128
129 Topology_Postcondition
130     [Documentation]    Verify that pcep-topology stays empty.
131     [Tags]    critical
132     WaitForFailure.Verify_Keyword_Does_Not_Fail_Within_Timeout    10s    1s    Test_Unauthorized
133
134 Delete_Pcep_Client_Module
135     [Documentation]    Delete Pcep client module.
136     &{mapping}    BuiltIn.Create_Dictionary    IP=${TOOLS_SYSTEM_IP}
137     CompareStream.Run_Keyword_If_At_Least_Oxygen    TemplatedRequests.Delete_Templated    ${DIR_WITH_TEMPLATES}${/}pcep_topology_node    ${mapping}
138     CompareStream.Run_Keyword_If_Less_Than_Oxygen    TemplatedRequests.Delete_Templated    ${DIR_WITH_TEMPLATES}${/}pcep_topology_client_module    ${mapping}
139
140 *** Keywords ***
141 Set_It_Up
142     [Documentation]    Create SSH session to Mininet machine, prepare HTTP client session to Controller.
143     ...    Figure out latest pcc-mock version and download it from Nexus to Mininet.
144     ...    Also, delete and create directories for json diff handling.
145     ...    Sets up netconf-connector on odl-streams less than oxygen.
146     KarafKeywords.Setup_Karaf_Keywords
147     TemplatedRequests.Create_Default_Session
148     BuiltIn.Run_Keyword_If    """${USE_NETCONF_CONNECTOR}""" == """False"""    CompareStream.Run_Keyword_If_Less_Than_Oxygen    Install_Netconf_Connector
149     NexusKeywords.Initialize_Artifact_Deployment_And_Usage
150     ${current_connection}=    SSHLibrary.Get_Connection
151     ${current_prompt}=    BuiltIn.Set_Variable    ${current_connection.prompt}
152     BuiltIn.Log    ${current_prompt}
153     BuiltIn.Set_Suite_Variable    ${prompt}    ${current_prompt}
154     RequestsLibrary.Create_Session    ${CONFIG_SESSION}    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}
155     ${name}=    NexusKeywords.Deploy_Test_Tool    bgpcep    pcep-pcc-mock
156     BuiltIn.Set_Suite_Variable    ${filename}    ${name}
157     #Setting Pcc Name and its code for mapping for templates
158     BuiltIn.Set_Suite_Variable    ${pcc_name}    pcc_${TOOLS_SYSTEM_IP}_tunnel_1
159     ${code}=    Evaluate    binascii.b2a_base64('${pcc_name}')[:-1]    modules=binascii
160     BuiltIn.Set_Suite_Variable    ${pcc_name_code}    ${code}
161     FailFast.Do_Not_Fail_Fast_From_Now_On
162
163 Tear_It_Down
164     [Documentation]    Download pccmock.log and Log its contents.
165     ...    Compute and Log the diff between expected and actual normalized responses.
166     ...    Close both HTTP client session and SSH connection to Mininet.
167     SSHLibrary.Get_File    pccmock.log
168     ${pccmocklog}=    OperatingSystem.Run    cat pccmock.log
169     BuiltIn.Log    ${pccmocklog}
170     BuiltIn.Run_Keyword_If    """${USE_NETCONF_CONNECTOR}""" == """False"""    CompareStream.Run_Keyword_If_Less_Than_Oxygen    Uninstall_Netconf_Connector
171     RequestsLibrary.Delete_All_Sessions
172     SSHLibrary.Close_All_Connections
173
174 Install_Netconf_Connector
175     [Documentation]    Installs ${CONNECTOR_FEATURE} feature.
176     # During the netconf connector installation the karaf's ssh is restarted and connection to karaf console is droped. This is causing an error
177     # which is ignored, because the feature should be installed anyway.
178     ${status}    ${results} =    BuiltIn.Run_Keyword_And_Ignore_Error    KarafKeywords.Install_A_Feature    ${CONNECTOR_FEATURE}
179     ${status}    ${results} =    BuiltIn.Run_Keyword_And_Ignore_Error    KarafKeywords.Install_A_Feature    ${PCEP_FEATURE}
180     ${status}    ${results} =    BuiltIn.Run_Keyword_And_Ignore_Error    KarafKeywords.Install_A_Feature    ${RESTCONF_FEATURE}
181     BuiltIn.Log    ${results}
182     BuiltIn.Wait_Until_Keyword_Succeeds    240s    3s    Check_Netconf_Up_And_Running
183
184 Check_Netconf_Up_And_Running
185     [Documentation]    Make a request to netconf connector's mounted pcep module and expect it is mounted.
186     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
187
188 Uninstall_Netconf_Connector
189     [Documentation]    Uninstalls ${CONNECTOR_FEATURE} feature.
190     ${status}    ${results} =    BuiltIn.Run_Keyword_And_Ignore_Error    KarafKeywords.Uninstall_A_Feature    ${CONNECTOR_FEATURE}
191     BuiltIn.Log    ${results}
192
193 Test_Unauthorized
194     [Documentation]    Try to access pcep topology with wrong password, should get empty topology
195     TemplatedRequests.Get_As_Json_Templated    ${DIR_WITH_TEMPLATES}${/}default_off    session=${CONFIG_SESSION}    verify=True
196
197 Set_Password_Less_Than_Oxygen
198     [Arguments]    ${password}=${EMPTY}
199     ${password_line}=    Construct_Password_Element_Line_Using_Password    password=${password}
200     Replace_Password_Xml_Element_In_Pcep_Client_Module_Less_Than_Oxygen    ${password_line}
201
202 Read_And_Fail_If_Prompt_Is_Seen
203     [Documentation]    Try to read SSH to see prompt, but expect to see no prompt within SSHLibrary's timeout.
204     BuiltIn.Run_Keyword_And_Expect_Error    No match found for '${prompt}' in *.    Read_Text_Before_Prompt
205
206 Read_Text_Before_Prompt
207     [Documentation]    Log text gathered by SSHLibrary.Read_Until_Prompt.
208     ...    This needs to be a separate keyword just because how Read_And_Fail_If_Prompt_Is_Seen is implemented.
209     ${text}=    SSHLibrary.Read_Until_Prompt
210     BuiltIn.Log    ${text}
211
212 Replace_Password_On_Pcep_Node
213     [Arguments]    ${password}
214     [Documentation]    Send restconf PUT to replace the config module specifying PCEP password element.
215     &{mapping}    BuiltIn.Create_Dictionary    IP=${TOOLS_SYSTEM_IP}    PASSWD=${password}
216     TemplatedRequests.Put_As_Xml_Templated    ${DIR_WITH_TEMPLATES}${/}pcep_topology_node    mapping=${mapping}
217
218 Unset_Password_On_Pcep_Node
219     [Documentation]    Send restconf PUT to unset the config module.
220     &{mapping}    BuiltIn.Create_Dictionary    IP=${TOOLS_SYSTEM_IP}
221     TemplatedRequests.Put_As_Xml_Templated    ${DIR_WITH_TEMPLATES}${/}pcep_topology_node_empty    mapping=${mapping}
222
223 Construct_Password_Element_Line_Using_Password
224     [Arguments]    ${password}
225     [Documentation]    Return line with password XML element containing given password, whitespace is there so that data to send looks neat.
226     ${element}=    String.Replace_String    ${SPACE}${SPACE}<password>$PASSWORD</password>${\n}    $PASSWORD    ${password}
227     BuiltIn.Log    ${element}
228     [Return]    ${element}
229
230 Replace_Password_Xml_Element_In_Pcep_Client_Module_Less_Than_Oxygen
231     [Arguments]    ${password_element}=${EMPTY}
232     [Documentation]    Send restconf PUT to replace the config module specifying PCEP password element (may be empty=missing).
233     &{mapping}    BuiltIn.Create_Dictionary    IP=${TOOLS_SYSTEM_IP}    PASSWD=${password_element}
234     TemplatedRequests.Put_As_Xml_Templated    ${DIR_WITH_TEMPLATES}${/}pcep_topology_client_module    mapping=${mapping}