Migrate Get Requests invocations(libraries)
[integration/test.git] / csit / suites / bgpcep / bgpclustering / PrefixcountKeywords.robot
1 *** Settings ***
2 Documentation       BGP performance of ingesting from 1 iBGP peer, data change counter is NOT used.
3 ...
4 ...                 Copyright (c) 2016 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 ...                 For propper usage of this resource ${config_session} varaible has to be set.
11 ...                 It should point to http://<ip-addr>:${RESTCONFPORT}.
12
13 Library             SSHLibrary    timeout=10s
14 Library             RequestsLibrary
15 Resource            ../../../libraries/BGPcliKeywords.robot
16 Resource            ../../../libraries/BGPSpeaker.robot
17 Resource            ../../../libraries/ClusterAdmin.robot
18 Resource            ../../../libraries/ClusterManagement.robot
19 Resource            ../../../libraries/FailFast.robot
20 Resource            ../../../libraries/KillPythonTool.robot
21 Resource            ../../../libraries/PrefixCounting.robot
22 Resource            ../../../libraries/SetupUtils.robot
23 Resource            ../../../libraries/ShardStability.robot
24 Resource            ../../../libraries/SSHKeywords.robot
25 Resource            ../../../libraries/TemplatedRequests.robot
26 Resource            ../../../variables/Variables.robot
27
28
29 *** Variables ***
30 ${BGP_TOOL_LOG_LEVEL}           info
31 # used for configuration of bgp peer via openconfig
32 ${BGP_PEER_FOLDER}
33 ...                             ${CURDIR}/../../../variables/bgpclustering/bgp_peer_openconf
34 # used for configuration of bgp peer
35 ${BGP_VARIABLES_FOLDER}
36 ...                             ${CURDIR}/../../../variables/bgpclustering/${ODL_STREAM}/bgp_peer
37 ${BGP_VARIABLES_FOLDER_OP}      ${CURDIR}/../../../variables/bgpclustering/${ODL_STREAM}/bgp_peer_operational
38 ${CHECK_PERIOD}                 10
39 ${HOLDTIME}                     180
40 ${INSERT}                       1
41 ${KARAF_LOG_LEVEL}              INFO
42 ${KARAF_BGPCEP_LOG_LEVEL}       ${KARAF_LOG_LEVEL}
43 ${KARAF_PROTOCOL_LOG_LEVEL}     ${KARAF_BGPCEP_LOG_LEVEL}
44 ${PREFILL}                      0
45 ${REPETITIONS}                  1
46 ${RESULTS_FILE_NAME}            bgp.csv
47 ${TEST_DURATION_MULTIPLIER}     1
48 ${UPDATE}                       single
49 ${WITHDRAW}                     0
50 ${INITIAL_RESTCONF_TIMEOUT}     30s
51 ${KARAF_HOME}                   ${WORKSPACE}/${BUNDLEFOLDER}
52 ${SHARD_DEFAULT_CONFIG}         shard-default-config
53 ${SHARD_DEFAULT_OPERATIONAL}    shard-default-operational
54 ${EXAMPLE_IPV4_TOPOLOGY}        example-ipv4-topology
55 ${DEVICE_NAME}                  peer-controller-config
56 ${DEVICE_CHECK_TIMEOUT}         60s
57 ${RIB_INSTANCE}                 example-bgp-rib
58 ${PROTOCOL_OPENCONFIG}          ${RIB_INSTANCE}
59 ${BGP_PEER_NAME}                example-bgp-peer
60 @{SHARD_MONITOR_LIST}
61 ...                             default:config
62 ...                             default:operational
63 ...                             topology:config
64 ...                             topology:operational
65 ...                             inventory:config
66 ...                             inventory:operational
67
68
69 *** Keywords ***
70 Setup_Everything
71     [Documentation]    Setup imported resources, SSH-login to tools system,
72     ...    create HTTP session, put Python tool to tools system.
73     SetupUtils.Setup_Utils_For_Setup_And_Teardown    http_timeout=125
74     PrefixCounting.PC_Setup
75     ${indices} =    ClusterManagement.List_All_Indices
76     FOR    ${member_index}    IN    @{indices}
77         ${session} =    ClusterManagement.Resolve_Http_Session_For_Member    ${member_index}
78         BuiltIn.Set_Suite_Variable    ${operational_${member_index}}    ${session}
79     END
80     BuiltIn.Set_Suite_Variable    ${pc_all_indices}    ${indices}
81     SSHLibrary.Set_Default_Configuration    prompt=${TOOLS_SYSTEM_PROMPT}
82     SSHLibrary.Open_Connection    ${TOOLS_SYSTEM_IP}
83     SSHKeywords.Flexible_Mininet_Login
84     # TODO: Do not include slash in ${OPERATIONAL_TOPO_API}, having it typed here is more readable.
85     # TODO: Alternatively, create variable in Variables which starts with http.
86     # Both TODOs would probably need to update every suite relying on current Variables.
87     SSHLibrary.Put_File    ${CURDIR}/../../../../tools/fastbgp/play.py
88     SSHKeywords.Require_Python
89     SSHKeywords.Assure_Library_Ipaddr    target_dir=.
90     # Calculate the timeout value based on how many routes are going to be pushed
91     # TODO: Replace 35 with some formula from period and repetitions.
92     ${timeout} =    BuiltIn.Evaluate    ${TEST_DURATION_MULTIPLIER} * (${COUNT} * 6.0 / 10000 + 35)
93     Builtin.Set_Suite_Variable    ${bgp_filling_timeout}    ${timeout}
94     Builtin.Set_Suite_Variable    ${bgp_emptying_timeout}    ${bgp_filling_timeout*3.0/4}
95     KarafKeywords.Execute_Controller_Karaf_Command_On_Background    log:set ${KARAF_LOG_LEVEL}
96     ${init_shard_details} =    ShardStability.Shards_Stability_Get_Details    ${SHARD_MONITOR_LIST}
97     BuiltIn.Set_Suite_Variable    ${init_shard_details}
98
99 Teardown_Everything
100     [Documentation]    Make sure Python tool was killed and tear down imported Resources.
101     # TODO:    This keyword is not specific to prefix counting. Find a better place for it.
102     # Environment issue may have dropped the SSH connection, but we do not want Teardown to fail.
103     BuiltIn.Run_Keyword_And_Ignore_Error    KillPythonTool.Search_And_Kill_Remote_Python    'play\.py'
104     RequestsLibrary.Delete_All_Sessions
105     SSHLibrary.Close_All_Connections
106
107 Start_Bgp_Peer
108     [Documentation]    Starts bgp peer and verifies that the peer runs.
109     [Arguments]    ${peerip}=${rib_owner_node_id}
110     # TODO:    This keyword is not specific to prefix counting. Find a better place for it.
111     BGPSpeaker.Start_BGP_Speaker
112     ...    --amount ${COUNT} --myip=${TOOLS_SYSTEM_IP} --myport=${BGP_TOOL_PORT} --peerip=${peerip} --peerport=${ODL_BGP_PORT} --insert=${INSERT} --withdraw=${WITHDRAW} --prefill ${PREFILL} --update ${UPDATE} --${BGP_TOOL_LOG_LEVEL} --results ${RESULTS_FILE_NAME}
113
114 Start_Bgp_Peer_And_Verify_Connected
115     [Documentation]    Starts the peer and verifies its connection. The verification is done by checking the presence
116     ...    of the peer in the bgp rib.
117     [Arguments]    ${connection_retries}=${1}    ${peerip}=${rib_owner_node_id}
118     # TODO:    This keyword is not specific to prefix counting. Find a better place for it.
119     FOR    ${idx}    IN RANGE    ${connection_retries}
120         Start_Bgp_Peer    peerip=${peerip}
121         ${status}    ${value} =    BuiltIn.Run_Keyword_And_Ignore_Error
122         ...    BuiltIn.Wait_Until_Keyword_Succeeds
123         ...    3x
124         ...    3s
125         ...    Verify_Bgp_Peer_Connection
126         ...    ${config_session}
127         ...    ${TOOLS_SYSTEM_IP}
128         ...    connected=${True}
129         IF    "${status}" != "PASS"    BGPSpeaker.Kill_BGP_Speaker
130         IF    "${status}" == "PASS"    RETURN
131     END
132     BuiltIn.Fail    Unable to connect bgp peer to ODL
133
134 Verify_Bgp_Peer_Connection
135     [Documentation]    Checks peer presence in operational datastore
136     [Arguments]    ${session}    ${peer_ip}    ${connected}=${True}
137     # TODO:    This keyword is not specific to prefix counting. Find a better place for it.
138     ${peer_check_url} =    BuiltIn.Set_Variable    ${REST_API}/bgp-rib:bgp-rib/rib=example-bgp-rib/peer=bgp:%2F%2F
139     ${exp_status_code} =    BuiltIn.Set_Variable_If    ${connected}    200    404
140     ${rsp} =    RequestsLibrary.GET On Session    ${session}    url=${peer_check_url}${peer_ip}?content=nonconfig    expected_status=${exp_status_code}
141     BuiltIn.Log    ${rsp.content}
142
143 Set_Shard_Leaders_Location_And_Verify
144     [Documentation]    Move default/topology config/operational shard location to local or remote node as requested
145     ...    towards the given rib singleton instance location.
146     [Arguments]    ${requested_shard_localtion_idx}
147     ShardStability.Set_Shard_Location    ${requested_shard_localtion_idx}
148     BuiltIn.Wait_Until_Keyword_Succeeds
149     ...    30s
150     ...    5s
151     ...    ShardStability.Verify_Shard_Leader_Located_As_Expected
152     ...    ${requested_shard_localtion_idx}
153     ...    http_timeout=125
154     ${init_shard_details} =    ShardStability.Shards_Stability_Get_Details    ${SHARD_MONITOR_LIST}
155     BuiltIn.Set_Suite_Variable    ${init_shard_details}