bgpingest testsuite latest review comments and fixme
[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     FailFast.Start_Failing_Fast_If_This_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
47 *** Variables ***
48 ${BGP_VARIABLES_FOLDER}    ${CURDIR}/../../../variables/bgpuser/
49 ${HOLDTIME}       180
50 ${HOLDTIME_CHANGE_COUNT}    ${HOLDTIME}
51 ${COUNT}          1000000
52 ${COUNT_CHANGE_COUNT}    ${COUNT}
53 ${CHECK_PERIOD}    1
54 ${CHECK_PERIOD_CHANGE_COUNT}    ${CHECK_PERIOD}
55 ${REPETITIONS_CHANGE_COUNT}    1
56 ${INSERT}         1
57 ${WITHDRAW}       0
58 ${PREFILL}        0
59 ${UPDATE}         single
60 ${BGP_TOOL_LOG_LEVEL}    info
61 ${CONTROLLER_LOG_LEVEL}    INFO
62 ${CONTROLLER_BGP_LOG_LEVEL}    DEFAULT
63 ${RESULTS_FILE_NAME}    bgp.csv
64 ${TEST_DURATION_MULTIPLIER}    1
65 # TODO: Option names can be better.
66 ${last_change_count}    -1
67
68 *** Test Cases ***
69 Check_For_Empty_Ipv4_Topology_Before_Talking
70     [Documentation]    Wait for example-ipv4-topology to come up and empty. Give large timeout for case when BGP boots slower than restconf.
71     [Tags]    critical
72     # TODO: Choose which tags to assign and make sure they are assigned correctly.
73     BuiltIn.Wait_Until_Keyword_Succeeds    120s    1s    PrefixCounting.Check_Ipv4_Topology_Is_Empty
74
75 Reconfigure_ODL_To_Accept_Connection
76     [Documentation]    Configure BGP peer module with initiate-connection set to false.
77     ${template_as_string} =    BuiltIn.Set_Variable    {'NAME': 'example-bgp-peer', 'IP': '${TOOLS_SYSTEM_IP}', 'HOLDTIME': '${HOLDTIME_CHANGE_COUNT}', 'PEER_PORT': '${BGP_TOOL_PORT}', 'INITIATE': 'false'}
78     ConfigViaRestconf.Put_Xml_Template_Folder_Config_Via_Restconf    ${BGP_VARIABLES_FOLDER}${/}bgp_peer    ${template_as_string}
79
80 Wait_For_Data_Change_Counter_Ready
81     [Documentation]    Data change counter might have been slower to start than ipv4 topology, wait for it.
82     BuiltIn.Wait_Until_Keyword_Succeeds    60s    1s    ChangeCounter.Get_Change_Count
83
84 Reconfigure_Data_Change_Counter
85     [Documentation]    Configure data change counter to count transactions in example-ipv4-topology instead of example-linkstate-topology.
86     ChangeCounter.Reconfigure_Topology_Name    example-ipv4-topology
87
88 Start_Talking_BGP_Speaker
89     [Documentation]    Start Python speaker to connect to ODL.
90     Store_Change_Count
91     # Myport value is needed for checking whether connection at precise port was established.
92     BGPSpeaker.Start_BGP_Speaker    --amount ${COUNT_CHANGE_COUNT} --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}
93
94 Wait_For_Stable_Talking_Ipv4_Topology
95     [Documentation]    Wait until example-ipv4-topology becomes stable. This is done by checking the change counter.
96     ChangeCounter.Wait_For_Change_Count_To_Become_Stable    timeout=${bgp_filling_timeout}    period=${CHECK_PERIOD_CHANGE_COUNT}    repetitions=${REPETITIONS_CHANGE_COUNT}    count_to_overcome=${last_change_count}
97
98 Check_Talking_Ipv4_Topology_Count
99     [Documentation]    Count the routes in example-ipv4-topology and fail if the count is not correct.
100     [Tags]    critical
101     PrefixCounting.Check_Ipv4_Topology_Count    ${COUNT_CHANGE_COUNT}
102
103 Kill_Talking_BGP_Speaker
104     [Documentation]    Abort the Python speaker. Also, attempt to stop failing fast.
105     [Tags]    critical
106     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
107     Store_Change_Count
108     BGPSpeaker.Kill_BGP_Speaker
109     FailFast.Do_Not_Fail_Fast_From_Now_On
110     # NOTE: It is still possible to remain failing fast, if both previous and this test have failed.
111     [Teardown]    FailFast.Do_Not_Start_Failing_If_This_Failed
112
113 Store_Results_For_Talking_BGP_Speaker
114     [Documentation]    Store results for plotting
115     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
116     Store_File_To_Workspace    totals-${RESULTS_FILE_NAME}    totals-${RESULTS_FILE_NAME}
117     Store_File_To_Workspace    performance-${RESULTS_FILE_NAME}    performance-${RESULTS_FILE_NAME}
118     Store_File_To_Workspace    totals-${RESULTS_FILE_NAME}    changecount-talking-totals-${RESULTS_FILE_NAME}
119     Store_File_To_Workspace    performance-${RESULTS_FILE_NAME}    changecount-talking-performance-${RESULTS_FILE_NAME}
120
121 Wait_For_Stable_Ipv4_Topology_After_Talking
122     [Documentation]    Wait until example-ipv4-topology becomes stable again.
123     [Tags]    critical
124     ChangeCounter.Wait_For_Change_Count_To_Become_Stable    timeout=${bgp_emptying_timeout}    period=${CHECK_PERIOD_CHANGE_COUNT}    repetitions=${REPETITIONS_CHANGE_COUNT}    count_to_overcome=${last_change_count}
125
126 Check_For_Empty_Ipv4_Topology_After_Talking
127     [Documentation]    Example-ipv4-topology should be empty now.
128     [Tags]    critical
129     PrefixCounting.Check_Ipv4_Topology_Is_Empty
130
131 Start_Listening_BGP_Speaker
132     [Documentation]    Start Python speaker in listening mode.
133     BGPSpeaker.Start_BGP_Speaker    --amount ${COUNT_CHANGE_COUNT} --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}
134
135 Reconfigure_ODL_To_Initiate_Connection
136     [Documentation]    Replace BGP peer config module, now with initiate-connection set to true.
137     Store_Change_Count
138     ${template_as_string} =    BuiltIn.Set_Variable    {'NAME': 'example-bgp-peer', 'IP': '${TOOLS_SYSTEM_IP}', 'HOLDTIME': '${HOLDTIME_CHANGE_COUNT}', 'PEER_PORT': '${BGP_TOOL_PORT}', 'INITIATE': 'true'}
139     ConfigViaRestconf.Put_Xml_Template_Folder_Config_Via_Restconf    ${BGP_VARIABLES_FOLDER}${/}bgp_peer    ${template_as_string}
140
141 Wait_For_Stable_Listening_Ipv4_Topology
142     [Documentation]    Wait until example-ipv4-topology becomes stable.
143     ChangeCounter.Wait_For_Change_Count_To_Become_Stable    timeout=${bgp_filling_timeout}    period=${CHECK_PERIOD_CHANGE_COUNT}    repetitions=${REPETITIONS_CHANGE_COUNT}    count_to_overcome=${last_change_count}
144
145 Check_Listening_Ipv4_Topology_Count
146     [Documentation]    Count the routes in example-ipv4-topology and fail if the count is not correct.
147     [Tags]    critical
148     PrefixCounting.Check_Ipv4_Topology_Count    ${COUNT_CHANGE_COUNT}
149
150 Kill_Listening_BGP_Speaker
151     [Documentation]    Abort the Python speaker. Also, attempt to stop failing fast.
152     [Tags]    critical
153     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
154     Store_Change_Count
155     BGPSpeaker.Kill_BGP_Speaker
156     FailFast.Do_Not_Fail_Fast_From_Now_On
157     # NOTE: It is still possible to remain failing fast, if both previous and this test have failed.
158     [Teardown]    FailFast.Do_Not_Start_Failing_If_This_Failed
159
160 Store_Results_For_Listening_BGP_Speaker
161     [Documentation]    Store results for plotting
162     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
163     Store_File_To_Workspace    totals-${RESULTS_FILE_NAME}    totals-${RESULTS_FILE_NAME}
164     Store_File_To_Workspace    performance-${RESULTS_FILE_NAME}    performance-${RESULTS_FILE_NAME}
165     Store_File_To_Workspace    totals-${RESULTS_FILE_NAME}    changecount-listening-totals-${RESULTS_FILE_NAME}
166     Store_File_To_Workspace    performance-${RESULTS_FILE_NAME}    changecount-listening-performance-${RESULTS_FILE_NAME}
167
168 Wait_For_Stable_Ipv4_Topology_After_Listening
169     [Documentation]    Wait until example-ipv4-topology becomes stable again.
170     [Tags]    critical
171     ChangeCounter.Wait_For_Change_Count_To_Become_Stable    timeout=${bgp_emptying_timeout}    period=${CHECK_PERIOD_CHANGE_COUNT}    repetitions=${REPETITIONS_CHANGE_COUNT}    count_to_overcome=${last_change_count}
172
173 Check_For_Empty_Ipv4_Topology_After_Listening
174     [Documentation]    Example-ipv4-topology should be empty now.
175     [Tags]    critical
176     PrefixCounting.Check_Ipv4_Topology_Is_Empty
177
178 Restore_Data_Change_Counter_Configuration
179     [Documentation]    Configure data change counter back to count transactions affecting example-linkstate-topology.
180     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
181     ChangeCounter.Reconfigure_Topology_Name    example-linkstate-topology
182
183 Delete_Bgp_Peer_Configuration
184     [Documentation]    Revert the BGP configuration to the original state: without any configured peers.
185     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
186     ${template_as_string} =    BuiltIn.Set_Variable    {'NAME': 'example-bgp-peer'}
187     ConfigViaRestconf.Delete_Xml_Template_Folder_Config_Via_Restconf    ${BGP_VARIABLES_FOLDER}${/}bgp_peer    ${template_as_string}
188
189 *** Keywords ***
190 Setup_Everything
191     [Documentation]    Setup imported resources, SSH-login to tools system,
192     ...    create HTTP session, put Python tool to tools system.
193     SetupUtils.Setup_Utils_For_Setup_And_Teardown
194     ConfigViaRestconf.Setup_Config_Via_Restconf
195     ChangeCounter.CC_Setup
196     PrefixCounting.PC_Setup
197     SSHLibrary.Set_Default_Configuration    prompt=${TOOLS_SYSTEM_PROMPT}
198     SSHLibrary.Open_Connection    ${TOOLS_SYSTEM_IP}
199     Utils.Flexible_Mininet_Login
200     RequestsLibrary.Create_Session    operational    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}${OPERATIONAL_API}    auth=${AUTH}
201     # TODO: Do not include slash in ${OPERATIONAL_TOPO_API}, having it typed here is more readable.
202     # TODO: Alternatively, create variable in Variables which starts with http.
203     # Both TODOs would probably need to update every suite relying on current Variables.
204     SSHLibrary.Put_File    ${CURDIR}/../../../../tools/fastbgp/play.py
205     # Calculate the timeout value based on how many routes are going to be pushed
206     # TODO: Replace 20 with some formula from period and repetitions.
207     ${timeout} =    BuiltIn.Evaluate    ${TEST_DURATION_MULTIPLIER} * ${COUNT_CHANGE_COUNT} * 3.0 / 10000 + 20
208     Builtin.Set_Suite_Variable    ${bgp_filling_timeout}    ${timeout}
209     Builtin.Set_Suite_Variable    ${bgp_emptying_timeout}    ${bgp_filling_timeout*3.0/4}
210     KarafKeywords.Execute_Controller_Karaf_Command_On_Background    log:set ${CONTROLLER_LOG_LEVEL}
211     KarafKeywords.Execute_Controller_Karaf_Command_On_Background    log:set ${CONTROLLER_BGP_LOG_LEVEL} org.opendaylight.bgpcep
212     KarafKeywords.Execute_Controller_Karaf_Command_On_Background    log:set ${CONTROLLER_BGP_LOG_LEVEL} org.opendaylight.protocol
213
214 Teardown_Everything
215     [Documentation]    Make sure Python tool was killed and tear down imported Resources.
216     KillPythonTool.Search_And_Kill_Remote_Python    'play\.py'
217     ConfigViaRestconf.Teardown_Config_Via_Restconf
218     RequestsLibrary.Delete_All_Sessions
219     SSHLibrary.Close_All_Connections
220
221 Store_Change_Count
222     [Documentation]    Get the count of changes from BGP change counter. Ignore error or store the value.
223     ${status}    ${count} =    BuiltIn.Run_Keyword_And_Ignore_Error    ChangeCounter.Get_Change_Count
224     BuiltIn.Run_Keyword_If    '${status}' == 'PASS'    BuiltIn.Set_Suite_Variable    ${last_change_count}    ${count}
225
226 Store_File_To_Workspace
227     [Arguments]    ${src_file_name}    ${dst_file_name}
228     [Documentation]    Store the provided file from the SSH client to workspace.
229     ${files}=    SSHLibrary.List Files In Directory    .
230     ${output_log}=    SSHLibrary.Execute_Command    cat ${src_file_name}
231     BuiltIn.Log    ${output_log}
232     Create File    ${dst_file_name}    ${output_log}