Kumar
Kumar

Reputation: 717

How to ssh a remote device from a already logged in device using robot framework?

I have the following Test topology:

Windows Computer ----- Router1 ----- Router2 

I need to do SSH from "Windows Computer" to "Router2". Its not possible through direct SSH, since its in different network (Access denied).

So, I need to SSH "Router1", then again from "Router1" I need to connect Router2 through SSH.

Can anybody tell me, how to do this in ROBOT FRAMEWORK.

Till now I am able to SSH from "Windows Computer" to "Router1" using the following "Keywords":

*** Keywords ***
Open Connection And Log In
    Open Connection         ${HOST}
    Login   ${USERNAME}     ${PASSWORD}

Thanks in advance.

Upvotes: 2

Views: 543

Answers (1)

Stiffo
Stiffo

Reputation: 818

How about something like this?
This would require sshpass on router1. There is a more involved way using an SSH key to avoid using the password. This is all assuming you don't need to run Robotframework on it, and are happy to run terminal commands on it.

***Keywords***
    Remote Bash  
    [Arguments]  ${command}  
    [Documentation]  Runs a given terminal command on remote server and returns terminal output.  

    ${test} =    SSHLibrary.Execute Command    ${command}
    Return From Keyword   ${test}
***Test Cases***
RemoteSSH
    Open Connection         ${ROUTER1_IP}
    Login   ${ROUTER1_USER}     ${ROUTER1_PW}
    Remote Bash  sshpass -p ${ROUTER2_PW} ${ROUTER2_USER}@${ROUTER2_IP}
    Remote Bash  echo 'Hello World!'

Upvotes: 1

Related Questions