Migrate Get Requests invocations(libraries)
[integration/test.git] / csit / suites / bgpcep / bgpingest / manypeers_changecount.robot
1 *** Settings ***
2 Documentation       BGP performance of ingesting from many iBGP peers, data change counter is used.
3 ...
4 ...                 Copyright (c) 2018 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 processes as iBGP peers.
12 ...                 This is analogue of single peer performance suite, which uses many peers.
13 ...                 Each peer is of ibgp type, and they contribute to the same example-bgp-rib,
14 ...                 and thus to the same single example-ipv4-topology.
15 ...                 The suite only looks at example-ipv4-topology, so RIB is not examined.
16 ...
17 ...                 This suite requires odl-bgpcep-data-change-counter to be installed so
18 ...                 make sure it is added to "install-features" of any jobs that are going to invoke it.
19 ...                 Use the other version of the suite (manypeers_prefixcount.robot) if the feature does not work.
20 ...
21 ...                 The suite consists of two halves, differing on which side initiates BGP connection.
22 ...                 Data change counter is a lightweight way to detect "work is being done".
23 ...                 WaitUtils provide a nice Keyword to wait for stability, but it needs
24 ...                 initial value, that is why Store_Change_Count appears just before work-inducing action.
25 ...                 The time for Wait_For_Stable_* cases to finish is the main performance metric.
26 ...                 After waiting for stability is done, full check on number of prefixes present is performed.
27 ...
28 ...                 TODO: Currently, if a bug causes zero increase of data changes,
29 ...                 affected test cases will wait for max time. Reconsider.
30 ...                 If zero increase is allowed as stable, higher number of repetitions should be required.
31 ...
32 ...                 ODL distinguishes peers by their IP addresses.
33 ...                 Currently, this suite requires python utils to be started on ODL System,
34 ...                 to guarantee IP address block is available for them to bind to.
35 ...                 TODO: Figure out how to use Docker and docker IP pool available in RelEng.
36 ...
37 ...                 Currently, 127.0.0.1 is hardcoded as the first peer address to use.
38 ...                 TODO: Figure out how to make it configurable.
39 ...                 As peer IP adresses are set incrementally, we need ipaddr to be used in Robot somehow.
40 ...
41 ...                 Brief description how to configure BGP peer can be found here:
42 ...                 https://wiki.opendaylight.org/view/BGP_LS_PCEP:User_Guide#BGP_Peer
43 ...                 http://docs.opendaylight.org/en/stable-boron/user-guide/bgp-user-guide.html#bgp-peering
44 ...
45 ...                 TODO: Is there a need for version of this suite where ODL connects to pers?
46 ...                 Note that configuring ODL is slow, which may affect measured performance singificantly.
47 ...                 Advanced TODO: Give manager ability to start pushing on trigger long after connections are established.
48
49 Library             DateTime
50 Library             RequestsLibrary
51 Library             SSHLibrary    timeout=10s
52 Resource            ../../../libraries/BGPcliKeywords.robot
53 Resource            ../../../libraries/BGPSpeaker.robot
54 Resource            ../../../libraries/ChangeCounter.robot
55 Resource            ../../../libraries/CompareStream.robot
56 Resource            ../../../libraries/FailFast.robot
57 Resource            ../../../libraries/KarafKeywords.robot
58 Resource            ../../../libraries/KillPythonTool.robot
59 Resource            ../../../libraries/PrefixCounting.robot
60 Resource            ../../../libraries/SetupUtils.robot
61 Resource            ../../../libraries/SSHKeywords.robot
62 Resource            ../../../libraries/TemplatedRequests.robot
63 Resource            ../../../libraries/Utils.robot
64 Resource            ../../../variables/Variables.robot
65
66 Suite Setup         Setup_Everything
67 Suite Teardown      Teardown_Everything
68 Test Setup          SetupUtils.Setup_Test_With_Logging_And_Fast_Failing
69 Test Teardown       SetupUtils.Teardown_Test_Show_Bugs_And_Start_Fast_Failing_If_Test_Failed
70
71
72 *** Variables ***
73 ${BGP_TOOL_LOG_LEVEL}                               info
74 ${BGP_VARIABLES_FOLDER}                             ${CURDIR}/../../../variables/bgpuser/
75 ${CHECK_PERIOD}                                     60
76 ${CHECK_PERIOD_CHANGE_COUNT}                        ${CHECK_PERIOD}
77 ${CHECK_PERIOD_CHANGE_COUNT_MANY}                   ${CHECK_PERIOD_CHANGE_COUNT}
78 ${COUNT}                                            600000
79 ${COUNT_CHANGE_COUNT}                               ${COUNT}
80 ${COUNT_CHANGE_COUNT_MANY}                          ${COUNT_CHANGE_COUNT}
81 ${FIRST_PEER_IP}                                    127.0.0.1
82 ${HOLDTIME}                                         180
83 ${HOLDTIME_CHANGE_COUNT}                            ${HOLDTIME}
84 ${HOLDTIME_CHANGE_COUNT_MANY}                       ${HOLDTIME_CHANGE_COUNT}
85 ${KARAF_LOG_LEVEL}                                  INFO
86 ${KARAF_BGPCEP_LOG_LEVEL}                           ${KARAF_LOG_LEVEL}
87 ${KARAF_PROTOCOL_LOG_LEVEL}                         ${KARAF_BGPCEP_LOG_LEVEL}
88 ${MULTIPLICITY}                                     2    # May be increased after Bug 4488 is fixed.
89 ${MULTIPLICITY_CHANGE_COUNT}                        ${MULTIPLICITY}
90 ${MULTIPLICITY_CHANGE_COUNT_MANY}                   ${MULTIPLICITY_CHANGE_COUNT}
91 ${PEER_GROUP}                                       internal-neighbors
92 ${REPETITIONS}                                      1    # Should be increased depending on multiplicity.
93 ${REPETITIONS_CHANGE_COUNT}                         ${REPETITIONS}
94 ${REPETITIONS_CHANGE_COUNT_MANY}                    ${REPETITIONS_CHANGE_COUNT}
95 ${TEST_DURATION_MULTIPLIER}                         1
96 ${TEST_DURATION_MULTIPLIER_CHANGE_COUNT}            ${TEST_DURATION_MULTIPLIER}
97 ${TEST_DURATION_MULTIPLIER_CHANGE_COUNT_MANY}       ${TEST_DURATION_MULTIPLIER_CHANGE_COUNT}
98 ${RIB_INSTANCE}                                     example-bgp-rib
99 ${PROTOCOL_OPENCONFIG}                              ${RIB_INSTANCE}
100 ${DEVICE_NAME}                                      controller-config
101 # TODO: Option names can be better.
102 ${last_change_count_many}                           1
103
104
105 *** Test Cases ***
106 Check_For_Empty_Ipv4_Topology_Before_Talking
107     [Documentation]    Wait for example-ipv4-topology to come up and empty. Give large timeout for case when BGP boots slower than restconf.
108     [Tags]    critical
109     # TODO: Choose which tags to assign and make sure they are assigned correctly.
110     BuiltIn.Wait_Until_Keyword_Succeeds    120s    1s    PrefixCounting.Check_Ipv4_Topology_Is_Empty
111
112 Reconfigure_ODL_To_Accept_Connections
113     [Documentation]    Configure BGP peer modules with initiate-connection set to false.
114     ...    It sets peer-group as template, and than sets all neighbors using it.
115     Configure_Peer_Group
116     FOR    ${index}    IN RANGE    1    ${MULTIPLICITY_CHANGE_COUNT_MANY}+1
117         ${peer_name} =    BuiltIn.Set_Variable    example-bgp-peer-${index}
118         ${peer_ip} =    BuiltIn.Evaluate    str(ipaddr.IPAddress('${FIRST_PEER_IP}') + ${index} - 1)    modules=ipaddr
119         &{mapping} =    Create Dictionary
120         ...    DEVICE_NAME=${DEVICE_NAME}
121         ...    BGP_NAME=${peer_name}
122         ...    IP=${peer_ip}
123         ...    HOLDTIME=${HOLDTIME_CHANGE_COUNT_MANY}
124         ...    PEER_PORT=${BGP_TOOL_PORT}
125         ...    INITIATE=false
126         ...    BGP_RIB=${RIB_INSTANCE}
127         ...    PASSIVE_MODE=true
128         ...    BGP_RIB_OPENCONFIG=${PROTOCOL_OPENCONFIG}
129         ...    RIB_INSTANCE_NAME=${RIB_INSTANCE}
130         ...    PEER_GROUP_NAME=${PEER_GROUP}
131         ...    RR_CLIENT=false
132         TemplatedRequests.Put_As_Xml_Templated    ${BGP_VARIABLES_FOLDER}${/}bgp_peer_group    mapping=${mapping}
133         # FIXME: Add testcase to change bgpcep and protocol log levels, when a Keyword that does it without messing with current connection is ready.
134     END
135
136 Reconfigure_Data_Change_Counter
137     [Documentation]    Configure data change counter to count transactions in example-ipv4-topology instead of example-linkstate-topology.
138     ChangeCounter.Reconfigure_Topology_Name    example-ipv4-topology
139
140 Verify_For_Data_Change_Counter_Ready
141     [Documentation]    Data change counter might have been slower to start than ipv4 topology, wait for it.
142     BuiltIn.Wait_Until_Keyword_Succeeds    5s    1s    ChangeCounter.Get_Change_Count
143
144 Change_Karaf_Logging_Levels
145     [Documentation]    We may want to set more verbose logging here after configuration is done.
146     KarafKeywords.Set_Bgpcep_Log_Levels
147     ...    bgpcep_level=${KARAF_BGPCEP_LOG_LEVEL}
148     ...    protocol_level=${KARAF_PROTOCOL_LOG_LEVEL}
149
150 Start_Talking_BGP_Manager
151     [Documentation]    Start Python manager to connect speakers to ODL.
152     Store_Change_Count
153     # Myport value is needed for checking whether connection at precise port was established.
154     BGPSpeaker.Start_BGP_Manager
155     ...    --amount=${COUNT_CHANGE_COUNT_MANY} --multiplicity=${MULTIPLICITY_CHANGE_COUNT_MANY} --myip=${FIRST_PEER_IP} --myport=${BGP_TOOL_PORT} --peerip=${ODL_SYSTEM_IP} --peerport=${ODL_BGP_PORT}
156
157 Wait_For_Stable_Talking_Ipv4_Topology
158     [Documentation]    Wait until example-ipv4-topology becomes stable. This is done by checking stability of the change counter.
159     ChangeCounter.Wait_For_Change_Count_To_Become_Stable
160     ...    timeout=${bgp_filling_timeout}
161     ...    period=${CHECK_PERIOD_CHANGE_COUNT_MANY}
162     ...    repetitions=${REPETITIONS_CHANGE_COUNT_MANY}
163     ...    count_to_overcome=${last_change_count_many}
164
165 Check_Talking_Ipv4_Topology_Count
166     [Documentation]    Count the routes in example-ipv4-topology and fail if the count is not correct.
167     [Tags]    critical
168     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
169     PrefixCounting.Check_Ipv4_Topology_Count    ${COUNT_CHANGE_COUNT_MANY}
170
171 Kill_Talking_BGP_Speakers
172     [Documentation]    Abort the Python speakers. Also, attempt to stop failing fast.
173     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
174     Store_Change_Count
175     BGPSpeaker.Kill_BGP_Speaker
176     BGPcliKeywords.Store_File_To_Workspace    play.py.out    manypeers_cc_play.log
177     FailFast.Do_Not_Fail_Fast_From_Now_On
178     # NOTE: It is still possible to remain failing fast, if both previous and this test have failed.
179     [Teardown]    SetupUtils.Teardown_Test_Show_Bugs_If_Test_Failed
180
181 Wait_For_Stable_Ipv4_Topology_After_Talking
182     [Documentation]    Wait until example-ipv4-topology becomes stable again.
183     [Tags]    critical
184     ChangeCounter.Wait_For_Change_Count_To_Become_Stable
185     ...    timeout=${bgp_filling_timeout}
186     ...    period=${CHECK_PERIOD_CHANGE_COUNT_MANY}
187     ...    repetitions=${REPETITIONS_CHANGE_COUNT_MANY}
188     ...    count_to_overcome=${last_change_count_many}
189
190 Check_For_Empty_Ipv4_Topology_After_Talking
191     [Documentation]    Example-ipv4-topology should be empty now.
192     [Tags]    critical
193     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
194     PrefixCounting.Check_Ipv4_Topology_Is_Empty
195
196 Restore_Karaf_Logging_Levels
197     [Documentation]    Set logging on bgpcep and protocol to the global value.
198     KarafKeywords.Set_Bgpcep_Log_Levels    bgpcep_level=${KARAF_LOG_LEVEL}    protocol_level=${KARAF_LOG_LEVEL}
199
200 Restore_Data_Change_Counter_Configuration
201     [Documentation]    Configure data change counter back to count transactions affecting example-linkstate-topology.
202     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
203     ChangeCounter.Reconfigure_Topology_Name    example-linkstate-topology
204
205 Delete_Bgp_Peer_Configuration
206     [Documentation]    Revert the BGP configuration to the original state: without any configured peers.
207     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
208     # TODO: Is it useful to extract peer naming logic to separate Keyword?
209     FOR    ${index}    IN RANGE    1    ${MULTIPLICITY_CHANGE_COUNT_MANY}+1
210         ${peer_name} =    BuiltIn.Set_Variable    example-bgp-peer-${index}
211         ${peer_ip} =    BuiltIn.Evaluate    str(ipaddr.IPAddress('${FIRST_PEER_IP}') + ${index} - 1)    modules=ipaddr
212         &{mapping} =    BuiltIn.Create_Dictionary
213         ...    DEVICE_NAME=${DEVICE_NAME}
214         ...    BGP_NAME=${peer_name}
215         ...    IP=${peer_ip}
216         ...    BGP_RIB_OPENCONFIG=${PROTOCOL_OPENCONFIG}
217         ...    PEER_GROUP_NAME=${PEER_GROUP}
218         ...    RR_CLIENT=false
219         TemplatedRequests.Delete_Templated    ${BGP_VARIABLES_FOLDER}${/}bgp_peer_group    mapping=${mapping}
220     END
221     Deconfigure_Peer_Group
222
223
224 *** Keywords ***
225 Setup_Everything
226     [Documentation]    Setup imported resources, SSH-login to ODL system,
227     ...    create HTTP session, put Python tool to ODL system.
228     SetupUtils.Setup_Utils_For_Setup_And_Teardown
229     TemplatedRequests.Create_Default_Session
230     ChangeCounter.CC_Setup
231     PrefixCounting.PC_Setup
232     KarafKeywords.Open Controller Karaf Console On Background
233     RequestsLibrary.Create_Session
234     ...    operational
235     ...    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}
236     ...    auth=${AUTH}
237     ...    timeout=125
238     ...    max_retries=0
239     # TODO: Do not include slash in ${OPERATIONAL_TOPO_API}, having it typed here is more readable.
240     # TODO: Alternatively, create variable in Variables which starts with http.
241     # Both TODOs would probably need to update every suite relying on current Variables.
242     SSHLibrary.Set_Default_Configuration    prompt=${ODL_SYSTEM_PROMPT}
243     SSHLibrary.Open_Connection    ${ODL_SYSTEM_IP}
244     SSHKeywords.Flexible_Controller_Login
245     SSHKeywords.Require_Python
246     SSHKeywords.Assure_Library_Ipaddr    target_dir=.
247     SSHLibrary.Put_File    ${CURDIR}/../../../../tools/fastbgp/play.py
248     # Calculate the timeout value based on how many routes are going to be pushed
249     ${period} =    DateTime.Convert_Time    ${CHECK_PERIOD_CHANGE_COUNT_MANY}    result_format=number
250     ${timeout} =    BuiltIn.Evaluate
251     ...    ${TEST_DURATION_MULTIPLIER_CHANGE_COUNT_MANY} * (${COUNT_CHANGE_COUNT_MANY} * 3.0 / 10000 + ${period} * (${REPETITIONS_CHANGE_COUNT_MANY} + 1)) + 20
252     Builtin.Set_Suite_Variable    ${bgp_filling_timeout}    ${timeout}
253     ${timeout} =    BuiltIn.Evaluate
254     ...    ${TEST_DURATION_MULTIPLIER_CHANGE_COUNT_MANY} * (${COUNT_CHANGE_COUNT_MANY} * 2.0 / 10000 + ${period} * (${REPETITIONS_CHANGE_COUNT_MANY} + 1)) + 20
255     Builtin.Set_Suite_Variable    ${bgp_emptying_timeout}    ${timeout}
256     KarafKeywords.Execute_Controller_Karaf_Command_On_Background    log:set ${KARAF_LOG_LEVEL}
257
258 Teardown_Everything
259     [Documentation]    Make sure Python tool was killed and tear down imported Resources.
260     # Environment issue may have dropped the SSH connection, but we do not want Teardown to fail.
261     BuiltIn.Run_Keyword_And_Ignore_Error    KillPythonTool.Search_And_Kill_Remote_Python    'play\.py'
262     BuiltIn.Run_Keyword_And_Ignore_Error    Utils.Get_Sysstat_Statistics
263     RequestsLibrary.Delete_All_Sessions
264     SSHLibrary.Close_All_Connections
265
266 Store_Change_Count
267     [Documentation]    Get the count of changes from BGP change counter. Ignore error or store the value.
268     ${status}    ${count} =    BuiltIn.Run_Keyword_And_Ignore_Error    ChangeCounter.Get_Change_Count
269     IF    '${status}' == 'PASS'
270         BuiltIn.Set_Suite_Variable    ${last_change_count_many}    ${count}
271     END
272
273 Configure_Peer_Group
274     [Documentation]    Configures peer group which is template for all the neighbors which are going
275     ...    to be configured. Also after PUT, this case verifies presence of peer group within
276     ...    peer-groups.
277     &{mapping} =    Create Dictionary
278     ...    DEVICE_NAME=${DEVICE_NAME}
279     ...    HOLDTIME=${HOLDTIME_CHANGE_COUNT_MANY}
280     ...    PEER_PORT=${BGP_TOOL_PORT}
281     ...    INITIATE=false
282     ...    BGP_RIB=${RIB_INSTANCE}
283     ...    PASSIVE_MODE=true
284     ...    BGP_RIB_OPENCONFIG=${PROTOCOL_OPENCONFIG}
285     ...    RIB_INSTANCE_NAME=${RIB_INSTANCE}
286     ...    PEER_GROUP_NAME=${PEER_GROUP}
287     ...    RR_CLIENT=false
288     ${verify_peer_group_folder} =    CompareStream.Run_Keyword_If_At_Least_Else
289     ...    sulfur
290     ...    BuiltIn.Set Variable
291     ...    verify_peer_group.sulfur
292     ...    ELSE
293     ...    BuiltIn.Set Variable
294     ...    verify_peer_group
295     TemplatedRequests.Put_As_Xml_Templated    ${BGP_VARIABLES_FOLDER}${/}peer_group    mapping=${mapping}
296     TemplatedRequests.Get_As_Json_Templated
297     ...    ${BGP_VARIABLES_FOLDER}${/}${verify_peer_group_folder}
298     ...    mapping=${mapping}
299     ...    verify=True
300
301 Deconfigure_Peer_Group
302     [Documentation]    Deconfigures peer group which is template for all the neighbors.
303     &{mapping} =    Create Dictionary
304     ...    DEVICE_NAME=${DEVICE_NAME}
305     ...    HOLDTIME=${HOLDTIME_CHANGE_COUNT_MANY}
306     ...    PEER_PORT=${BGP_TOOL_PORT}
307     ...    INITIATE=false
308     ...    BGP_RIB=${RIB_INSTANCE}
309     ...    PASSIVE_MODE=true
310     ...    BGP_RIB_OPENCONFIG=${PROTOCOL_OPENCONFIG}
311     ...    RIB_INSTANCE_NAME=${RIB_INSTANCE}
312     ...    PEER_GROUP_NAME=${PEER_GROUP}
313     ...    RR_CLIENT=false
314     TemplatedRequests.Delete_Templated    ${BGP_VARIABLES_FOLDER}${/}peer_group    mapping=${mapping}