2 Documentation Robot keyword library (Resource) for handling the BGP speaker CLI tools
4 ... Copyright (c) 2015,2017 Cisco Systems, Inc. and others. All rights reserved.
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
10 ... This library contains keywords to handle command line tools in BGP Application
11 ... for handling shell connections.
13 ... TODO: RemoteBash.robot contains logic which could be reused here.
15 Library SSHLibrary timeout=10s
16 Library RequestsLibrary
17 Resource ../variables/Variables.robot
18 Resource BGPSpeaker.robot
19 Resource RemoteBash.robot
20 Resource NexusKeywords.robot
25 [Documentation] Start the tool ${command} ${tool_opt}
26 [Arguments] ${command} ${tool_opt}
27 ${start_cmd}= BuiltIn.Set_Variable ${command} ${tool_opt}
28 BuiltIn.Log ${start_cmd}
29 ${output}= SSHLibrary.Write ${start_cmd}
32 Start_Java_Tool_And_Verify_Connection
33 [Arguments] ${command} ${until_phrase}
34 ${start_cmd}= NexusKeywords.Compose_Full_Java_Command ${command}
35 BuiltIn.Log ${start_cmd}
36 SSHLibrary.Set_Client_Configuration timeout=30s
37 SSHLibrary.Write ${start_cmd}
38 ${output}= SSHLibrary.Read_Until ${until_phrase}
41 Wait_Until_Console_Tool_Finish
42 [Documentation] Wait ${timeout} for the tool exit.
43 [Arguments] ${timeout}
44 BuiltIn.Wait Until Keyword Succeeds ${timeout} 1s SSHLibrary.Read Until Prompt
47 [Documentation] Stop the tool if still running.
48 RemoteBash.Write_Bare_Ctrl_C
49 ${output}= SSHLibrary.Read delay=1s
52 Stop_Console_Tool_And_Wait_Until_Prompt
53 [Documentation] Stops the tool by sending ctrl+c
54 ${output}= SSHLibrary.Read
56 RemoteBash.Write_Bare_Ctrl_C
57 ${output}= SSHLibrary.Read_Until_Prompt
60 Read_And_Fail_If_Prompt_Is_Seen
61 [Documentation] Try to read SSH to see prompt, but expect to see no prompt within SSHLibrary's timeout.
62 ${passed}= BuiltIn.Run_Keyword_And_Return_Status
63 ... BuiltIn.Run_Keyword_And_Expect_Error
64 ... No match found for '${ODL_SYSTEM_PROMPT}' in *.
65 ... Read_Text_Before_Prompt
67 BGPSpeaker.Dump_BGP_Speaker_Logs
68 Builtin.Fail The prompt was seen but it was not expected yet
70 Read_Text_Before_Prompt
71 [Documentation] Log text gathered by SSHLibrary.Read_Until_Prompt.
72 ... This needs to be a separate keyword just because how Read_And_Fail_If_Prompt_Is_Seen is implemented.
73 ${text}= SSHLibrary.Read_Until_Prompt
76 Store_File_To_Workspace
77 [Documentation] Store the ${source_file_name} to the workspace as ${target_file_name}.
78 [Arguments] ${source_file_name} ${target_file_name}
79 ${output_log}= SSHLibrary.Execute_Command cat ${source_file_name}
80 BuiltIn.Log ${output_log}
81 Create File ${target_file_name} ${output_log}
83 Check_File_For_Word_Count
84 [Documentation] Count ${word} in ${file_name}. Expect ${expected_count} occurence(s)
85 [Arguments] ${file_name} ${word} ${expected_count}
86 ${output_log}= SSHLibrary.Execute_Command grep -o '${word}' ${file_name} | wc -l
87 BuiltIn.Log ${output_log}
88 BuiltIn.Should_Be_Equal_As_Strings ${output_log} ${expected_count}
91 [Documentation] Check file for ${keyword} or ${keyword} ${value} pair and returns number of occurences
92 [Arguments] ${file_name} ${keyword} ${value}=''
93 ${output_log}= SSHLibrary.Execute_Command grep '${keyword}' ${file_name} | grep -c ${value}
94 ${count}= Convert To Integer ${output_log}
97 Check_File_For_Occurence
98 [Documentation] Check file for ${keyword} or ${keyword} ${value} pair and returns number of occurences
99 [Arguments] ${file_name} ${keyword} ${value}=''
100 ${output_log}= SSHLibrary.Execute_Command grep '${keyword}' ${file_name} | grep -c ${value}
101 ${count}= Convert To Integer ${output_log}