go.ligato.io/vpp-agent/v3@v3.5.0/tests/robot/libraries/ssh.robot (about)

     1  [Documentation] Keywords for ssh sessions
     2  
     3  *** Settings ***
     4  #Library       String
     5  #Library       RequestsLibrary
     6  Library       SSHLibrary            timeout=15 seconds       loglevel=TRACE
     7  Library       DateTime
     8  Library       Process
     9  
    10  *** Keywords ***
    11  Execute On Machine     [Arguments]              ${machine}               ${command}               ${log}=true
    12                         [Documentation]          *Execute On Machine ${machine} ${command}*
    13                         ...                      Executing ${command} on connection with name ${machine}
    14                         ...                      Output log is added to machine output log
    15                         Switch Connection        ${machine}
    16                         ${currdate}=             Get Current Date
    17                         Append To File    ${RESULTS_FOLDER}/output_${machine}.log    *** Time:${currdate} Command: ${command}${\n}
    18                         Append To File    ${RESULTS_FOLDER_SUITE}/output_${machine}.log    *** Time:${currdate} Command: ${command}${\n}
    19                         ${out}   ${stderr}=      Execute Command          ${command}    return_stderr=True
    20                         ${status}=               Run Keyword And Return Status    Should Be Empty    ${stderr}
    21                         Run Keyword If           ${status}==False         Log     One or more error occured during execution of a command ${command} on ${machine}    level=WARN
    22                         Run Keyword If           '${log}'=='true'         Append To File    ${RESULTS_FOLDER}/output_${machine}.log    *** Time:${currdate} Response: ${out}${\n}
    23                         Run Keyword If           '${log}'=='true'         Append To File    ${RESULTS_FOLDER_SUITE}/output_${machine}.log    *** Time:${currdate} Response: ${out}${\n}
    24                         Run Keyword If           ${status}==False         Append To File    ${RESULTS_FOLDER}/output_${machine}.log    *** Error: ${stderr}${\n}
    25                         Run Keyword If           ${status}==False         Append To File    ${RESULTS_FOLDER_SUITE}/output_${machine}.log    *** Error: ${stderr}${\n}
    26                         [Return]                 ${out}
    27  
    28  Write To Machine       [Arguments]              ${machine}               ${command}               ${delay}=${SSH_READ_DELAY}s
    29                         [Documentation]          *Write Machine ${machine} ${command}*
    30                         ...                      Writing ${command} to connection with name ${machine}
    31                         ...                      Output log is added to machine output log
    32                         Switch Connection        ${machine}
    33                         ${currdate}=             Get Current Date
    34                         Append To File           ${RESULTS_FOLDER}/output_${machine}.log    *** Time:${currdate} Command: ${command}${\n}
    35                         Append To File           ${RESULTS_FOLDER_SUITE}/output_${machine}.log    *** Time:${currdate} Command: ${command}${\n}
    36                         Write                    ${command}      loglevel=TRACE
    37                         ${out}=                  Read            loglevel=TRACE         delay=${delay}
    38                         Append To File           ${RESULTS_FOLDER}/output_${machine}.log    *** Time:${currdate} Response: ${out}${\n}
    39                         Append To File           ${RESULTS_FOLDER_SUITE}/output_${machine}.log    *** Time:${currdate} Response: ${out}${\n}
    40                         [Return]                 ${out}
    41  
    42  Write To Machine Until Prompt
    43                         [Arguments]              ${machine}    ${command}    ${prompt}=root@    ${delay}=${SSH_READ_DELAY}
    44                         [Documentation]          *Write Machine ${machine} ${command}*
    45                         ...                      Writing ${command} to connection with name ${machine} and reading until prompt
    46                         ...                      Output log is added to machine output log
    47                         Log                      Use 'Write To Container Until Prompt' instead of this kw    level=WARN
    48                         Switch Connection        ${machine}
    49                         ${currdate}=             Get Current Date
    50                         Append To File           ${RESULTS_FOLDER}/output_${machine}.log    *** Time:${currdate} Command: ${command}${\n}
    51                         Append To File           ${RESULTS_FOLDER_SUITE}/output_${machine}.log    *** Time:${currdate} Command: ${command}${\n}
    52                         Write                    ${command}       loglevel=TRACE
    53                         ${out}=                  Read Until               ${prompt}${${machine}_HOSTNAME}     loglevel=TRACE
    54                         ${out2}=                 Read             loglevel=TRACE       delay=${delay}
    55                         Append To File           ${RESULTS_FOLDER}/output_${machine}.log    *** Time:${currdate} Response: ${out}${out2}${\n}
    56                         Append To File           ${RESULTS_FOLDER_SUITE}/output_${machine}.log    *** Time:${currdate} Response: ${out}${out2}${\n}
    57                         [Return]                 ${out}${out2}
    58  
    59  Write To Machine Until String
    60                         [Arguments]              ${machine}    ${command}    ${string}    ${delay}=${SSH_READ_DELAY}
    61                         [Documentation]          *Write Machine ${machine} ${command}*
    62                         ...                      Writing ${command} to connection with name ${machine} and reading until specified string
    63                         ...                      Output log is added to machine output log
    64                         Switch Connection        ${machine}
    65                         ${currdate}=             Get Current Date
    66                         Append To File           ${RESULTS_FOLDER}/output_${machine}.log    *** Time:${currdate} Command: ${command}${\n}
    67                         Append To File           ${RESULTS_FOLDER_SUITE}/output_${machine}.log    *** Time:${currdate} Command: ${command}${\n}
    68                         Write                    ${command}       loglevel=TRACE
    69                         ${out}=                  Read Until       ${string}       loglevel=TRACE
    70                         ${out2}=                 Read             loglevel=TRACE        delay=${delay}
    71                         Append To File           ${RESULTS_FOLDER}/output_${machine}.log    *** Time:${currdate} Response: ${out}${out2}${\n}
    72                         Append To File           ${RESULTS_FOLDER_SUITE}/output_${machine}.log    *** Time:${currdate} Response: ${out}${out2}${\n}
    73                         [Return]                 ${out}${out2}
    74  
    75  Copy File To Machine
    76                         [Arguments]              ${machine}    ${local_path}    ${remote_path}
    77                         Switch Connection        ${machine}
    78                         ${out}   ${stderr}=      Put File    ${local_path}    ${remote_path}    mode=0777