onap on kubernetes source files
[oom.git] / kubernetes / config / docker / init / src / config / robot / robot / resources / ssh / files.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
5 Library           HttpLibrary.HTTP
6 Library           String
7 Library           Collections
8
9 *** Variables ***
10
11 *** Keywords ***
12 Open Connection And Log In
13    [Documentation]    Open a connection using the passed user and SSH key. Connection alias will be the host name by default.
14    [Arguments]    ${HOST}    ${user}    ${pvt}    ${password}=    ${alias}=${HOST}    ${timeout}=120s
15    Open Connection    ${HOST}    alias=${alias}    timeout=${timeout}
16    Login With Public Key    ${user}    ${pvt}    password=${password}    delay=0.5 seconds
17
18 Grep Local File
19     [Documentation]     Grep the passed file name and return all of the lines that match the passed pattern using the current connection
20     [Arguments]    ${pattern}     ${fullpath}
21     ${output}=    Execute Command    grep ${pattern} ${fullpath}
22     [Return]     ${output}
23
24  Grep File on Host
25     [Documentation]     Grep the passed file name and return all of the lines that match the passed pattern using passed connection alias/host
26     [Arguments]     ${host}    ${pattern}     ${fullpath}
27     Switch Connection    ${host}
28     ${output}=    Grep Local File    ${pattern}    ${fullpath}
29     @{lines}=    Split To Lines    ${output}
30     [Return]     @{lines}
31
32 Grep File on Hosts
33     [Documentation]     Grep the passed file name and return all of the lines that match the passed pattern using passed list of connections
34     [Arguments]    ${HOSTS}    ${pattern}    ${fullpath}
35     &{map}=    Create Dictionary
36     :FOR    ${HOST}    IN    @{HOSTS}
37     \    Log    ${HOST}
38     \    @{lines}=    Grep File on Host    ${HOST}   ${pattern}    ${fullpath}
39     \    &{map}=    Create Dictionary    ${HOST}=@{lines}    &{map}
40     [Return]    &{map}
41
42 Tail File on Host Until
43     [Documentation]     Tail log file into grep which returns file lines containing the grep pattern. Will timeout after timeout= if expected pattern not received.
44     [Arguments]    ${host}    ${pattern}    ${fullpath}    ${expected}    ${timeout}=60    ${options}=-c -0
45     Switch Connection    ${host}
46     ${tailcommand}=    Catenate    tail ${options} -f ${fullpath} | grep --color=never ${pattern}
47     Write    ${tailcommand}
48     ${stdout}=  Read Until Regexp    ${expected}
49     @{lines}=    Split To Lines    ${stdout}
50     [Return]    @{lines}