robotframework封裝ssh關鍵字用於遠程控制和文件傳輸

robotframework封裝ssh關鍵字用於遠程控制和文件傳輸

*** Settings  ***
Library           SSHLibrary
Library           String 
*** Variables ***
*** Keywords  ***
OpenConnectionAndLogin
    [Documentation]        ssh remote server
    [Arguments]            ${ip}  ${user}  ${password}  ${alias}
    Open Connection  ${ip}  alias=${alias}
    Login  ${user}  ${password}

SwithConnectionAndLog
    [Documentation]        swith connection 
    [Arguments]            ${machine}
    Switch Connection  ${${machine}_alias}
    ${myc}  Get Connection  ${${machine}_alias}
    log  ${myc.host}

SshExecuteCmd
    [Documentation]        ssh execute cmd, check return, 可指定機器
    [Arguments]            ${machine}  ${cmd}
    SwithConnectionAndLog  ${machine}
    ${stdout}  ${rc} =  SSHLibrary.Execute Command  ${cmd}  return_rc=${true}
    Return From Keyword  ${stdout}  ${rc}

SshPutFile
    [Documentation]        ssh執行命令, 判斷返回碼, 可指定機器
    [Arguments]            ${machine}    ${src}  ${dest}
    SwithConnectionAndLog  ${machine}
    SSHLibrary.Put File    ${src}  ${dest}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章