onap on kubernetes source files
[oom.git] / kubernetes / config / docker / init / src / config / robot / robot / resources / ssh / processes.robot
1 *** Settings ***
2 Documentation     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
3 Library           OperatingSystem
4 Library               SSHLibrary    60 seconds
5 Library           HttpLibrary.HTTP
6 Library           String
7 Library           Collections
8
9 *** Variables ***
10
11 *** Keywords ***
12
13 Get Processes
14     [Documentation]     Returns all of the processes on the currently connected host 
15     ${output}=    Execute Command    ps -ef   
16     ${map}=    Create Process Map    ${output}
17     [Return]     ${map}
18
19 Grep Processes
20     [Documentation]     Return the list of processes matching the passed regex 
21     [Arguments]    ${pattern} 
22     ${output}=    Execute Command    ps -ef|grep "${pattern}"|grep -v grep   
23     ${map}=    Create Process Map    ${output}
24     [Return]     ${map}
25
26 Create Process Map
27     [Documentation]     Extract process pids and process names from ps -ef output
28     [Arguments]    ${input} 
29     @{lines}=    Split To Lines    ${input}
30     ${map}=    Create Dictionary
31     :for    ${line}    in    @{lines}
32     \    @{parts}=    Split String    ${line}    max_split=7 
33     \    ${pid}=    Catenate    ${parts[1]}
34     \    ${name}=   Catenate   ${parts[7]}
35     \    Set To Dictionary    ${map}    ${pid}=${name}      
36     [Return]     ${map}
37     
38          
39 Wait for Process on Host
40     [Documentation]     Wait for the passed process name (regular expression) to be running on the passed host  
41     [Arguments]    ${process_name}    ${host}    ${timeout}=600s    
42     ${map}=    Wait Until Keyword Succeeds    ${timeout}    10 sec    Is Process On Host    ${process_name}    ${host}
43     [Return]    ${map}
44
45
46 Pkill Process on Host
47     [Documentation]     Kill the named process(es). Process name must match exactly  
48     [Arguments]    ${process_name}    ${host}    ${timeout}=600s
49     Switch Connection    ${host}
50     ${output}=    Execute Command    pkill -9 -e -f ${process_name}     
51     [Return]    ${output}
52
53 Is Process on Host
54    [Documentation]     Look for the passed process name (regex) to be running on the passed host. Process name can include regex.   
55    [Arguments]    ${process_name}    ${host}    
56    Switch Connection    ${host}
57    ${pass}    ${map}=    Run Keyword and Ignore Error    Grep Processes    ${process_name}
58    @{pids}=    Get Dictionary Keys    ${map}
59    ${foundpid}=    Catenate    ""
60    :for    ${pid}    in    @{pids}
61    \    ${process_cmd}=    Get From Dictionary    ${map}    ${pid}
62    \    ${status}    ${value}=    Run Keyword And Ignore Error    Should Match Regexp    ${process_cmd}    ${process_name}    
63    \    Run Keyword If   '${status}' == 'PASS'    Set Test Variable    ${foundpid}    ${pid}             
64    Should Not Be Equal    ${foundpid}    ""           
65    [Return]    ${map}[${foundpid}]
66    
67    
68 Get Process List on Host
69     [Documentation]     Gets the list of all processes on the passed host  
70     [Arguments]    ${host}    
71     Switch Connection    ${host}
72     ${map}=    Get Processes  
73     [Return]    ${map}
74