Robot Framework - SSH library - Editing a file on remote server

1.6k views Asked by At

I am writing a test case in Robot Framework where in, I have to either copy the file from the local machine (windows) to the remote server (linux) or create a new one at the location. I have used multiple sudo su - command to switch users to root user to reach the desired host. As a result of this, I am not able to use Put File Keyword from SSH Library to upload the file. I have reached at the desired folder location by executing the commands with Write keyword. Since there is no option left (thats what i realize with my limited knowledge on Robot Framework), i started creating a new file with vi <filename> command. I have also reached the INSERT mode of the file, BUT i am not able to edit text into the file.

Can someone please suggest me how can i either

  1. Copy the file from local windows machine to remote linux server AFTER multiple SU commands (Switch User)
  2. Create a new text file and enter the content.

Please See : the new file which is being created / copied is a certificate file. Hence i do not wish to write the entire content of the certificate in my test suite file

The entire test case looks something like this

First Jump1
    Log    Starting the connection to AWS VM
    # Connection to VM with Public Key
    Connection To VM    ${hostname}    ${username} 
    Send Command    sudo su -
    Send Command    su - <ServiceUser1>
    # Reached the Detination server
    Send Command    whoami  
    Send Command    ss -tln | grep 127.0.0.1:40
    # Connecting to Particular ZIP
    Send Command    sudo -u <ServiceUser2> /usr/bin/ssh <ServiceUser2>@localhost -p <port>
    Send Command    sudo su -
    # Check Auth Certificate
    Send Command    mosquitto_pub -h ${mq_host} -p ${mq_port} -u ${mq_username} -P ${mq_password}

In the step Check Auth Certificate, the certificate is checked to be present or not, if present -> delete the current certificate and create the new one (either create a new file or upload from local) and if it not there create a new certificate

1

There are 1 answers

0
Nike On BEST ANSWER

though it might not be ideal, but was able to achieve what i wanted to do with

echo "content" > newFilename
echo "update content" >> newFileName