blob: 0536a8ad8406be5e3ea874ae5c9c5213d8f03a9b [file] [log] [blame]
Kailash Khalasib6e87fc2017-04-18 15:08:19 -07001*** Settings ***
2Documentation Library for various utilities
3Library SSHLibrary
4Library HttpLibrary.HTTP
5Library String
6Library DateTime
7Library Process
8Library Collections
9Library RequestsLibrary
10#Library ${CURDIR}/readProperties.py
11#Resource ${CURDIR}/utils.py
12
13*** Keywords ***
14Run 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
27Execute 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
40Execute 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
54Get 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
61Get 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}