Sending commands, retrieving outputs and screenshot results via SSH library and Process

Hello, I intend to write some testcases that involve sending commands via ssh to a remote server or devices, capturing the output (screenshot the shell output directly or creating a .txt file or similar that can be screenshot and also save the file log) to be post-processed, filtered and piping it to other processes and do the capture process again for the new outputs.

To do so started reading about the SSH and Process libraries, their basic functionality and created a robot file to test the simplest case to establish an ssh session , send a command and log the output.
But for some reason even though it establishes a session, it gives a return code 1 for the log.

I have tested connecting to the server and sending a “show version” command, using a python script with the netmiko library and it works well.

This is the robot framework code and the output.

*** Test Cases ***
Establish SSH connection to EPNM
Open Connection ${epnm_host}
Login ${epnm_username} ${epnm_password}
${output} ${stderr} ${rc} = Execute Command show version return_stderr=True return_rc=True

Log     ${rc}
log     ${output}
log     ${stderr}

close connection

Am I missing something?
I have also thought about writing a custom library that exposes netmiko functionality to the testcases, but would rather try to solve the issue and use the keywords from SSH library.

Other question I had is if it is possible to use first the SSH library to establish the connection and then Process to send the command and extract the info for the same session.

Lastly want to know if it is possible to take a screenshot of the actual CLI output or if it will be necessary to redirect the output to a txt file and take the screenshot from there.

I appreciate any ideas to solve the issue and for the specific testcase.

Thanks in advance.

exit code 1 typically mean that the command was executed but that program encountered an error.

In this case, stderr shows “Error getty tty, exiting”. Quick googling didnt show this error message to be anything generic so most likely that is coming from your program. So the issue could be that your “show” application requires tty (or pty) for some reason and without one, it fails…

Paramiko does have feature to request a pty but I didn’t find anything in the sshlibrary code where that could be implemented.

As possible solution, on your machine where you run robot and sshlibrary, add your hostname into ssh config file and add RequestTTY force under that host. That might help

2 Likes

I use the keywords Write and Read and the output is enough for my needs.

About getting screenshots, I found an article on how to get HTML mimicking the screen, which allowed me to capture the topor htop output. But this is done with a technique of “cloning” the screen, and I never tried to make a SSHLibrary keyword.

2 Likes

I’d add that using Write and Read might actually allocate the tty automatically. Since tty/pty is typically needed for interactive shell session so what @HelioGuilherme66 said might also a good idea to try at leasat.

2 Likes