System test for Yangtools
[integration/test.git] / csit / libraries / BGPSpeaker.robot
1 *** Settings ***
2 Documentation     Robot keyword library (Resource) for handling the BGP speaker Python utilities.
3 ...
4 ...               Copyright (c) 2015,2017 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 library assumes that a SSH connection exists (and is switched to)
12 ...               to a Linux machine (usualy TOOLS_SYSTEM) where the Python BGP speaker should be run.
13 ...               It also assumes that the current working directory on that connection is the
14 ...               directory where the speaker tool was deployed as there are no paths to neither
15 ...               the play.py nor the log files in the commands.
16 ...
17 ...               Aside BGP Speaker utility, there is also BGP Manager starting utilities in parallel.
18 ...               For purpose of dumping logs and killing, Manager behaves the same as Speaker.
19 ...
20 ...               TODO: RemoteBash.robot contains logic which could be reused here.
21 ...
22 ...               TODO: Update the following TODOs, as SSHKeywords.robot was introduced.
23 ...               TODO: The Utils.robot library has a "Run Command On Remote System" if we didn't
24 ...               want to make the assumption that an SSH connection was already open.
25 ...               alternative TODO: Explain that it is not worth to perform separate SSH logins.
26 Library           SSHLibrary
27 Resource          ${CURDIR}/Utils.robot
28
29 *** Variables ***
30 ${BGPSpeaker__OUTPUT_LOG}    play.py.out
31
32 *** Keywords ***
33 Start_BGP_Speaker
34     [Arguments]    ${arguments}
35     [Documentation]    Start the BGP speaker python utility. Redirect its error output to a log file
36     ...    so it can be dumped into the logs later, when stopping it. This also avoids polluting the
37     ...    output seen by "Read Until Prompt" with false propmpts so it won't stop prematurely
38     ...    leading to a spurious test failure, messy log content or other misbehavior.
39     ${command} =    BuiltIn.Set_Variable    python play.py ${arguments} &> ${BGPSpeaker__OUTPUT_LOG}
40     BuiltIn.Log    ${command}
41     ${output} =    SSHLibrary.Write    ${command}
42
43 Start_BGP_Manager
44     [Arguments]    ${arguments}
45     [Documentation]    Start the BGP manager python utility. Redirect its error output to a log file.
46     ${command}=    BuiltIn.Set_Variable    python play.py ${arguments} &> ${BGPSpeaker__OUTPUT_LOG}
47     BuiltIn.Log    ${command}
48     ${output}=    SSHLibrary.Write    ${command}
49
50 Dump_BGP_Speaker_Logs
51     [Documentation]    Send all output produced by the play.py utility to Robot logs.
52     ...    This needs to be called if your suite detects play.py crashing and bypasses
53     ...    Kill_BGP_Speaker in that case otherwise the output of play.py (which most
54     ...    likely contains clues about why it crashed) will be lost.
55     ${output_log} =    SSHLibrary.Execute_Command    cat ${BGPSpeaker__OUTPUT_LOG}
56     BuiltIn.Log    ${output_log}
57
58 Kill_BGP_Speaker
59     [Documentation]    Interrupt play.py, fail if no prompt is seen within SSHLibrary timeout.
60     ...    Also dump the logs with the output the program produced.
61     ...    This keyword is also suitable for stopping BGP manager.
62     Utils.Write_Bare_Ctrl_C
63     ${status}    ${message} =    BuiltIn.Run_Keyword_And_Ignore_Error    SSHLibrary.Read_Until_Prompt
64     Dump_BGP_Speaker_Logs
65     # TODO: When Propagate_Failure is moved to better Resource, use it instead of the following.
66     BuiltIn.Return_From_Keyword_If    '${status}' == 'PASS'
67     BuiltIn.Log    ${message}
68     BuiltIn.Fail    The prompt was not seen within timeout period.