Include needed Assure_* keywords in BGP tests
[integration/test.git] / csit / suites / bgpcep / bgpingest / singlepeer_prefixcount.robot
1 *** Settings ***
2 Documentation     BGP performance of ingesting from 1 iBGP peer, data change counter is NOT 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 ...               The suite consists of two halves, differing on which side initiates BGP connection.
15 ...               State of "work is being done" is detected by increasing value of prefixes in topology.
16 ...               The time for Wait_For_Stable_* cases to finish is the main performance metric.
17 ...               After waiting for stability is done, full check on number of prefixes present is performed.
18 ...
19 ...               TODO: Currently, if a bug causes prefix count to remain at zero,
20 ...               affected test cases will wait for max time. Reconsider.
21 ...               If zero is allowed as stable, higher period or repetitions would be required.
22 ...
23 ...               The prefix counting is quite heavyweight and may induce large variation in time.
24 ...               Try the other version of the suite (singlepeer_changecount.robot) to get better precision.
25 Suite Setup       Setup_Everything
26 Suite Teardown    Teardown_Everything
27 Test Setup        SetupUtils.Setup_Test_With_Logging_And_Fast_Failing
28 Test Teardown     SetupUtils.Teardown_Test_Show_Bugs_And_Start_Fast_Failing_If_Test_Failed
29 Library           SSHLibrary    timeout=10s
30 Library           RequestsLibrary
31 Variables         ${CURDIR}/../../../variables/Variables.py
32 Resource          ${CURDIR}/../../../libraries/BGPSpeaker.robot
33 Resource          ${CURDIR}/../../../libraries/ConfigViaRestconf.robot
34 Resource          ${CURDIR}/../../../libraries/FailFast.robot
35 Resource          ${CURDIR}/../../../libraries/KillPythonTool.robot
36 Resource          ${CURDIR}/../../../libraries/PrefixCounting.robot
37 Resource          ${CURDIR}/../../../libraries/SetupUtils.robot
38 Resource          ${CURDIR}/../../../libraries/SSHKeywords.robot
39
40 *** Variables ***
41 ${BGP_TOOL_LOG_LEVEL}    info
42 ${BGP_VARIABLES_FOLDER}    ${CURDIR}/../../../variables/bgpuser/
43 ${CHECK_PERIOD}    1
44 ${CHECK_PERIOD_PREFIX_COUNT}    ${CHECK_PERIOD}
45 ${CHECK_PERIOD_PREFIX_COUNT_SINGLE}    ${CHECK_PERIOD_PREFIX_COUNT}
46 ${COUNT}          1000000
47 ${COUNT_PREFIX_COUNT}    ${COUNT}
48 ${COUNT_PREFIX_COUNT_SINGLE}    ${COUNT_PREFIX_COUNT}
49 ${HOLDTIME}       180
50 ${HOLDTIME_PREFIX_COUNT}    ${HOLDTIME}
51 ${HOLDTIME_PREFIX_COUNT_SINGLE}    ${HOLDTIME_PREFIX_COUNT}
52 ${INSERT}         1
53 ${KARAF_LOG_LEVEL}    INFO
54 ${KARAF_BGPCEP_LOG_LEVEL}    ${KARAF_LOG_LEVEL}
55 ${KARAF_PROTOCOL_LOG_LEVEL}    ${KARAF_BGPCEP_LOG_LEVEL}
56 ${PREFILL}        0
57 ${REPETITIONS}    1
58 ${REPETITIONS_PREFIX_COUNT}    ${REPETITIONS}
59 ${REPETITIONS_PREFIX_COUNT_SINGLE}    ${REPETITIONS_PREFIX_COUNT}
60 ${RESULTS_FILE_NAME}    bgp.csv
61 ${TEST_DURATION_MULTIPLIER}    1
62 ${TEST_DURATION_MULTIPLIER_PREFIX_COUNT}    ${TEST_DURATION_MULTIPLIER}
63 ${TEST_DURATION_MULTIPLIER_PREFIX_COUNT_SINGLE}    ${TEST_DURATION_MULTIPLIER_PREFIX_COUNT}
64 ${UPDATE}         single
65 ${WITHDRAW}       0
66 # TODO: Option names can be better.
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_PREFIX_COUNT_SINGLE}', '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 Change_Karaf_Logging_Levels
81     [Documentation]    We may want to set more verbose logging here after configuration is done.
82     KarafKeywords.Set_Bgpcep_Log_Levels    bgpcep_level=${KARAF_BGPCEP_LOG_LEVEL}    protocol_level=${KARAF_PROTOCOL_LOG_LEVEL}
83
84 Start_Talking_BGP_Speaker
85     [Documentation]    Start Python speaker to connect to ODL.
86     # Myport value is needed for checking whether connection at precise port was established.
87     BGPSpeaker.Start_BGP_Speaker    --amount ${COUNT_PREFIX_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}
88
89 Wait_For_Stable_Talking_Ipv4_Topology
90     [Documentation]    Wait until example-ipv4-topology becomes stable. This is done by checking stability of prefix count.
91     PrefixCounting.Wait_For_Ipv4_Topology_Prefixes_To_Become_Stable    timeout=${bgp_filling_timeout}    period=${CHECK_PERIOD_PREFIX_COUNT_SINGLE}    repetitions=${REPETITIONS_PREFIX_COUNT_SINGLE}    excluded_count=0
92
93 Check_Talking_Ipv4_Topology_Count
94     [Documentation]    Count the routes in example-ipv4-topology and fail if the count is not correct.
95     [Tags]    critical
96     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
97     PrefixCounting.Check_Ipv4_Topology_Count    ${COUNT_PREFIX_COUNT_SINGLE}
98
99 Kill_Talking_BGP_Speaker
100     [Documentation]    Abort the Python speaker. Also, attempt to stop failing fast.
101     [Tags]    critical
102     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
103     BGPSpeaker.Kill_BGP_Speaker
104     FailFast.Do_Not_Fail_Fast_From_Now_On
105     # NOTE: It is still possible to remain failing fast, if both previous and this test have failed.
106     [Teardown]    SetupUtils.Teardown_Test_Show_Bugs_If_Test_Failed
107
108 Store_Results_For_Talking_BGP_Speaker
109     [Documentation]    Store results for plotting
110     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
111     Store_File_To_Workspace    totals-${RESULTS_FILE_NAME}    totals-${RESULTS_FILE_NAME}
112     Store_File_To_Workspace    performance-${RESULTS_FILE_NAME}    performance-${RESULTS_FILE_NAME}
113     Store_File_To_Workspace    totals-${RESULTS_FILE_NAME}    prefixcount-talking-totals-${RESULTS_FILE_NAME}
114     Store_File_To_Workspace    performance-${RESULTS_FILE_NAME}    prefixcount-talking-performance-${RESULTS_FILE_NAME}
115
116 Wait_For_Stable_Ipv4_Topology_After_Talking
117     [Documentation]    Wait until example-ipv4-topology becomes stable again.
118     [Tags]    critical
119     # TODO: Is is possible to have failed at Check_Talking_Ipv4_Topology_Count and still have initial period of constant count?
120     # FIXME: If yes, do count here to get the initial value and use it (if nonzero).
121     # TODO: If yes, decide whether access to the FailFast state should have keyword or just variable name.
122     PrefixCounting.Wait_For_Ipv4_Topology_Prefixes_To_Become_Stable    timeout=${bgp_filling_timeout}    period=${CHECK_PERIOD_PREFIX_COUNT_SINGLE}    repetitions=${REPETITIONS_PREFIX_COUNT_SINGLE}    excluded_count=${COUNT_PREFIX_COUNT_SINGLE}
123
124 Check_For_Empty_Ipv4_Topology_After_Talking
125     [Documentation]    Example-ipv4-topology should be empty now.
126     [Tags]    critical
127     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
128     PrefixCounting.Check_Ipv4_Topology_Is_Empty
129
130 Start_Listening_BGP_Speaker
131     [Documentation]    Start Python speaker in listening mode.
132     BGPSpeaker.Start_BGP_Speaker    --amount ${COUNT_PREFIX_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}
133
134 Reconfigure_ODL_To_Initiate_Connection
135     [Documentation]    Replace BGP peer config module, now with initiate-connection set to true.
136     ${template_as_string} =    BuiltIn.Set_Variable    {'NAME': 'example-bgp-peer', 'IP': '${TOOLS_SYSTEM_IP}', 'HOLDTIME': '${HOLDTIME_PREFIX_COUNT_SINGLE}', 'PEER_PORT': '${BGP_TOOL_PORT}', 'INITIATE': 'true'}
137     ConfigViaRestconf.Put_Xml_Template_Folder_Config_Via_Restconf    ${BGP_VARIABLES_FOLDER}${/}bgp_peer    ${template_as_string}
138
139 Wait_For_Stable_Listening_Ipv4_Topology
140     [Documentation]    Wait until example-ipv4-topology becomes stable.
141     PrefixCounting.Wait_For_Ipv4_Topology_Prefixes_To_Become_Stable    timeout=${bgp_filling_timeout}    period=${CHECK_PERIOD_PREFIX_COUNT_SINGLE}    repetitions=${REPETITIONS_PREFIX_COUNT_SINGLE}    excluded_count=0
142
143 Check_Listening_Ipv4_Topology_Count
144     [Documentation]    Count the routes in example-ipv4-topology and fail if the count is not correct.
145     [Tags]    critical
146     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
147     PrefixCounting.Check_Ipv4_Topology_Count    ${COUNT_PREFIX_COUNT_SINGLE}
148
149 Kill_Listening_BGP_Speaker
150     [Documentation]    Abort the Python speaker. Also, attempt to stop failing fast.
151     [Tags]    critical
152     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
153     BGPSpeaker.Kill_BGP_Speaker
154     FailFast.Do_Not_Fail_Fast_From_Now_On
155     # NOTE: It is still possible to remain failing fast, if both previous and this test have failed.
156     [Teardown]    SetupUtils.Teardown_Test_Show_Bugs_If_Test_Failed
157
158 Store_Results_For_Listening_BGP_Speaker
159     [Documentation]    Store results for plotting
160     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
161     Store_File_To_Workspace    totals-${RESULTS_FILE_NAME}    totals-${RESULTS_FILE_NAME}
162     Store_File_To_Workspace    performance-${RESULTS_FILE_NAME}    performance-${RESULTS_FILE_NAME}
163     Store_File_To_Workspace    totals-${RESULTS_FILE_NAME}    prefixcount-listening-totals-${RESULTS_FILE_NAME}
164     Store_File_To_Workspace    performance-${RESULTS_FILE_NAME}    prefixcount-listening-performance-${RESULTS_FILE_NAME}
165
166 Wait_For_Stable_Ipv4_Topology_After_Listening
167     [Documentation]    Wait until example-ipv4-topology becomes stable again.
168     [Tags]    critical
169     PrefixCounting.Wait_For_Ipv4_Topology_Prefixes_To_Become_Stable    timeout=${bgp_filling_timeout}    period=${CHECK_PERIOD_PREFIX_COUNT_SINGLE}    repetitions=${REPETITIONS_PREFIX_COUNT_SINGLE}    excluded_count=${COUNT_PREFIX_COUNT_SINGLE}
170
171 Check_For_Empty_Ipv4_Topology_After_Listening
172     [Documentation]    Example-ipv4-topology should be empty now.
173     [Tags]    critical
174     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
175     PrefixCounting.Check_Ipv4_Topology_Is_Empty
176
177 Restore_Karaf_Logging_Levels
178     [Documentation]    Set logging on bgpcep and protocol to the global value.
179     KarafKeywords.Set_Bgpcep_Log_Levels    bgpcep_level=${KARAF_LOG_LEVEL}    protocol_level=${KARAF_LOG_LEVEL}
180
181 Delete_Bgp_Peer_Configuration
182     [Documentation]    Revert the BGP configuration to the original state: without any configured peers.
183     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
184     ${template_as_string} =    BuiltIn.Set_Variable    {'NAME': 'example-bgp-peer'}
185     ConfigViaRestconf.Delete_Xml_Template_Folder_Config_Via_Restconf    ${BGP_VARIABLES_FOLDER}${/}bgp_peer    ${template_as_string}
186
187 *** Keywords ***
188 Setup_Everything
189     [Documentation]    Setup imported resources, SSH-login to tools system,
190     ...    create HTTP session, put Python tool to tools system.
191     SetupUtils.Setup_Utils_For_Setup_And_Teardown
192     ConfigViaRestconf.Setup_Config_Via_Restconf
193     PrefixCounting.PC_Setup
194     RequestsLibrary.Create_Session    operational    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}${OPERATIONAL_API}    auth=${AUTH}
195     # TODO: Do not include slash in ${OPERATIONAL_TOPO_API}, having it typed here is more readable.
196     # TODO: Alternatively, create variable in Variables which starts with http.
197     # Both TODOs would probably need to update every suite relying on current Variables.
198     SSHLibrary.Set_Default_Configuration    prompt=${TOOLS_SYSTEM_PROMPT}
199     SSHLibrary.Open_Connection    ${TOOLS_SYSTEM_IP}
200     Utils.Flexible_Mininet_Login
201     SSHKeywords.Require_Python
202     SSHKeywords.Assure_Library_Ipaddr    target_dir=.
203     SSHLibrary.Put_File    ${CURDIR}/../../../../tools/fastbgp/play.py
204     # Calculate the timeout value based on how many routes are going to be pushed
205     # TODO: Replace 20 with some formula from period and repetitions.
206     ${timeout} =    BuiltIn.Evaluate    ${TEST_DURATION_MULTIPLIER_PREFIX_COUNT_SINGLE} * (${COUNT_PREFIX_COUNT_SINGLE} * 3.0 / 10000 + 20)
207     Builtin.Set_Suite_Variable    ${bgp_filling_timeout}    ${timeout}
208     Builtin.Set_Suite_Variable    ${bgp_emptying_timeout}    ${bgp_filling_timeout*3.0/4}
209     KarafKeywords.Execute_Controller_Karaf_Command_On_Background    log:set ${KARAF_LOG_LEVEL}
210
211 Teardown_Everything
212     [Documentation]    Make sure Python tool was killed and tear down imported Resources.
213     # Environment issue may have dropped the SSH connection, but we do not want Teardown to fail.
214     BuiltIn.Run_Keyword_And_Ignore_Error    KillPythonTool.Search_And_Kill_Remote_Python    'play\.py'
215     ConfigViaRestconf.Teardown_Config_Via_Restconf
216     RequestsLibrary.Delete_All_Sessions
217     SSHLibrary.Close_All_Connections
218
219 Store_File_To_Workspace
220     [Arguments]    ${src_file_name}    ${dst_file_name}
221     [Documentation]    Store the provided file from the SSH client to workspace.
222     ${files}=    SSHLibrary.List Files In Directory    .
223     ${output_log}=    SSHLibrary.Execute_Command    cat ${src_file_name}
224     BuiltIn.Log    ${output_log}
225     Create File    ${dst_file_name}    ${output_log}