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.
14 Library SSHLibrary timeout=10s
15 Library RequestsLibrary
16 Resource ../variables/Variables.robot
17 Resource RemoteBash.robot
18 Resource NexusKeywords.robot
22 [Arguments] ${command} ${tool_opt}
23 [Documentation] Start the tool ${command} ${tool_opt}
24 ${start_cmd} BuiltIn.Set_Variable ${command} ${tool_opt}
25 BuiltIn.Log ${start_cmd}
26 ${output}= SSHLibrary.Write ${start_cmd}
29 Start_Java_Tool_And_Verify_Connection
30 [Arguments] ${command} ${until_phrase}
31 ${start_cmd} NexusKeywords.Compose_Full_Java_Command ${command}
32 BuiltIn.Log ${start_cmd}
33 SSHLibrary.Set_Client_Configuration timeout=30s
34 SSHLibrary.Write ${start_cmd}
35 ${output}= SSHLibrary.Read_Until ${until_phrase}
38 Wait_Until_Console_Tool_Finish
39 [Arguments] ${timeout}
40 [Documentation] Wait ${timeout} for the tool exit.
41 BuiltIn.Wait Until Keyword Succeeds ${timeout} 1s SSHLibrary.Read Until Prompt
44 [Documentation] Stop the tool if still running.
45 RemoteBash.Write_Bare_Ctrl_C
46 ${output}= SSHLibrary.Read delay=1s
49 Stop_Console_Tool_And_Wait_Until_Prompt
50 [Documentation] Stops the tool by sending ctrl+c
51 ${output}= SSHLibrary.Read
53 RemoteBash.Write_Bare_Ctrl_C
54 ${output}= SSHLibrary.Read_Until_Prompt
57 Read_And_Fail_If_Prompt_Is_Seen
58 [Documentation] Try to read SSH to see prompt, but expect to see no prompt within SSHLibrary's timeout.
59 ${passed}= BuiltIn.Run_Keyword_And_Return_Status BuiltIn.Run_Keyword_And_Expect_Error No match found for '${ODL_SYSTEM_PROMPT}' in *. Read_Text_Before_Prompt
60 BuiltIn.Return_From_Keyword_If ${passed}
61 BGPSpeaker.Dump_BGP_Speaker_Logs
62 Builtin.Fail The prompt was seen but it was not expected yet
64 Read_Text_Before_Prompt
65 [Documentation] Log text gathered by SSHLibrary.Read_Until_Prompt.
66 ... This needs to be a separate keyword just because how Read_And_Fail_If_Prompt_Is_Seen is implemented.
67 ${text}= SSHLibrary.Read_Until_Prompt
70 Store_File_To_Workspace
71 [Arguments] ${source_file_name} ${target_file_name}
72 [Documentation] Store the ${source_file_name} to the workspace as ${target_file_name}.
73 ${output_log}= SSHLibrary.Execute_Command cat ${source_file_name}
74 BuiltIn.Log ${output_log}
75 Create File ${target_file_name} ${output_log}
77 Check_File_For_Word_Count
78 [Arguments] ${file_name} ${word} ${expected_count}
79 [Documentation] Count ${word} in ${file_name}. Expect ${expected_count} occurence(s)
80 ${output_log}= SSHLibrary.Execute_Command grep -o '${word}' ${file_name} | wc -l
81 BuiltIn.Log ${output_log}
82 BuiltIn.Should_Be_Equal_As_Strings ${output_log} ${expected_count}
85 [Arguments] ${file_name} ${keyword} ${value}=''
86 [Documentation] Check file for ${keyword} or ${keyword} ${value} pair and returns number of occurences
87 ${output_log}= SSHLibrary.Execute_Command grep '${keyword}' ${file_name} | grep -c ${value}
88 ${count}= Convert To Integer ${output_log}
91 Check_File_For_Occurence
92 [Arguments] ${file_name} ${keyword} ${value}=''
93 [Documentation] Check file for ${keyword} or ${keyword} ${value} pair and returns number of occurences
94 ${output_log}= SSHLibrary.Execute_Command grep '${keyword}' ${file_name} | grep -c ${value}
95 ${count}= Convert To Integer ${output_log}