blob: 0d2ba1496914defc7c9915bce20eb3f2a2d238d5 [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
Kailash Khalasi2adbad82017-05-15 14:53:40 -070028 [Arguments] ${system} ${vm} ${cmd} ${user}=${VM_USER} ${password}=${VM_PASS} ${prompt}=$ ${use_key}=True ${strip_line}=True
Kailash Khalasib6e87fc2017-04-18 15:08:19 -070029 [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
Kailash Khalasi2adbad82017-05-15 14:53:40 -070037 ${output_1}= Run Keyword If '${strip_line}' == 'True' Get Line ${output} 0
38 ${output}= Set Variable If '${strip_line}' == 'True' ${output_1} ${output}
Kailash Khalasib6e87fc2017-04-18 15:08:19 -070039 [Return] ${output}
40
41Execute Command on Compute Node in CIAB
42 [Arguments] ${system} ${hostname} ${cmd} ${user}=${VM_USER} ${password}=${VM_PASS} ${prompt}=$ ${use_key}=True
43 [Documentation] SSHs into ${HOST} where CIAB is running and executes a command in the Prod Vagrant VM where all the containers are running
44 ${conn_id}= SSHLibrary.Open Connection ${system} prompt=${prompt} timeout=300s
45 Run Keyword If '${use_key}' == 'False' SSHLibrary.Login ${user} ${pass} ELSE SSHLibrary.Login With Public Key ${user} %{HOME}/.ssh/${SSH_KEY} any
46 SSHLibrary.Write ssh prod
47 SSHLibrary.Read Until Prompt
48 SSHLibrary.Write ssh root@${hostname}
49 SSHLibrary.Read Until \#
50 SSHLibrary.Write ${cmd}
51 ${output}= SSHLibrary.Read Until \#
52 SSHLibrary.Close Connection
53 [Return] ${output}
54
Kailash Khalasi3a4e0f52017-06-01 16:35:59 -070055Execute Command Locally
56 [Arguments] ${cmd}
57 ${output}= Run ${cmd}
58 [Return] ${output}
59
Kailash Khalasib6e87fc2017-04-18 15:08:19 -070060Get Docker Container ID
61 [Arguments] ${system} ${container_name} ${user}=${USER} ${password}=${PASSWD}
62 [Documentation] Retrieves the id of the requested docker container running inside given ${HOST}
63 ${container_id}= Execute Command on CIAB Server in Specific VM ${system} prod docker ps | grep ${container_name} | awk '{print $1}' ${user} ${password}
64 Log ${container_id}
65 [Return] ${container_id}
66
67Get Docker Logs
68 [Arguments] ${system} ${container_id} ${user}=${USER} ${password}=${PASSWD} ${prompt}=prod:~$
69 [Documentation] Retrieves the id of the requested docker container running inside given ${HOST}
70 ##In Ciab, all containers are run in the prod vm so we must log into that
71 ${conn_id}= SSHLibrary.Open Connection ${system} prompt=$ timeout=300s
72 SSHLibrary.Login With Public Key ${USER} %{HOME}/.ssh/${SSH_KEY} any
73 #SSHLibrary.Login ${HOST_USER} ${HOST_PASSWORD}
74 SSHLibrary.Write ssh prod
75 SSHLibrary.Read Until ${prompt}
76 SSHLibrary.Write docker logs -t ${container_id}
77 ${container_logs}= SSHLibrary.Read Until ${prompt}
78 SSHLibrary.Close Connection
79 Log ${container_logs}
Kailash Khalasi2adbad82017-05-15 14:53:40 -070080 [Return] ${container_logs}
Kailash Khalasi86e231e2017-06-06 13:13:43 -070081
82Remove Value From List
83 [Arguments] ${list} ${val}
84 ${length}= Get Length ${list}
85 : FOR ${INDEX} IN RANGE 0 ${length}-1
86 \ Log ${list[${INDEX}]}
87 \ ${value}= Get Dictionary Values ${list[${INDEX}]}
88 \ Log ${value[0]}
89 \ Run Keyword If '${value[0]}' == '${val}' Remove From List ${list} ${INDEX}