BGP application peer functional suite documentation update.
[integration/test.git] / csit / suites / bgpcep / bgpuser / bgp_app_peer_basic.robot
1 *** Settings ***
2 Documentation     Basic tests for BGP application peer.
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 ...               Test suite performs basic BGP functional test cases for
11 ...               BGP application peer operations and checks for IP4 topology updates
12 ...               and updates towards BGP peer as follows:
13 ...
14 ...               Test case 1: Initial BGP peer connection with pre-filled topology (Bug 4714),
15 ...               POST and simple DELETE requests used. 
16 ...               BGP_Application_Peer_Post_3_Initial_Routes,
17 ...               Check_Example-IPv4-Topology_Is_Filled_With_3_Routes,
18 ...               Connect_BGP_Peer,
19 ...               BGP_Peer_Check_Incomming_Updates_For_3_Introduced_Prefixes,
20 ...               BGP_Application_Peer_Delete_3_Initial_Routes,
21 ...               Check_Example-IPv4-Topology_Is_Empty,
22 ...               Peer_Check_Incomming_Updates_For_3_Withdrawn_Prefixes,
23 ...               Stop_BGP_Peer.
24 ...
25 ...               Test case 2: PUT and DELETE all routes requests while BGP peer is connected.
26 ...               Reconnect_BGP_Peer,
27 ...               BGP_Application_Peer_Put_3_Routes,
28 ...               Check_Example-IPv4-Topology_Is_Filled_With_3_Routes,
29 ...               BGP_Peer_Check_Incomming_Updates_For_3_Introduced_Prefixes,
30 ...               BGP_Application_Peer_Delete_All_Routes,
31 ...               Check_Example-IPv4-Topology_Is_Empty,
32 ...               BGP_Peer_Check_Incomming_Updates_For_3_Withdrawn_Prefixes,
33 ...               Stop_BGP_Peer.
34 ...
35 ...               Test case 3: Repeated BGP peer re-connection with pre-filled topology.
36 ...               BGP_Application_Peer_Put_3_Routes,
37 ...               Check_Example-IPv4-Topology_Is_Filled_With_3_Routes,
38 ...               Reconnect_BGP_Peer_And_Check_Incomming_Updates_For_3_Introduced_Prefixes,
39 ...               BGP_Application_Peer_Delete_All_Routes,
40 ...               Check_Example-IPv4-Topology_Is_Empty,
41 ...               BGP_Peer_Check_Incomming_Updates_For_3_Withdrawn_Prefixes,
42 ...               Stop_BGP_Peer.
43 ...
44 ...               Brief description how to configure BGP application peer and
45 ...               how to use restconf application peer interface:
46 ...               https://wiki.opendaylight.org/view/BGP_LS_PCEP:User_Guide#BGP_Application_Peer
47 ...               https://wiki.opendaylight.org/view/BGP_LS_PCEP:Programmer_Guide#BGP
48 ...               Covered bugs:
49 ...               Bug 4714 - No routes from loc-rib are advertised to newly connected peer
50 Suite Setup       Setup_Everything
51 Suite Teardown    Teardown_Everything
52 Test Setup        SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
53 Test Teardown     FailFast.Start_Failing_Fast_If_This_Failed
54 Library           OperatingSystem
55 Library           SSHLibrary    timeout=10s
56 Library           RequestsLibrary
57 Library           ${CURDIR}/../../../libraries/HsfJson/hsf_json.py
58 Variables         ${CURDIR}/../../../variables/Variables.py
59 Variables         ${CURDIR}/../../../variables/bgpuser/variables.py    ${TOOLS_SYSTEM_IP}
60 Resource          ${CURDIR}/../../../libraries/BGPSpeaker.robot
61 Resource          ${CURDIR}/../../../libraries/ConfigViaRestconf.robot
62 Resource          ${CURDIR}/../../../libraries/FailFast.robot
63 Resource          ${CURDIR}/../../../libraries/KarafKeywords.robot
64 Resource          ${CURDIR}/../../../libraries/KillPythonTool.robot
65 Resource          ${CURDIR}/../../../libraries/SetupUtils.robot
66 Resource          ${CURDIR}/../../../libraries/SSHKeywords.robot
67 Resource          ${CURDIR}/../../../libraries/Utils.robot
68 Resource          ${CURDIR}/../../../libraries/WaitForFailure.robot
69
70 *** Variables ***
71 ${ACTUAL_RESPONSES_FOLDER}    ${TEMPDIR}/actual
72 ${EXPECTED_RESPONSES_FOLDER}    ${TEMPDIR}/expected
73 ${BGP_VARIABLES_FOLDER}    ${CURDIR}/../../../variables/bgpuser/
74 ${TOOLS_SYSTEM_PROMPT}    ${DEFAULT_LINUX_PROMPT}
75 ${HOLDTIME}       180
76 ${BGP_PEER_LOG_LEVEL}    debug
77 ${BGP_APP_PEER_LOG_LEVEL}    debug
78 ${CONTROLLER_LOG_LEVEL}    INFO
79 ${CONTROLLER_BGP_LOG_LEVEL}    DEFAULT
80 ${BGP_PEER_COMMAND}    python play.py --amount 0 --myip=${TOOLS_SYSTEM_IP} --myport=${BGP_TOOL_PORT} --peerip=${ODL_SYSTEM_IP} --peerport=${ODL_BGP_PORT} --${BGP_PEER_LOG_LEVEL}
81 ${BGP_PEER_OPTIONS}    ${EMPTY}
82 ${BGP_APP_PEER_ID}    10.0.0.10
83 ${BGP_APP_PEER_POST_COMMAND}    python bgp_app_peer.py --host ${ODL_SYSTEM_IP} --port ${RESTCONFPORT} --command post --count 3 --prefix 8.0.1.0 --prefixlen 28 --${BGP_APP_PEER_LOG_LEVEL}
84 ${BGP_APP_PEER_PUT_COMMAND}    python bgp_app_peer.py --host ${ODL_SYSTEM_IP} --port ${RESTCONFPORT} --command put --count 3 --prefix 8.0.1.0 --prefixlen 28 --${BGP_APP_PEER_LOG_LEVEL}
85 ${BGP_APP_PEER_DELETE_COMMAND}    python bgp_app_peer.py --host ${ODL_SYSTEM_IP} --port ${RESTCONFPORT} --command delete --count 3 --prefix 8.0.1.0 --prefixlen 28 --${BGP_APP_PEER_LOG_LEVEL}
86 ${BGP_APP_PEER_DELETE_ALL_COMMAND}    python bgp_app_peer.py --host ${ODL_SYSTEM_IP} --port ${RESTCONFPORT} --command delete-all --${BGP_APP_PEER_LOG_LEVEL}
87 ${BGP_APP_PEER_GET_COMMAND}    python bgp_app_peer.py --host ${ODL_SYSTEM_IP} --port ${RESTCONFPORT} --command get --${BGP_APP_PEER_LOG_LEVEL}
88 ${BGP_APP_PEER_OPTIONS}    &>/dev/null
89 ${BGP_APP_PEER_TIMEOUT}    30s
90
91 *** Test Cases ***
92 Reconfigure_ODL_To_Accept_BGP_Peer_Connection
93     [Documentation]    Configure BGP peer module with initiate-connection set to false.
94     [Tags]    critical
95     ${template_as_string}=    BuiltIn.Set_Variable    {'NAME': 'example-bgp-peer', 'IP': '${TOOLS_SYSTEM_IP}', 'HOLDTIME': '${HOLDTIME}', 'PEER_PORT': '${BGP_TOOL_PORT}', 'INITIATE': 'false'}
96     ConfigViaRestconf.Put_Xml_Template_Folder_Config_Via_Restconf    ${BGP_VARIABLES_FOLDER}${/}bgp_peer    ${template_as_string}
97
98 Reconfigure_ODL_To_Accept_BGP_Application_Peer
99     [Documentation]    Configure BGP application peer module.
100     [Tags]    critical
101     ${template_as_string}=    BuiltIn.Set_Variable    {'NAME': 'example-bgp-peer-app', 'IP': '${BGP_APP_PEER_ID}'}
102     ConfigViaRestconf.Put_Xml_Template_Folder_Config_Via_Restconf    ${BGP_VARIABLES_FOLDER}${/}bgp_application_peer    ${template_as_string}
103
104 Check_For_Empty_Example-IPv4-Topology
105     [Documentation]    Sanity check example-ipv4-topology is up but empty.
106     [Tags]    critical
107     Wait_For_Topology_To_Change_To    ${empty_json}    000_Empty.json    timeout=120s
108
109 TC1_BGP_Application_Peer_Post_3_Initial_Routes
110     [Documentation]    Start BGP application peer tool and give it ${BGP_APP_PEER_TIMEOUT}
111     [Tags]    critical
112     Switch_To_BGP_Application_Peer_Console
113     Start_Console_Tool    ${BGP_APP_PEER_POST_COMMAND}    ${BGP_APP_PEER_OPTIONS}
114     Wait_Until_Console_Tool_Finish    ${BGP_APP_PEER_TIMEOUT}
115     Store_File_To_Workspace    bgp_app_peer.log    bgp_app_peer_initial_post_tc1.log
116
117 TC1_Check_Example-IPv4-Topology_Is_Filled_With_3_Routes
118     [Documentation]    See new routes in example-ipv4-topology as a proof that synchronization was correct.
119     [Tags]    critical
120     Wait_For_Topology_To_Change_To    ${filled_json}    010_Filled.json
121
122 TC1_Connect_BGP_Peer
123     [Documentation]    Start BGP peer tool
124     [Tags]    critical
125     Switch_To_BGP_Peer_Console
126     Start_Console_Tool    ${BGP_PEER_COMMAND}    ${BGP_PEER_OPTIONS}
127     Read_And_Fail_If_Prompt_Is_Seen
128
129 TC1_BGP_Peer_Check_Incomming_Updates_For_3_Introduced_Prefixes
130     [Documentation]    Check incomming updates for new routes
131     [Tags]    critical
132     Switch_To_BGP_Peer_Console
133     BuiltIn.Wait_Until_Keyword_Succeeds    60s    1s    Check_File_For_Word_Count    bgp_peer.log    nlri_prefix_received:    3
134     Check_File_For_Word_Count    bgp_peer.log    nlri_prefix_received: 8.0.1.0/28    1
135     Check_File_For_Word_Count    bgp_peer.log    nlri_prefix_received: 8.0.1.16/28    1
136     Check_File_For_Word_Count    bgp_peer.log    nlri_prefix_received: 8.0.1.32/28    1
137     Check_File_For_Word_Count    bgp_peer.log    withdrawn_prefix_received:    0
138     [Teardown]    Report_Failure_Due_To_Bug    4714
139
140 TC1_BGP_Application_Peer_Delete_3_Initial_Routes
141     [Documentation]    Start BGP application peer tool and give him ${BGP_APP_PEER_TIMEOUT}
142     [Tags]    critical
143     Switch_To_BGP_Application_Peer_Console
144     Start_Console_Tool    ${BGP_APP_PEER_DELETE_COMMAND}    ${BGP_APP_PEER_OPTIONS}
145     Wait_Until_Console_Tool_Finish    ${BGP_APP_PEER_TIMEOUT}
146     Store_File_To_Workspace    bgp_app_peer.log    bgp_app_peer_delete_tc1.log
147
148 TC1_Check_Example-IPv4-Topology_Is_Empty
149     [Documentation]    See new routes are deleted.
150     [Tags]    critical
151     Wait_For_Topology_To_Change_To    ${empty_json}    011_Empty.json
152
153 TC1_Peer_Check_Incomming_Updates_For_3_Withdrawn_Prefixes
154     [Documentation]    Check incomming updates for new routes
155     [Tags]    critical
156     Switch_To_BGP_Peer_Console
157     BuiltIn.Wait_Until_Keyword_Succeeds    60s    1s    Check_File_For_Word_Count    bgp_peer.log    withdrawn_prefix_received:    3
158     Check_File_For_Word_Count    bgp_peer.log    withdrawn_prefix_received: 8.0.1.0/28    1
159     Check_File_For_Word_Count    bgp_peer.log    withdrawn_prefix_received: 8.0.1.16/28    1
160     Check_File_For_Word_Count    bgp_peer.log    withdrawn_prefix_received: 8.0.1.32/28    1
161     Check_File_For_Word_Count    bgp_peer.log    nlri_prefix_received:    3
162     [Teardown]    Report_Failure_Due_To_Bug    4714
163
164 TC1_Stop_BGP_Peer
165     [Documentation]    Stop BGP peer tool
166     [Tags]    critical
167     Switch_To_BGP_Peer_Console
168     Stop_Console_Tool
169     Store_File_To_Workspace    bgp_peer.log    bgp_peer_tc1.log
170
171 TC2_Reconnect_BGP_Peer
172     [Documentation]    Start BGP peer tool
173     [Tags]    critical
174     Switch_To_BGP_Peer_Console
175     Start_Console_Tool    ${BGP_PEER_COMMAND}    ${BGP_PEER_OPTIONS}
176     Read_And_Fail_If_Prompt_Is_Seen
177     Check_File_For_Word_Count    bgp_peer.log    nlri_prefix_received:    0
178     Check_File_For_Word_Count    bgp_peer.log    withdrawn_prefix_received:    0
179
180 TC2_BGP_Application_Peer_Put_3_Routes
181     [Documentation]    Start BGP application peer tool and give him ${BGP_APP_PEER_TIMEOUT}
182     [Tags]    critical
183     Switch_To_BGP_Application_Peer_Console
184     Start_Console_Tool    ${BGP_APP_PEER_PUT_COMMAND}    ${BGP_APP_PEER_OPTIONS}
185     Wait_Until_Console_Tool_Finish    ${BGP_APP_PEER_TIMEOUT}
186     Store_File_To_Workspace    bgp_app_peer.log    bgp_app_peer_put_tc2.log
187
188 TC2_Check_Example-IPv4-Topology_Is_Filled_With_3_Routes
189     [Documentation]    See new routes in example-ipv4-topology as a proof that synchronization was correct.
190     [Tags]    critical
191     Wait_For_Topology_To_Change_To    ${filled_json}    020_Filled.json
192
193 TC2_BGP_Peer_Check_Incomming_Updates_For_3_Introduced_Prefixes
194     [Documentation]    Check incomming updates for new routes
195     [Tags]    critical
196     Switch_To_BGP_Peer_Console
197     BuiltIn.Wait_Until_Keyword_Succeeds    60s    1s    Check_File_For_Word_Count    bgp_peer.log    nlri_prefix_received:    3
198     Check_File_For_Word_Count    bgp_peer.log    nlri_prefix_received: 8.0.1.0/28    1
199     Check_File_For_Word_Count    bgp_peer.log    nlri_prefix_received: 8.0.1.16/28    1
200     Check_File_For_Word_Count    bgp_peer.log    nlri_prefix_received: 8.0.1.32/28    1
201     Check_File_For_Word_Count    bgp_peer.log    withdrawn_prefix_received:    0
202
203 TC2_BGP_Application_Peer_Delete_All_Routes
204     [Documentation]    Start BGP application peer tool and give him ${BGP_APP_PEER_TIMEOUT}
205     [Tags]    critical
206     Switch_To_BGP_Application_Peer_Console
207     Start_Console_Tool    ${BGP_APP_PEER_DELETE_ALL_COMMAND}    ${BGP_APP_PEER_OPTIONS}
208     Wait_Until_Console_Tool_Finish    ${BGP_APP_PEER_TIMEOUT}
209     Store_File_To_Workspace    bgp_app_peer.log    bgp_app_peer_delete_all_tc2.log
210
211 TC2_Check_Example-IPv4-Topology_Is_Empty
212     [Documentation]    See new routes are deleted.
213     [Tags]    critical
214     Wait_For_Topology_To_Change_To    ${empty_json}    021_Empty.json
215
216 TC2_BGP_Peer_Check_Incomming_Updates_For_3_Withdrawn_Prefixes
217     [Documentation]    Check incomming updates for new routes
218     [Tags]    critical
219     Switch_To_BGP_Peer_Console
220     BuiltIn.Wait_Until_Keyword_Succeeds    60s    1s    Check_File_For_Word_Count    bgp_peer.log    withdrawn_prefix_received:    3
221     Check_File_For_Word_Count    bgp_peer.log    withdrawn_prefix_received: 8.0.1.0/28    1
222     Check_File_For_Word_Count    bgp_peer.log    withdrawn_prefix_received: 8.0.1.16/28    1
223     Check_File_For_Word_Count    bgp_peer.log    withdrawn_prefix_received: 8.0.1.32/28    1
224     Check_File_For_Word_Count    bgp_peer.log    nlri_prefix_received:    3
225
226 TC2_Stop_BGP_Peer
227     [Documentation]    Stop BGP peer tool
228     [Tags]    critical
229     Switch_To_BGP_Peer_Console
230     Stop_Console_Tool
231     Store_File_To_Workspace    bgp_peer.log    bgp_peer_tc2.log
232
233 TC3_BGP_Application_Peer_Put_3_Routes
234     [Documentation]    Start BGP application peer tool and give him ${BGP_APP_PEER_TIMEOUT}
235     [Tags]    critical
236     Switch_To_BGP_Application_Peer_Console
237     Start_Console_Tool    ${BGP_APP_PEER_PUT_COMMAND}    ${BGP_APP_PEER_OPTIONS}
238     Wait_Until_Console_Tool_Finish    ${BGP_APP_PEER_TIMEOUT}
239     Store_File_To_Workspace    bgp_app_peer.log    bgp_app_peer_put_tc3.log
240
241 TC3_Check_Example-IPv4-Topology_Is_Filled_With_3_Routes
242     [Documentation]    See new routes in example-ipv4-topology as a proof that synchronization was correct.
243     [Tags]    critical
244     Wait_For_Topology_To_Change_To    ${filled_json}    030_Filled.json
245
246 TC3_Reconnect_BGP_Peer_And_Check_Incomming_Updates_For_3_Introduced_Prefixes
247     [Documentation]    Start BGP peer tool
248     [Tags]    critical
249     Switch_To_BGP_Peer_Console
250     Start_Console_Tool    ${BGP_PEER_COMMAND}    ${BGP_PEER_OPTIONS}
251     Read_And_Fail_If_Prompt_Is_Seen
252     BuiltIn.Wait_Until_Keyword_Succeeds    60s    1s    Check_File_For_Word_Count    bgp_peer.log    nlri_prefix_received:    3
253     Check_File_For_Word_Count    bgp_peer.log    nlri_prefix_received:    3
254     Check_File_For_Word_Count    bgp_peer.log    nlri_prefix_received: 8.0.1.0/28    1
255     Check_File_For_Word_Count    bgp_peer.log    nlri_prefix_received: 8.0.1.16/28    1
256     Check_File_For_Word_Count    bgp_peer.log    nlri_prefix_received: 8.0.1.32/28    1
257     Check_File_For_Word_Count    bgp_peer.log    withdrawn_prefix_received:    0
258
259 TC3_BGP_Application_Peer_Delete_All_Routes
260     [Documentation]    Start BGP application peer tool and give him ${BGP_APP_PEER_TIMEOUT}
261     [Tags]    critical
262     Switch_To_BGP_Application_Peer_Console
263     Start_Console_Tool    ${BGP_APP_PEER_DELETE_ALL_COMMAND}    ${BGP_APP_PEER_OPTIONS}
264     Wait_Until_Console_Tool_Finish    ${BGP_APP_PEER_TIMEOUT}
265     Store_File_To_Workspace    bgp_app_peer.log    bgp_app_peer_delete_all_tc3.log
266
267 TC3_Check_Example-IPv4-Topology_Is_Empty
268     [Documentation]    See new routes are deleted.
269     [Tags]    critical
270     Wait_For_Topology_To_Change_To    ${empty_json}    031_Empty.json
271
272 TC3_BGP_Peer_Check_Incomming_Updates_For_3_Withdrawn_Prefixes
273     [Documentation]    Check incomming updates for new routes
274     [Tags]    critical
275     Switch_To_BGP_Peer_Console
276     BuiltIn.Wait_Until_Keyword_Succeeds    60s    1s    Check_File_For_Word_Count    bgp_peer.log    withdrawn_prefix_received:    3
277     Check_File_For_Word_Count    bgp_peer.log    withdrawn_prefix_received: 8.0.1.0/28    1
278     Check_File_For_Word_Count    bgp_peer.log    withdrawn_prefix_received: 8.0.1.16/28    1
279     Check_File_For_Word_Count    bgp_peer.log    withdrawn_prefix_received: 8.0.1.32/28    1
280     Check_File_For_Word_Count    bgp_peer.log    nlri_prefix_received:    3
281
282 TC3_Stop_BGP_Peer
283     [Documentation]    Stop BGP peer tool
284     [Tags]    critical
285     Switch_To_BGP_Peer_Console
286     Stop_Console_Tool
287     Store_File_To_Workspace    bgp_peer.log    bgp_peer_tc3.log
288
289 Delete_Bgp_Peer_Configuration
290     [Documentation]    Revert the BGP configuration to the original state: without any configured peers.
291     [Tags]    critical
292     ${template_as_string}=    BuiltIn.Set_Variable    {'NAME': 'example-bgp-peer'}
293     ConfigViaRestconf.Delete_Xml_Template_Folder_Config_Via_Restconf    ${BGP_VARIABLES_FOLDER}${/}bgp_peer    ${template_as_string}
294
295 Delete_Bgp_Application_Peer_Configuration
296     [Documentation]    Revert the BGP configuration to the original state: without any configured peers.
297     [Tags]    critical
298     ${template_as_string}=    BuiltIn.Set_Variable    {'NAME': 'example-bgp-peer-app'}
299     ConfigViaRestconf.Delete_Xml_Template_Folder_Config_Via_Restconf    ${BGP_VARIABLES_FOLDER}${/}bgp_application_peer    ${template_as_string}
300
301 *** Keywords ***
302 Setup_Everything
303     [Documentation]    SSH-login to mininet machine, create HTTP session,
304     ...    prepare directories for responses, put Python tool to mininet machine, setup imported resources.
305     SetupUtils.Setup_Utils_For_Setup_And_Teardown
306     SSHLibrary.Set_Default_Configuration    prompt=${TOOLS_SYSTEM_PROMPT}
307     Open_BGP_Peer_Console
308     SSHLibrary.Put_File    ${CURDIR}/../../../../tools/fastbgp/play.py
309     Open_BGP_Aplicationp_Peer_Console
310     SSHLibrary.Put_File    ${CURDIR}/../../../../tools/fastbgp/bgp_app_peer.py
311     SSHLibrary.Put_File    ${CURDIR}/../../../../tools/fastbgp/ipv4-routes-template.xml
312     OperatingSystem.Remove_Directory    ${EXPECTED_RESPONSES_FOLDER}    recursive=True
313     OperatingSystem.Remove_Directory    ${ACTUAL_RESPONSES_FOLDER}    recursive=True
314     # The previous suite may have been using the same directories.
315     OperatingSystem.Create_Directory    ${EXPECTED_RESPONSES_FOLDER}
316     OperatingSystem.Create_Directory    ${ACTUAL_RESPONSES_FOLDER}
317     RequestsLibrary.Create_Session    operational    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}${OPERATIONAL_TOPO_API}    auth=${AUTH}
318     ConfigViaRestconf.Setup_Config_Via_Restconf
319     KarafKeywords.Execute_Controller_Karaf_Command_On_Background    log:set ${CONTROLLER_LOG_LEVEL}
320     KarafKeywords.Execute_Controller_Karaf_Command_On_Background    log:set ${CONTROLLER_BGP_LOG_LEVEL} org.opendaylight.bgpcep
321     KarafKeywords.Execute_Controller_Karaf_Command_On_Background    log:set ${CONTROLLER_BGP_LOG_LEVEL} org.opendaylight.protocol
322
323 Teardown_Everything
324     [Documentation]    Create and Log the diff between expected and actual responses, make sure Python tool was killed.
325     ...    Tear down imported Resources.
326     ${diff}=    OperatingSystem.Run    diff -dur ${EXPECTED_RESPONSES_FOLDER} ${ACTUAL_RESPONSES_FOLDER}
327     BuiltIn.Log    ${diff}
328     KillPythonTool.Search_And_Kill_Remote_Python    'play\.py'
329     KillPythonTool.Search_And_Kill_Remote_Python    'bgp_app_peer\.py'
330     ConfigViaRestconf.Teardown_Config_Via_Restconf
331     RequestsLibrary.Delete_All_Sessions
332     SSHLibrary.Close_All_Connections
333
334 Open_BGP_Peer_Console
335     [Documentation]    Create a session for BGP peer.
336     SSHLibrary.Open_Connection    ${TOOLS_SYSTEM_IP}    alias=bgp_peer_console
337     Utils.Flexible_Mininet_Login
338
339 Open_BGP_Aplicationp_Peer_Console
340     [Documentation]    Create a session for BGP peer.
341     SSHLibrary.Open_Connection    ${TOOLS_SYSTEM_IP}    alias=bgp_app_peer_console
342     Utils.Flexible_Mininet_Login
343
344 Switch_To_BGP_Peer_Console
345     SSHLibrary.Switch Connection    bgp_peer_console
346
347 Switch_To_BGP_Application_Peer_Console
348     SSHLibrary.Switch Connection    bgp_app_peer_console
349
350 Start_Console_Tool
351     [Arguments]    ${command}    ${tool_opt}
352     [Documentation]    Start the tool ${command} ${tool_opt}
353     BuiltIn.Log    ${command}
354     ${output}=    SSHLibrary.Write    ${command} ${tool_opt}
355     BuiltIn.Log    ${output}
356
357 Wait_Until_Console_Tool_Finish
358     [Arguments]    ${timeout}
359     [Documentation]    Wait ${timeout} for the tool exit.
360     BuiltIn.Wait Until Keyword Succeeds    ${timeout}    1s    SSHLibrary.Read Until Prompt
361
362 Stop_Console_Tool
363     [Documentation]    Stop the tool if still running.
364     Utils.Write_Bare_Ctrl_C
365     ${output}=    SSHLibrary.Read    delay=1s
366     BuiltIn.Log    ${output}
367
368 Wait_For_Topology_To_Change_To
369     [Arguments]    ${json_topology}    ${filename}    ${timeout}=10s    ${refresh}=1s
370     [Documentation]    Normalize the expected json topology and save it to ${EXPECTED_RESPONSES_FOLDER}.
371     ...    Wait until Compare_Topology matches. ${ACTUAL_RESPONSES_FOLDER} will hold its last result.
372     ${topology_normalized}=    Normalize_And_Save_Expected_Json    ${json_topology}    ${filename}    ${EXPECTED_RESPONSES_FOLDER}
373     BuiltIn.Wait_Until_Keyword_Succeeds    ${timeout}    ${refresh}    Compare_Topology    ${topology_normalized}    ${filename}
374
375 Verify_That_Topology_Does_Not_Change_From
376     [Arguments]    ${json_topology}    ${filename}    ${timeout}=10s    ${refresh}=1s
377     [Documentation]    Normalize the expected json topology and save it to ${EXPECTED_RESPONSES_FOLDER}.
378     ...    Verify that Compare_Topology keeps passing. ${ACTUAL_RESPONSES_FOLDER} will hold its last result.
379     ${topology_normalized}=    Normalize_And_Save_Expected_Json    ${json_topology}    ${filename}    ${EXPECTED_RESPONSES_FOLDER}
380     WaitForFailure.Verify_Keyword_Does_Not_Fail_Within_Timeout    ${timeout}    ${refresh}    Compare_Topology    ${topology_normalized}    ${filename}
381
382 Compare_Topology
383     [Arguments]    ${expected_normalized}    ${filename}
384     [Documentation]    Get current example-ipv4-topology as json, normalize it, save to ${ACTUAL_RESPONSES_FOLDER}.
385     ...    Check that status code is 200, check that normalized jsons match exactly.
386     ${response}=    RequestsLibrary.Get Request    operational    topology/example-ipv4-topology
387     BuiltIn.Log    ${response.status_code}
388     BuiltIn.Log    ${response.text}
389     ${actual_normalized}=    Normalize_And_Save_Expected_Json    ${response.text}    ${filename}    ${ACTUAL_RESPONSES_FOLDER}
390     BuiltIn.Should_Be_Equal_As_Strings    ${response.status_code}    200
391     BuiltIn.Should_Be_Equal    ${actual_normalized}    ${expected_normalized}
392
393 Normalize_And_Save_Expected_Json
394     [Arguments]    ${json_text}    ${filename}    ${directory}
395     [Documentation]    Normalize given json using hsf_json library. Log and save the result to given filename under given directory.
396     ${json_normalized}=    hsf_json.Hsf_Json    ${json_text}
397     BuiltIn.Log    ${json_normalized}
398     OperatingSystem.Create_File    ${directory}${/}${filename}    ${json_normalized}
399     # TODO: Should we prepend .json to the filename? When we detect it is not already prepended?
400     [Return]    ${json_normalized}
401
402 Read_And_Fail_If_Prompt_Is_Seen
403     [Documentation]    Try to read SSH to see prompt, but expect to see no prompt within SSHLibrary's timeout.
404     ${passed}=    BuiltIn.Run_Keyword_And_Return_Status    BuiltIn.Run_Keyword_And_Expect_Error    No match found for '${TOOLS_SYSTEM_PROMPT}' in *.    Read_Text_Before_Prompt
405     BuiltIn.Return_From_Keyword_If    ${passed}
406     BGPSpeaker.Dump_BGP_Speaker_Logs
407     Builtin.Fail    The prompt was seen but it was not expected yet
408
409 Read_Text_Before_Prompt
410     [Documentation]    Log text gathered by SSHLibrary.Read_Until_Prompt.
411     ...    This needs to be a separate keyword just because how Read_And_Fail_If_Prompt_Is_Seen is implemented.
412     ${text}=    SSHLibrary.Read_Until_Prompt
413     BuiltIn.Log    ${text}
414
415 Store_File_To_Workspace
416     [Arguments]    ${source_file_name}    ${target_file_name}
417     [Documentation]    Store the ${source_file_name} to the workspace as ${target_file_name}.
418     ${output_log}=    SSHLibrary.Execute_Command    cat ${source_file_name}
419     BuiltIn.Log    ${output_log}
420     Create File    ${target_file_name}    ${output_log}
421
422 Check_File_For_Word_Count
423     [Arguments]    ${file_name}    ${word}    ${expected_count}
424     [Documentation]    Count ${word} in ${file_name}. Expect ${expected_count} occurence(s)
425     ${output_log}=    SSHLibrary.Execute_Command    grep -o '${word}' ${file_name} | wc -l
426     BuiltIn.Log    ${output_log}
427     BuiltIn.Should_Be_Equal_As_Strings    ${output_log}    ${expected_count}