blob: 44d82c86be3f00adf3dea025db9ad775bdfa0030 [file] [log] [blame]
DR695Hccff30b2017-02-17 18:44:24 -05001*** Settings ***
2Documentation Some handy Keywords for accessing log files over SSH. Assumptions are that logs will belong to users other than the currently logged in user and that sudo will be required
3Library OperatingSystem
4Library SSHLibrary 60 seconds
DR695Hccff30b2017-02-17 18:44:24 -05005Library String
6Library Collections
7
8*** Variables ***
9
10*** Keywords ***
11
12Get Processes
13 [Documentation] Returns all of the processes on the currently connected host
14 ${output}= Execute Command ps -ef
15 ${map}= Create Process Map ${output}
16 [Return] ${map}
17
18Grep Processes
19 [Documentation] Return the list of processes matching the passed regex
20 [Arguments] ${pattern}
21 ${output}= Execute Command ps -ef|grep "${pattern}"|grep -v grep
22 ${map}= Create Process Map ${output}
23 [Return] ${map}
24
25Create Process Map
26 [Documentation] Extract process pids and process names from ps -ef output
27 [Arguments] ${input}
28 @{lines}= Split To Lines ${input}
29 ${map}= Create Dictionary
DR695H910097e2019-05-08 13:55:32 -040030 :FOR ${line} IN @{lines}
DR695Hccff30b2017-02-17 18:44:24 -050031 \ @{parts}= Split String ${line} max_split=7
32 \ ${pid}= Catenate ${parts[1]}
33 \ ${name}= Catenate ${parts[7]}
34 \ Set To Dictionary ${map} ${pid}=${name}
35 [Return] ${map}
36
37
38Wait for Process on Host
39 [Documentation] Wait for the passed process name (regular expression) to be running on the passed host
Gary Wu76bc74f2018-03-22 13:25:49 -070040 [Arguments] ${process_name} ${host} ${timeout}=1200s
DR695Hccff30b2017-02-17 18:44:24 -050041 ${map}= Wait Until Keyword Succeeds ${timeout} 10 sec Is Process On Host ${process_name} ${host}
42 [Return] ${map}
43
44
45Pkill Process on Host
46 [Documentation] Kill the named process(es). Process name must match exactly
47 [Arguments] ${process_name} ${host} ${timeout}=600s
48 Switch Connection ${host}
49 ${output}= Execute Command pkill -9 -e -f ${process_name}
50 [Return] ${output}
51
52Is Process on Host
53 [Documentation] Look for the passed process name (regex) to be running on the passed host. Process name can include regex.
54 [Arguments] ${process_name} ${host}
55 Switch Connection ${host}
56 ${pass} ${map}= Run Keyword and Ignore Error Grep Processes ${process_name}
57 @{pids}= Get Dictionary Keys ${map}
58 ${foundpid}= Catenate ""
DR695H910097e2019-05-08 13:55:32 -040059 :FOR ${pid} IN @{pids}
DR695Hccff30b2017-02-17 18:44:24 -050060 \ ${process_cmd}= Get From Dictionary ${map} ${pid}
61 \ ${status} ${value}= Run Keyword And Ignore Error Should Match Regexp ${process_cmd} ${process_name}
62 \ Run Keyword If '${status}' == 'PASS' Set Test Variable ${foundpid} ${pid}
63 Should Not Be Equal ${foundpid} ""
64 [Return] ${map}[${foundpid}]
65
66
67Get Process List on Host
68 [Documentation] Gets the list of all processes on the passed host
69 [Arguments] ${host}
70 Switch Connection ${host}
71 ${map}= Get Processes
72 [Return] ${map}
73