1

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

Nike
  • 23
  • 1
  • 10
  • why do you need multiple sudo su commands? can you elaborate more on how you connect to the desired location – Jiri Janous Jun 24 '21 at 08:20
  • Because, our team does not have the public & private key to connect with the destination host with the service / technical user. Hence have to connect with our individual users and then `sudo su` commands – Nike Jun 24 '21 at 09:00
  • what i meant was, how many connections do you need to make, where do you need to switch the user etc... – Jiri Janous Jun 24 '21 at 09:14
  • @JiriJanous its 3 connections - the test case is updated in the question – Nike Jun 24 '21 at 11:58
  • You could copy the file with scp with your login user (even to /tmp), then su, copy it locally to the destination folder and change its ownership as needed. – Todor Minakov Jun 24 '21 at 19:57
  • tried doing this, but got struck at the last step due to lack of permission to do SCP or SFTP and also existence of firewall between the 2 host machines – Nike Jul 02 '21 at 11:44

1 Answers1

1

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

echo "content" > newFilename
echo "update content" >> newFileName
Nike
  • 23
  • 1
  • 10