Include needed Assure_* keywords in BGP tests
[integration/test.git] / csit / suites / bgpcep / bgpingest / singlepeer_changecount.robot
1 *** Settings ***
2 Documentation     BGP performance of ingesting from 1 iBGP peer, data change counter is used.
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 ...               This suite uses play.py as single iBGP peer.
12 ...               The suite only looks at example-ipv4-topology, so RIB is not examined.
13 ...
14 ...               This suite requires odl-bgpcep-data-change-counter to be installed so
15 ...               make sure it is added to "install-features" of any jobs that are going
16 ...               to invoke it.
17 ...
18 ...               The suite consists of two halves, differing on which side initiates BGP connection.
19 ...               Data change counter is a lightweight way to detect "work is being done".
20 ...               WaitUtils provide a nice Keyword to wait for stability, but it needs
21 ...               initial value, that is why Store_Change_Count appears just before work-inducing action.
22 ...               The time for Wait_For_Stable_* cases to finish is the main performance metric.
23 ...               After waiting for stability is done, full check on number of prefixes present is performed.
24 ...
25 ...               TODO: Currently, if a bug causes zero increase of data changes,
26 ...               affected test cases will wait for max time. Reconsider.
27 ...               If zero increase is allowed as stable, higher number of repetitions should be required.
28 ...
29 ...               Additionally this test suite is not compatible with Helium and Hydrogen
30 ...               releases as they don't include data change counter feature.
31 ...               Use the other version of the suite (singlepeer_prefixcount.robot) to test them.
32 Suite Setup       Setup_Everything
33 Suite Teardown    Teardown_Everything
34 Test Setup        SetupUtils.Setup_Test_With_Logging_And_Fast_Failing
35 Test Teardown     SetupUtils.Teardown_Test_Show_Bugs_And_Start_Fast_Failing_If_Test_Failed
36 Library           SSHLibrary    timeout=10s
37 Library           RequestsLibrary
38 Variables         ${CURDIR}/../../../variables/Variables.py
39 Resource          ${CURDIR}/../../../libraries/BGPSpeaker.robot
40 Resource          ${CURDIR}/../../../libraries/ChangeCounter.robot
41 Resource          ${CURDIR}/../../../libraries/ConfigViaRestconf.robot
42 Resource          ${CURDIR}/../../../libraries/FailFast.robot
43 Resource          ${CURDIR}/../../../libraries/KillPythonTool.robot
44 Resource          ${CURDIR}/../../../libraries/PrefixCounting.robot
45 Resource          ${CURDIR}/../../../libraries/SetupUtils.robot
46 Resource          ${CURDIR}/../../../libraries/SSHKeywords.robot
47
48 *** Variables ***
49 ${BGP_TOOL_LOG_LEVEL}    info
50 ${BGP_VARIABLES_FOLDER}    ${CURDIR}/../../../variables/bgpuser/
51 ${CHECK_PERIOD}    1
52 ${CHECK_PERIOD_CHANGE_COUNT}    ${CHECK_PERIOD}
53 ${CHECK_PERIOD_CHANGE_COUNT_SINGLE}    ${CHECK_PERIOD_CHANGE_COUNT}
54 ${COUNT}          1000000
55 ${COUNT_CHANGE_COUNT}    ${COUNT}
56 ${COUNT_CHANGE_COUNT_SINGLE}    ${COUNT_CHANGE_COUNT}
57 ${HOLDTIME}       180
58 ${HOLDTIME_CHANGE_COUNT}    ${HOLDTIME}
59 ${HOLDTIME_CHANGE_COUNT_SINGLE}    ${HOLDTIME_CHANGE_COUNT}
60 ${INSERT}         1
61 ${KARAF_LOG_LEVEL}    INFO
62 ${KARAF_BGPCEP_LOG_LEVEL}    ${KARAF_LOG_LEVEL}
63 ${KARAF_PROTOCOL_LOG_LEVEL}    ${KARAF_BGPCEP_LOG_LEVEL}
64 ${PREFILL}        0
65 ${REPETITIONS}    1
66 ${REPETITIONS_CHANGE_COUNT}    ${REPETITIONS}
67 ${REPETITIONS_CHANGE_COUNT_SINGLE}    ${REPETITIONS_CHANGE_COUNT}
68 ${RESULTS_FILE_NAME}    bgp.csv
69 ${TEST_DURATION_MULTIPLIER}    1
70 ${TEST_DURATION_MULTIPLIER_CHANGE_COUNT}    ${TEST_DURATION_MULTIPLIER}
71 ${TEST_DURATION_MULTIPLIER_CHANGE_COUNT_SINGLE}    ${TEST_DURATION_MULTIPLIER_CHANGE_COUNT}
72 ${UPDATE}         single
73 ${WITHDRAW}       0
74 # TODO: Option names can be better.
75 ${last_change_count_single}    -1
76
77 *** Test Cases ***
78 Check_For_Empty_Ipv4_Topology_Before_Talking
79     [Documentation]    Wait for example-ipv4-topology to come up and empty. Give large timeout for case when BGP boots slower than restconf.
80     [Tags]    critical
81     # TODO: Choose which tags to assign and make sure they are assigned correctly.
82     BuiltIn.Wait_Until_Keyword_Succeeds    120s    1s    PrefixCounting.Check_Ipv4_Topology_Is_Empty
83
84 Reconfigure_ODL_To_Accept_Connection
85     [Documentation]    Configure BGP peer module with initiate-connection set to false.
86     ${template_as_string} =    BuiltIn.Set_Variable    {'NAME': 'example-bgp-peer', 'IP': '${TOOLS_SYSTEM_IP}', 'HOLDTIME': '${HOLDTIME_CHANGE_COUNT_SINGLE}', 'PEER_PORT': '${BGP_TOOL_PORT}', 'INITIATE': 'false'}
87     ConfigViaRestconf.Put_Xml_Template_Folder_Config_Via_Restconf    ${BGP_VARIABLES_FOLDER}${/}bgp_peer    ${template_as_string}
88
89 Wait_For_Data_Change_Counter_Ready
90     [Documentation]    Data change counter might have been slower to start than ipv4 topology, wait for it.
91     BuiltIn.Wait_Until_Keyword_Succeeds    60s    1s    ChangeCounter.Get_Change_Count
92
93 Reconfigure_Data_Change_Counter
94     [Documentation]    Configure data change counter to count transactions in example-ipv4-topology instead of example-linkstate-topology.
95     ChangeCounter.Reconfigure_Topology_Name    example-ipv4-topology
96
97 Change_Karaf_Logging_Levels
98     [Documentation]    We may want to set more verbose logging here after configuration is done.
99     KarafKeywords.Set_Bgpcep_Log_Levels    bgpcep_level=${KARAF_BGPCEP_LOG_LEVEL}    protocol_level=${KARAF_PROTOCOL_LOG_LEVEL}
100
101 Start_Talking_BGP_Speaker
102     [Documentation]    Start Python speaker to connect to ODL.
103     Store_Change_Count
104     # Myport value is needed for checking whether connection at precise port was established.
105     BGPSpeaker.Start_BGP_Speaker    --amount ${COUNT_CHANGE_COUNT_SINGLE} --myip=${TOOLS_SYSTEM_IP} --myport=${BGP_TOOL_PORT} --peerip=${ODL_SYSTEM_IP} --peerport=${ODL_BGP_PORT} --insert=${INSERT} --withdraw=${WITHDRAW} --prefill ${PREFILL} --update ${UPDATE} --${BGP_TOOL_LOG_LEVEL} --results ${RESULTS_FILE_NAME}
106
107 Wait_For_Stable_Talking_Ipv4_Topology
108     [Documentation]    Wait until example-ipv4-topology becomes stable. This is done by checking the change counter.
109     ChangeCounter.Wait_For_Change_Count_To_Become_Stable    timeout=${bgp_filling_timeout}    period=${CHECK_PERIOD_CHANGE_COUNT_SINGLE}    repetitions=${REPETITIONS_CHANGE_COUNT_SINGLE}    count_to_overcome=${last_change_count_single}
110
111 Check_Talking_Ipv4_Topology_Count
112     [Documentation]    Count the routes in example-ipv4-topology and fail if the count is not correct.
113     [Tags]    critical
114     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
115     PrefixCounting.Check_Ipv4_Topology_Count    ${COUNT_CHANGE_COUNT_SINGLE}
116
117 Kill_Talking_BGP_Speaker
118     [Documentation]    Abort the Python speaker. Also, attempt to stop failing fast.
119     [Tags]    critical
120     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
121     Store_Change_Count
122     BGPSpeaker.Kill_BGP_Speaker
123     FailFast.Do_Not_Fail_Fast_From_Now_On
124     # NOTE: It is still possible to remain failing fast, if both previous and this test have failed.
125     [Teardown]    SetupUtils.Teardown_Test_Show_Bugs_If_Test_Failed
126
127 Store_Results_For_Talking_BGP_Speaker
128     [Documentation]    Store results for plotting
129     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
130     Store_File_To_Workspace    totals-${RESULTS_FILE_NAME}    totals-${RESULTS_FILE_NAME}
131     Store_File_To_Workspace    performance-${RESULTS_FILE_NAME}    performance-${RESULTS_FILE_NAME}
132     Store_File_To_Workspace    totals-${RESULTS_FILE_NAME}    changecount-talking-totals-${RESULTS_FILE_NAME}
133     Store_File_To_Workspace    performance-${RESULTS_FILE_NAME}    changecount-talking-performance-${RESULTS_FILE_NAME}
134
135 Wait_For_Stable_Ipv4_Topology_After_Talking
136     [Documentation]    Wait until example-ipv4-topology becomes stable again.
137     [Tags]    critical
138     ChangeCounter.Wait_For_Change_Count_To_Become_Stable    timeout=${bgp_emptying_timeout}    period=${CHECK_PERIOD_CHANGE_COUNT_SINGLE}    repetitions=${REPETITIONS_CHANGE_COUNT_SINGLE}    count_to_overcome=${last_change_count_single}
139
140 Check_For_Empty_Ipv4_Topology_After_Talking
141     [Documentation]    Example-ipv4-topology should be empty now.
142     [Tags]    critical
143     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
144     PrefixCounting.Check_Ipv4_Topology_Is_Empty
145
146 Start_Listening_BGP_Speaker
147     [Documentation]    Start Python speaker in listening mode.
148     BGPSpeaker.Start_BGP_Speaker    --amount ${COUNT_CHANGE_COUNT_SINGLE} --listen --myip=${TOOLS_SYSTEM_IP} --myport=${BGP_TOOL_PORT} --peerip=${ODL_SYSTEM_IP} --insert=${INSERT} --withdraw=${WITHDRAW} --prefill ${PREFILL} --update ${UPDATE} --${BGP_TOOL_LOG_LEVEL} --results ${RESULTS_FILE_NAME}
149
150 Reconfigure_ODL_To_Initiate_Connection
151     [Documentation]    Replace BGP peer config module, now with initiate-connection set to true.
152     Store_Change_Count
153     ${template_as_string} =    BuiltIn.Set_Variable    {'NAME': 'example-bgp-peer', 'IP': '${TOOLS_SYSTEM_IP}', 'HOLDTIME': '${HOLDTIME_CHANGE_COUNT_SINGLE}', 'PEER_PORT': '${BGP_TOOL_PORT}', 'INITIATE': 'true'}
154     ConfigViaRestconf.Put_Xml_Template_Folder_Config_Via_Restconf    ${BGP_VARIABLES_FOLDER}${/}bgp_peer    ${template_as_string}
155
156 Wait_For_Stable_Listening_Ipv4_Topology
157     [Documentation]    Wait until example-ipv4-topology becomes stable.
158     ChangeCounter.Wait_For_Change_Count_To_Become_Stable    timeout=${bgp_filling_timeout}    period=${CHECK_PERIOD_CHANGE_COUNT_SINGLE}    repetitions=${REPETITIONS_CHANGE_COUNT_SINGLE}    count_to_overcome=${last_change_count_single}
159
160 Check_Listening_Ipv4_Topology_Count
161     [Documentation]    Count the routes in example-ipv4-topology and fail if the count is not correct.
162     [Tags]    critical
163     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
164     PrefixCounting.Check_Ipv4_Topology_Count    ${COUNT_CHANGE_COUNT_SINGLE}
165
166 Kill_Listening_BGP_Speaker
167     [Documentation]    Abort the Python speaker. Also, attempt to stop failing fast.
168     [Tags]    critical
169     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
170     Store_Change_Count
171     BGPSpeaker.Kill_BGP_Speaker
172     FailFast.Do_Not_Fail_Fast_From_Now_On
173     # NOTE: It is still possible to remain failing fast, if both previous and this test have failed.
174     [Teardown]    SetupUtils.Teardown_Test_Show_Bugs_If_Test_Failed
175
176 Store_Results_For_Listening_BGP_Speaker
177     [Documentation]    Store results for plotting
178     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
179     Store_File_To_Workspace    totals-${RESULTS_FILE_NAME}    totals-${RESULTS_FILE_NAME}
180     Store_File_To_Workspace    performance-${RESULTS_FILE_NAME}    performance-${RESULTS_FILE_NAME}
181     Store_File_To_Workspace    totals-${RESULTS_FILE_NAME}    changecount-listening-totals-${RESULTS_FILE_NAME}
182     Store_File_To_Workspace    performance-${RESULTS_FILE_NAME}    changecount-listening-performance-${RESULTS_FILE_NAME}
183
184 Wait_For_Stable_Ipv4_Topology_After_Listening
185     [Documentation]    Wait until example-ipv4-topology becomes stable again.
186     [Tags]    critical
187     ChangeCounter.Wait_For_Change_Count_To_Become_Stable    timeout=${bgp_emptying_timeout}    period=${CHECK_PERIOD_CHANGE_COUNT_SINGLE}    repetitions=${REPETITIONS_CHANGE_COUNT_SINGLE}    count_to_overcome=${last_change_count_single}
188
189 Check_For_Empty_Ipv4_Topology_After_Listening
190     [Documentation]    Example-ipv4-topology should be empty now.
191     [Tags]    critical
192     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
193     PrefixCounting.Check_Ipv4_Topology_Is_Empty
194
195 Restore_Karaf_Logging_Levels
196     [Documentation]    Set logging on bgpcep and protocol to the global value.
197     KarafKeywords.Set_Bgpcep_Log_Levels    bgpcep_level=${KARAF_LOG_LEVEL}    protocol_level=${KARAF_LOG_LEVEL}
198
199 Restore_Data_Change_Counter_Configuration
200     [Documentation]    Configure data change counter back to count transactions affecting example-linkstate-topology.
201     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
202     ChangeCounter.Reconfigure_Topology_Name    example-linkstate-topology
203
204 Delete_Bgp_Peer_Configuration
205     [Documentation]    Revert the BGP configuration to the original state: without any configured peers.
206     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
207     ${template_as_string} =    BuiltIn.Set_Variable    {'NAME': 'example-bgp-peer'}
208     ConfigViaRestconf.Delete_Xml_Template_Folder_Config_Via_Restconf    ${BGP_VARIABLES_FOLDER}${/}bgp_peer    ${template_as_string}
209
210 *** Keywords ***
211 Setup_Everything
212     [Documentation]    Setup imported resources, SSH-login to tools system,
213     ...    create HTTP session, put Python tool to tools system.
214     SetupUtils.Setup_Utils_For_Setup_And_Teardown
215     ConfigViaRestconf.Setup_Config_Via_Restconf
216     ChangeCounter.CC_Setup
217     PrefixCounting.PC_Setup
218     RequestsLibrary.Create_Session    operational    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}${OPERATIONAL_API}    auth=${AUTH}
219     # TODO: Do not include slash in ${OPERATIONAL_TOPO_API}, having it typed here is more readable.
220     # TODO: Alternatively, create variable in Variables which starts with http.
221     # Both TODOs would probably need to update every suite relying on current Variables.
222     SSHLibrary.Set_Default_Configuration    prompt=${TOOLS_SYSTEM_PROMPT}
223     SSHLibrary.Open_Connection    ${TOOLS_SYSTEM_IP}
224     Utils.Flexible_Mininet_Login
225     SSHKeywords.Require_Python
226     SSHKeywords.Assure_Library_Ipaddr    target_dir=.
227     SSHLibrary.Put_File    ${CURDIR}/../../../../tools/fastbgp/play.py
228     # Calculate the timeout value based on how many routes are going to be pushed
229     # TODO: Unify formulas with other suites in this directory.
230     ${timeout} =    BuiltIn.Evaluate    ${TEST_DURATION_MULTIPLIER_CHANGE_COUNT_SINGLE} * (${COUNT_CHANGE_COUNT_SINGLE} * 3.0 / 10000 + 20)
231     Builtin.Set_Suite_Variable    ${bgp_filling_timeout}    ${timeout}
232     Builtin.Set_Suite_Variable    ${bgp_emptying_timeout}    ${bgp_filling_timeout*3.0/4}
233     KarafKeywords.Execute_Controller_Karaf_Command_On_Background    log:set ${KARAF_LOG_LEVEL}
234
235 Teardown_Everything
236     [Documentation]    Make sure Python tool was killed and tear down imported Resources.
237     # Environment issue may have dropped the SSH connection, but we do not want Teardown to fail.
238     BuiltIn.Run_Keyword_And_Ignore_Error    KillPythonTool.Search_And_Kill_Remote_Python    'play\.py'
239     ConfigViaRestconf.Teardown_Config_Via_Restconf
240     RequestsLibrary.Delete_All_Sessions
241     SSHLibrary.Close_All_Connections
242
243 Store_Change_Count
244     [Documentation]    Get the count of changes from BGP change counter. Ignore error or store the value.
245     ${status}    ${count} =    BuiltIn.Run_Keyword_And_Ignore_Error    ChangeCounter.Get_Change_Count
246     BuiltIn.Run_Keyword_If    '${status}' == 'PASS'    BuiltIn.Set_Suite_Variable    ${last_change_count_single}    ${count}
247
248 Store_File_To_Workspace
249     [Arguments]    ${src_file_name}    ${dst_file_name}
250     [Documentation]    Store the provided file from the SSH client to workspace.
251     ${files}=    SSHLibrary.List Files In Directory    .
252     ${output_log}=    SSHLibrary.Execute_Command    cat ${src_file_name}
253     BuiltIn.Log    ${output_log}
254     Create File    ${dst_file_name}    ${output_log}