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 RemoteBash.robot
19 Resource NexusKeywords.robot
24 [Documentation] Start the tool ${command} ${tool_opt}
25 [Arguments] ${command} ${tool_opt}
26 ${start_cmd}= BuiltIn.Set_Variable ${command} ${tool_opt}
27 BuiltIn.Log ${start_cmd}
28 ${output}= SSHLibrary.Write ${start_cmd}
31 Start_Java_Tool_And_Verify_Connection
32 [Arguments] ${command} ${until_phrase}
33 ${start_cmd}= NexusKeywords.Compose_Full_Java_Command ${command}
34 BuiltIn.Log ${start_cmd}
35 SSHLibrary.Set_Client_Configuration timeout=30s
36 SSHLibrary.Write ${start_cmd}
37 ${output}= SSHLibrary.Read_Until ${until_phrase}
40 Wait_Until_Console_Tool_Finish
41 [Documentation] Wait ${timeout} for the tool exit.
42 [Arguments] ${timeout}
43 BuiltIn.Wait Until Keyword Succeeds ${timeout} 1s SSHLibrary.Read Until Prompt
46 [Documentation] Stop the tool if still running.
47 RemoteBash.Write_Bare_Ctrl_C
48 ${output}= SSHLibrary.Read delay=1s
51 Stop_Console_Tool_And_Wait_Until_Prompt
52 [Documentation] Stops the tool by sending ctrl+c
53 ${output}= SSHLibrary.Read
55 RemoteBash.Write_Bare_Ctrl_C
56 ${output}= SSHLibrary.Read_Until_Prompt
59 Read_And_Fail_If_Prompt_Is_Seen
60 [Documentation] Try to read SSH to see prompt, but expect to see no prompt within SSHLibrary's timeout.
61 ${passed}= BuiltIn.Run_Keyword_And_Return_Status
62 ... BuiltIn.Run_Keyword_And_Expect_Error
63 ... No match found for '${ODL_SYSTEM_PROMPT}' in *.
64 ... Read_Text_Before_Prompt
66 BGPSpeaker.Dump_BGP_Speaker_Logs
67 Builtin.Fail The prompt was seen but it was not expected yet
69 Read_Text_Before_Prompt
70 [Documentation] Log text gathered by SSHLibrary.Read_Until_Prompt.
71 ... This needs to be a separate keyword just because how Read_And_Fail_If_Prompt_Is_Seen is implemented.
72 ${text}= SSHLibrary.Read_Until_Prompt
75 Store_File_To_Workspace
76 [Documentation] Store the ${source_file_name} to the workspace as ${target_file_name}.
77 [Arguments] ${source_file_name} ${target_file_name}
78 ${output_log}= SSHLibrary.Execute_Command cat ${source_file_name}
79 BuiltIn.Log ${output_log}
80 Create File ${target_file_name} ${output_log}
82 Check_File_For_Word_Count
83 [Documentation] Count ${word} in ${file_name}. Expect ${expected_count} occurence(s)
84 [Arguments] ${file_name} ${word} ${expected_count}
85 ${output_log}= SSHLibrary.Execute_Command grep -o '${word}' ${file_name} | wc -l
86 BuiltIn.Log ${output_log}
87 BuiltIn.Should_Be_Equal_As_Strings ${output_log} ${expected_count}
90 [Documentation] Check file for ${keyword} or ${keyword} ${value} pair and returns number of occurences
91 [Arguments] ${file_name} ${keyword} ${value}=''
92 ${output_log}= SSHLibrary.Execute_Command grep '${keyword}' ${file_name} | grep -c ${value}
93 ${count}= Convert To Integer ${output_log}
96 Check_File_For_Occurence
97 [Documentation] Check file for ${keyword} or ${keyword} ${value} pair and returns number of occurences
98 [Arguments] ${file_name} ${keyword} ${value}=''
99 ${output_log}= SSHLibrary.Execute_Command grep '${keyword}' ${file_name} | grep -c ${value}
100 ${count}= Convert To Integer ${output_log}