Edited suites to use norm_json.py instead of HsfJson
[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/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    ${TOOLS_SYSTEM_IP}
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 ${TOOLS_SYSTEM_IP} --remote-address ${ODL_SYSTEM_IP} 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 Topology_Unauthorized_2
55     [Documentation]    The same logic as Topology_Unauthorized_1 as no password was provided to ODL.
56     [Tags]    critical
57     WaitForFailure.Verify_Keyword_Does_Not_Fail_Within_Timeout    10s    1s    Compare_Topology    ${off_json}    030_Unauthorized_2.json
58
59 Set_Wrong_Password
60     [Documentation]    Configure password in pcep dispatcher for client with Mininet IP address.
61     ...    This password does not match what pcc-mock uses.
62     ${password_line}=    Construct_Password_Element_Line_Using_Password    changeme
63     BuiltIn.Log    ${password_line}
64     Replace_Password_Xml_Element_In_Pcep_Client_Module    ${password_line}
65
66 Topology_Unauthorized_3
67     [Documentation]    The same logic as Topology_Unauthorized_1 as incorrect password was provided to ODL.
68     [Tags]    critical
69     WaitForFailure.Verify_Keyword_Does_Not_Fail_Within_Timeout    10s    1s    Compare_Topology    ${off_json}    040_Unauthorized_3.json
70
71 Set_Correct_Password
72     [Documentation]    Configure password in pcep dispatcher for client with Mininet IP address.
73     ...    This password finally matches what pcc-mock uses.
74     ${password_line}=    Construct_Password_Element_Line_Using_Password    topsecret
75     BuiltIn.Log    ${password_line}
76     Replace_Password_Xml_Element_In_Pcep_Client_Module    ${password_line}
77
78 Topology_Intercondition
79     [Documentation]    Compare pcep-topology to filled one, which includes a tunnel from pcc-mock.
80     BuiltIn.Wait_Until_Keyword_Succeeds    10s    1s    Compare_Topology    ${default_json}    050_Intercondition.json
81
82 Update_Delegated
83     [Documentation]    Perform update-lsp on the mocked tunnel, check response is success.
84     ${text}=    PcepOperations.Update_Xml_Lsp_Return_Json    ${update_delegated_xml}
85     Pcep_Json_Is_Success    ${text}
86
87 Topology_Updated
88     [Documentation]    Compare pcep-topology to default_json, which includes the updated tunnel.
89     [Tags]    critical
90     BuiltIn.Wait_Until_Keyword_succeeds    5s    1s    Compare_Topology    ${updated_json}    060_Topology_Updated.json
91
92 Unset_Password
93     [Documentation]    De-configure password for pcep dispatcher for client with Mininet IP address.
94     [Setup]    FailFast.Run_Even_When_Failing_Fast
95     Replace_Password_Xml_Element_In_Pcep_Client_Module    ${EMPTY}
96     FailFast.Do_Not_Fail_Fast_From_Now_On
97     # NOTE: It is still possible to remain failing, if both previous and this test failed.
98     [Teardown]    FailFast.Do_Not_Start_Failing_If_This_Failed
99
100 Topology_Unauthorized_4
101     [Documentation]    Wait for pcep-topology to become empty again.
102     [Tags]    critical
103     BuiltIn.Wait_Until_Keyword_Succeeds    10s    1s    Compare_Topology    ${offjson}    070_Unauthorized_4.json
104
105 Stop_Pcc_Mock
106     [Documentation]    Send ctrl+c to pcc-mock, fails if no prompt is seen
107     ...    after 3 seconds (the default for SSHLibrary)
108     [Setup]    FailFast.Run_Even_When_Failing_Fast
109     # FIXME: Bgpcepuser has Write_Ctrl_C keyword. Re-use it.
110     ${command}=    BuiltIn.Evaluate    chr(int(3))
111     BuiltIn.Log    ${command}
112     SSHLibrary.Write    ${command}
113     SSHLibrary.Read_Until_Prompt
114     FailFast.Do_Not_Fail_Fast_From_Now_On
115     # NOTE: It is still possible to remain failing, if both previous and this test failed.
116     [Teardown]    FailFast.Do_Not_Start_Failing_If_This_Failed
117
118 Topology_Postcondition
119     [Documentation]    Verify that pcep-topology stays empty.
120     [Tags]    critical
121     WaitForFailure.Verify_Keyword_Does_Not_Fail_Within_Timeout    10    1    Compare_Topology    ${offjson}    080_Postcondition.json
122     # FIXME: We should delete config changes to not affect next suite.
123
124 *** Keywords ***
125 Set_It_Up
126     [Documentation]    Create SSH session to Mininet machine, prepare HTTP client session to Controller.
127     ...    Figure out latest pcc-mock version and download it from Nexus to Mininet.
128     ...    Also, delete and create directories for json diff handling.
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     ConfigViaRestconf.Setup_Config_Via_Restconf
143     PcepOperations.Setup_Pcep_Operations
144     FailFast.Do_Not_Fail_Fast_From_Now_On
145
146 Tear_It_Down
147     [Documentation]    Download pccmock.log and Log its contents.
148     ...    Compute and Log the diff between expected and actual normalized responses.
149     ...    Close both HTTP client session and SSH connection to Mininet.
150     SSHLibrary.Get_File    pccmock.log
151     ${pccmocklog}=    OperatingSystem.Run    cat pccmock.log
152     BuiltIn.Log    ${pccmocklog}
153     ${diff}=    OperatingSystem.Run    diff -dur ${directory_for_expected_responses} ${directory_for_actual_responses}
154     BuiltIn.Log    ${diff}
155     PcepOperations.Teardown_Pcep_Operations
156     ConfigViaRestconf.Teardown_Config_Via_Restconf
157     RequestsLibrary.Delete_All_Sessions
158     SSHLibrary.Close_All_Connections
159
160 Read_And_Fail_If_Prompt_Is_Seen
161     [Documentation]    Try to read SSH to see prompt, but expect to see no prompt within SSHLibrary's timeout.
162     BuiltIn.Run_Keyword_And_Expect_Error    No match found for '${prompt}' in *.    Read_Text_Before_Prompt
163
164 Read_Text_Before_Prompt
165     [Documentation]    Log text gathered by SSHLibrary.Read_Until_Prompt.
166     ...    This needs to be a separate keyword just because how Read_And_Fail_If_Prompt_Is_Seen is implemented.
167     ${text}=    SSHLibrary.Read_Until_Prompt
168     BuiltIn.Log    ${text}
169
170 Compare_Topology
171     [Arguments]    ${expected}    ${name}
172     [Documentation]    Get current pcep-topology as json, normalize both expected and actual json.
173     ...    Save normalized jsons to files for later processing.
174     ...    Error codes and normalized jsons should match exactly.
175     # FIXME: See bgpuser to move handling of expected outside WUKS loop, as in bgpuser suite.
176     ${normexp}=    norm_json.normalize_json_text    ${expected}
177     BuiltIn.Log    ${normexp}
178     OperatingSystem.Create_File    ${directory_for_expected_responses}${/}${name}    ${normexp}
179     ${resp}=    RequestsLibrary.Get_Request    ses    topology/pcep-topology
180     BuiltIn.Log    ${resp}
181     BuiltIn.Log    ${resp.text}
182     ${normresp}=    norm_json.normalize_json_text    ${resp.text}
183     BuiltIn.Log    ${normresp}
184     OperatingSystem.Create_File    ${directory_for_actual_responses}${/}${name}    ${normresp}
185     BuiltIn.Should_Be_Equal_As_Strings    ${resp.status_code}    200
186     BuiltIn.Should_Be_Equal    ${normresp}    ${normexp}
187
188 Construct_Password_Element_Line_Using_Password
189     [Arguments]    ${password}
190     [Documentation]    Return line with password XML element containing given password, whitespace is there so that data to send looks neat.
191     ${element}=    String.Replace_String    ${SPACE}${SPACE}<password>$PASSWORD</password>${\n}    $PASSWORD    ${password}
192     BuiltIn.Log    ${element}
193     [Return]    ${element}
194
195 Replace_Password_Xml_Element_In_Pcep_Client_Module
196     [Arguments]    ${password_element}
197     [Documentation]    Send restconf PUT to replace the config module specifying PCEP password element (may me empty=missing).
198     ${mapping_as_string}=    BuiltIn.Set_Variable    {'IP': '${TOOLS_SYSTEM_IP}', 'PASSWD': '''${password_element}'''}
199     BuiltIn.Log    ${mapping_as_string}
200     ConfigViaRestconf.Put_Xml_Template_Folder_Config_Via_Restconf    ${directory_with_template_folders}${/}pcep_topology_client_module    ${mapping_as_string}