Kailash Khalasi | b6e87fc | 2017-04-18 15:08:19 -0700 | [diff] [blame^] | 1 | *** Settings *** |
| 2 | Documentation Library for various utilities |
| 3 | Library SSHLibrary |
| 4 | Library HttpLibrary.HTTP |
| 5 | Library String |
| 6 | Library DateTime |
| 7 | Library Process |
| 8 | Library Collections |
| 9 | Library RequestsLibrary |
| 10 | #Library ${CURDIR}/readProperties.py |
| 11 | #Resource ${CURDIR}/utils.py |
| 12 | |
| 13 | *** Keywords *** |
| 14 | Run Command On Remote System |
| 15 | [Arguments] ${system} ${cmd} ${user}=${VM_USER} ${pass}=${VM_PASS} ${prompt}=$ ${prompt_timeout}=60s ${use_key}=False |
| 16 | [Documentation] SSH's into a remote host, executes command, and logs+returns output |
| 17 | BuiltIn.Log Attempting to execute command "${cmd}" on remote system "${system}" |
| 18 | BuiltIn.Log ${password} |
| 19 | ${conn_id}= SSHLibrary.Open Connection ${system} prompt=${prompt} timeout=${prompt_timeout} |
| 20 | Run Keyword If '${use_key}' == 'False' SSHLibrary.Login ${user} ${pass} ELSE SSHLibrary.Login With Public Key ${user} %{HOME}/.ssh/${SSH_KEY} any |
| 21 | #SSHLibrary.Login ${user} ${pass} |
| 22 | ${output}= SSHLibrary.Execute Command ${cmd} |
| 23 | SSHLibrary.Close Connection |
| 24 | Log ${output} |
| 25 | [Return] ${output} |
| 26 | |
| 27 | Execute Command on CIAB Server in Specific VM |
| 28 | [Arguments] ${system} ${vm} ${cmd} ${user}=${VM_USER} ${password}=${VM_PASS} ${prompt}=$ ${use_key}=True |
| 29 | [Documentation] SSHs into ${HOST} where CIAB is running and executes a command in the Prod Vagrant VM where all the containers are running |
| 30 | ${conn_id}= SSHLibrary.Open Connection ${system} prompt=${prompt} timeout=300s |
| 31 | Run Keyword If '${use_key}' == 'False' SSHLibrary.Login ${user} ${pass} ELSE SSHLibrary.Login With Public Key ${user} %{HOME}/.ssh/${SSH_KEY} any |
| 32 | SSHLibrary.Write ssh ${vm} |
| 33 | SSHLibrary.Read Until Prompt |
| 34 | SSHLibrary.Write ${cmd} |
| 35 | ${output}= SSHLibrary.Read Until Prompt |
| 36 | SSHLibrary.Close Connection |
| 37 | ${output}= Get Line ${output} 0 |
| 38 | [Return] ${output} |
| 39 | |
| 40 | Execute Command on Compute Node in CIAB |
| 41 | [Arguments] ${system} ${hostname} ${cmd} ${user}=${VM_USER} ${password}=${VM_PASS} ${prompt}=$ ${use_key}=True |
| 42 | [Documentation] SSHs into ${HOST} where CIAB is running and executes a command in the Prod Vagrant VM where all the containers are running |
| 43 | ${conn_id}= SSHLibrary.Open Connection ${system} prompt=${prompt} timeout=300s |
| 44 | Run Keyword If '${use_key}' == 'False' SSHLibrary.Login ${user} ${pass} ELSE SSHLibrary.Login With Public Key ${user} %{HOME}/.ssh/${SSH_KEY} any |
| 45 | SSHLibrary.Write ssh prod |
| 46 | SSHLibrary.Read Until Prompt |
| 47 | SSHLibrary.Write ssh root@${hostname} |
| 48 | SSHLibrary.Read Until \# |
| 49 | SSHLibrary.Write ${cmd} |
| 50 | ${output}= SSHLibrary.Read Until \# |
| 51 | SSHLibrary.Close Connection |
| 52 | [Return] ${output} |
| 53 | |
| 54 | Get Docker Container ID |
| 55 | [Arguments] ${system} ${container_name} ${user}=${USER} ${password}=${PASSWD} |
| 56 | [Documentation] Retrieves the id of the requested docker container running inside given ${HOST} |
| 57 | ${container_id}= Execute Command on CIAB Server in Specific VM ${system} prod docker ps | grep ${container_name} | awk '{print $1}' ${user} ${password} |
| 58 | Log ${container_id} |
| 59 | [Return] ${container_id} |
| 60 | |
| 61 | Get Docker Logs |
| 62 | [Arguments] ${system} ${container_id} ${user}=${USER} ${password}=${PASSWD} ${prompt}=prod:~$ |
| 63 | [Documentation] Retrieves the id of the requested docker container running inside given ${HOST} |
| 64 | ##In Ciab, all containers are run in the prod vm so we must log into that |
| 65 | ${conn_id}= SSHLibrary.Open Connection ${system} prompt=$ timeout=300s |
| 66 | SSHLibrary.Login With Public Key ${USER} %{HOME}/.ssh/${SSH_KEY} any |
| 67 | #SSHLibrary.Login ${HOST_USER} ${HOST_PASSWORD} |
| 68 | SSHLibrary.Write ssh prod |
| 69 | SSHLibrary.Read Until ${prompt} |
| 70 | SSHLibrary.Write docker logs -t ${container_id} |
| 71 | ${container_logs}= SSHLibrary.Read Until ${prompt} |
| 72 | SSHLibrary.Close Connection |
| 73 | Log ${container_logs} |
| 74 | [Return] ${container_logs} |