SSH Connection to Database using Database Library?

925 views
Skip to first unread message

Greg Meece

unread,
Sep 17, 2015, 1:03:42 AM9/17/15
to robotframework-users
This may have been asked previously, but just in case...

I am trying to leverage the Database Library to connect to a MySQL database hosted on an AWS instance. I can connect to it via MySQL workbench using a private SSH key (to a gateway) which in turn is connected to the AWS instance.

Does anyone have any suggestions that would help me achieve connection for cross-platform implementation (Windows and Linux)? I can supply whatever additional information might be needed.

Thanks!

The information in this email may be confidential and/or privileged. This email may be reviewed only by the intended recipient named above. Any review, use or disclosure of the information contained in this email, or any attachments by anyone other than the intended recipient, is prohibited. If you have received this email in error, please immediately notify the sender and permanently delete this email from your system.

Jerry Schneider

unread,
Sep 17, 2015, 9:07:13 AM9/17/15
to robotframe...@googlegroups.com
Have you tried using the " Connect To Database Using Custom Params" keyword?  What does your connect string look like using the ssh key?  I have not tried anything like this and do not currently have a setup to test it out.

jer
--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-u...@googlegroups.com.
To post to this group, send email to robotframe...@googlegroups.com.
Visit this group at http://groups.google.com/group/robotframework-users.
For more options, visit https://groups.google.com/d/optout.

-- 
Linux registered user #475536
Ubuntu registered user #28583

Greg Meece

unread,
Nov 5, 2015, 4:04:35 PM11/5/15
to robotframework-users
Hey, All -

I was able to develop a solution to my issue. 

Here's the TL;DR:
  • Using pip, install sshtunnel
  • Prior to connecting to MySQL, invoke a tunnel via the RF Process library
  • Connect - do your stuff.
  • Kill the process that created the tunnel.
Hit me up if you need more detail.

Jerry Schneider

unread,
Nov 5, 2015, 4:07:45 PM11/5/15
to glm...@gmail.com, robotframework-users
Have you thought about submitting an enhancement request to say sshlibrary to add the tunneling (setup/teardown) keywords?  I am sure there are others who might need something like this and it doesn't sound too terribly hard to code up.

jer
--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-u...@googlegroups.com.
To post to this group, send email to robotframe...@googlegroups.com.
Visit this group at http://groups.google.com/group/robotframework-users.
For more options, visit https://groups.google.com/d/optout.

Greg Meece

unread,
Nov 5, 2015, 4:19:54 PM11/5/15
to robotframework-users
Thinking better of my short reply, here's more detail:

  1. Execute pip install sshtunnel
  2. Create a keyword such as shown below, and invoke it before you attempt a database connection.
  3. After you disconnect from the database, call the Process keyword: Terminate All Processes

Example Keyword

Open SSH Tunnel
    [Arguments]       ${GATEWAY}  ${SSHUSER}  ${SSHKEY}  ${HOST}  ${LOCPORT}  ${REMHOST}  ${REMPORT}
    Log to Console    ${SPACE}≡ Opening SSH tunnel...
    Start Process     python  -m  sshtunnel  ${GATEWAY}  -U  ${SSHUSER}  -K  ${SSHKEY}  -L  ${HOST}:${LOCPORT}  -R  ${REMHOST}:${REMPORT}
    Sleep             4 seconds
    Log to Console    ${SPACE}≡ Tunnel should be open!

Jerry Schneider

unread,
Nov 5, 2015, 5:24:47 PM11/5/15
to glm...@gmail.com, robotframework-users
Thanks this looks good.  I am going to try it out later on some test machines I use.

jer
--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-u...@googlegroups.com.
To post to this group, send email to robotframe...@googlegroups.com.
Visit this group at http://groups.google.com/group/robotframework-users.
For more options, visit https://groups.google.com/d/optout.

nguyen duong

unread,
Jan 15, 2016, 3:21:31 AM1/15/16
to robotframework-users
Hi Greg,

I am connecting to Database via MySQL Workbench using private SSH key. But I don't know how to make that connection from Robot Framework IDE. Could you please show me a sample script of it?

Vào 12:03:42 UTC+7 Thứ Năm, ngày 17 tháng 9 năm 2015, Greg Meece đã viết:

Joseph Jacob

unread,
Jan 26, 2018, 2:03:09 PM1/26/18
to robotframework-users
Hi Greg

could you please help how to connect tunnel and kill the process . do you have any robot file to do that ? or do you have any other steps 


On Thursday, November 5, 2015 at 3:04:35 PM UTC-6, Greg Meece wrote:
Reply all
Reply to author
Forward
0 new messages