Gunaseelan | ed0eb1b | 2017-08-08 08:12:12 -0500 | [diff] [blame] | 1 | # Copyright 2017-present Open Networking Foundation |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
| 15 | # Copyright 2017-present Radisys Corporation |
| 16 | # |
| 17 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 18 | # you may not use this file except in compliance with the License. |
| 19 | # You may obtain a copy of the License at |
| 20 | # |
| 21 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 22 | # |
| 23 | # Unless required by applicable law or agreed to in writing, software |
| 24 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 25 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 26 | # See the License for the specific language governing permissions and |
| 27 | # limitations under the License. |
| 28 | |
| 29 | |
| 30 | |
Kailash Khalasi | b6e87fc | 2017-04-18 15:08:19 -0700 | [diff] [blame] | 31 | *** Settings *** |
| 32 | Documentation Library for various utilities |
| 33 | Library SSHLibrary |
| 34 | Library HttpLibrary.HTTP |
| 35 | Library String |
| 36 | Library DateTime |
| 37 | Library Process |
| 38 | Library Collections |
| 39 | Library RequestsLibrary |
| 40 | #Library ${CURDIR}/readProperties.py |
| 41 | #Resource ${CURDIR}/utils.py |
Gunaseelan | ed0eb1b | 2017-08-08 08:12:12 -0500 | [diff] [blame] | 42 | *** Variables *** |
| 43 | ${SSH_KEY}= id_rsa |
Kailash Khalasi | b6e87fc | 2017-04-18 15:08:19 -0700 | [diff] [blame] | 44 | |
| 45 | *** Keywords *** |
| 46 | Run Command On Remote System |
| 47 | [Arguments] ${system} ${cmd} ${user}=${VM_USER} ${pass}=${VM_PASS} ${prompt}=$ ${prompt_timeout}=60s ${use_key}=False |
| 48 | [Documentation] SSH's into a remote host, executes command, and logs+returns output |
| 49 | BuiltIn.Log Attempting to execute command "${cmd}" on remote system "${system}" |
Gunaseelan | ed0eb1b | 2017-08-08 08:12:12 -0500 | [diff] [blame] | 50 | BuiltIn.Log ${pass} |
Kailash Khalasi | b6e87fc | 2017-04-18 15:08:19 -0700 | [diff] [blame] | 51 | ${conn_id}= SSHLibrary.Open Connection ${system} prompt=${prompt} timeout=${prompt_timeout} |
| 52 | Run Keyword If '${use_key}' == 'False' SSHLibrary.Login ${user} ${pass} ELSE SSHLibrary.Login With Public Key ${user} %{HOME}/.ssh/${SSH_KEY} any |
| 53 | #SSHLibrary.Login ${user} ${pass} |
| 54 | ${output}= SSHLibrary.Execute Command ${cmd} |
| 55 | SSHLibrary.Close Connection |
| 56 | Log ${output} |
| 57 | [Return] ${output} |
| 58 | |
| 59 | Execute Command on CIAB Server in Specific VM |
Kailash Khalasi | 2adbad8 | 2017-05-15 14:53:40 -0700 | [diff] [blame] | 60 | [Arguments] ${system} ${vm} ${cmd} ${user}=${VM_USER} ${password}=${VM_PASS} ${prompt}=$ ${use_key}=True ${strip_line}=True |
Kailash Khalasi | b6e87fc | 2017-04-18 15:08:19 -0700 | [diff] [blame] | 61 | [Documentation] SSHs into ${HOST} where CIAB is running and executes a command in the Prod Vagrant VM where all the containers are running |
| 62 | ${conn_id}= SSHLibrary.Open Connection ${system} prompt=${prompt} timeout=300s |
| 63 | Run Keyword If '${use_key}' == 'False' SSHLibrary.Login ${user} ${pass} ELSE SSHLibrary.Login With Public Key ${user} %{HOME}/.ssh/${SSH_KEY} any |
| 64 | SSHLibrary.Write ssh ${vm} |
| 65 | SSHLibrary.Read Until Prompt |
| 66 | SSHLibrary.Write ${cmd} |
| 67 | ${output}= SSHLibrary.Read Until Prompt |
| 68 | SSHLibrary.Close Connection |
Kailash Khalasi | 2adbad8 | 2017-05-15 14:53:40 -0700 | [diff] [blame] | 69 | ${output_1}= Run Keyword If '${strip_line}' == 'True' Get Line ${output} 0 |
| 70 | ${output}= Set Variable If '${strip_line}' == 'True' ${output_1} ${output} |
Kailash Khalasi | b6e87fc | 2017-04-18 15:08:19 -0700 | [diff] [blame] | 71 | [Return] ${output} |
| 72 | |
| 73 | Execute Command on Compute Node in CIAB |
Kailash Khalasi | f6de259 | 2017-09-13 13:37:14 -0700 | [diff] [blame^] | 74 | [Arguments] ${system} ${node} ${hostname} ${cmd} ${user}=${VM_USER} ${password}=${VM_PASS} ${prompt}=$ ${use_key}=True |
Kailash Khalasi | b6e87fc | 2017-04-18 15:08:19 -0700 | [diff] [blame] | 75 | [Documentation] SSHs into ${HOST} where CIAB is running and executes a command in the Prod Vagrant VM where all the containers are running |
| 76 | ${conn_id}= SSHLibrary.Open Connection ${system} prompt=${prompt} timeout=300s |
| 77 | Run Keyword If '${use_key}' == 'False' SSHLibrary.Login ${user} ${pass} ELSE SSHLibrary.Login With Public Key ${user} %{HOME}/.ssh/${SSH_KEY} any |
Kailash Khalasi | f6de259 | 2017-09-13 13:37:14 -0700 | [diff] [blame^] | 78 | SSHLibrary.Write ssh ${node} |
Kailash Khalasi | b6e87fc | 2017-04-18 15:08:19 -0700 | [diff] [blame] | 79 | SSHLibrary.Read Until Prompt |
| 80 | SSHLibrary.Write ssh root@${hostname} |
| 81 | SSHLibrary.Read Until \# |
| 82 | SSHLibrary.Write ${cmd} |
| 83 | ${output}= SSHLibrary.Read Until \# |
| 84 | SSHLibrary.Close Connection |
| 85 | [Return] ${output} |
| 86 | |
Kailash Khalasi | 3a4e0f5 | 2017-06-01 16:35:59 -0700 | [diff] [blame] | 87 | Execute Command Locally |
| 88 | [Arguments] ${cmd} |
| 89 | ${output}= Run ${cmd} |
| 90 | [Return] ${output} |
| 91 | |
Kailash Khalasi | b6e87fc | 2017-04-18 15:08:19 -0700 | [diff] [blame] | 92 | Get Docker Container ID |
| 93 | [Arguments] ${system} ${container_name} ${user}=${USER} ${password}=${PASSWD} |
| 94 | [Documentation] Retrieves the id of the requested docker container running inside given ${HOST} |
Kailash Khalasi | f6de259 | 2017-09-13 13:37:14 -0700 | [diff] [blame^] | 95 | ${container_id}= Execute Command on CIAB Server in Specific VM ${system} head1 docker ps | grep ${container_name} | awk '{print $1}' ${user} ${password} |
Kailash Khalasi | b6e87fc | 2017-04-18 15:08:19 -0700 | [diff] [blame] | 96 | Log ${container_id} |
| 97 | [Return] ${container_id} |
| 98 | |
| 99 | Get Docker Logs |
| 100 | [Arguments] ${system} ${container_id} ${user}=${USER} ${password}=${PASSWD} ${prompt}=prod:~$ |
| 101 | [Documentation] Retrieves the id of the requested docker container running inside given ${HOST} |
| 102 | ##In Ciab, all containers are run in the prod vm so we must log into that |
| 103 | ${conn_id}= SSHLibrary.Open Connection ${system} prompt=$ timeout=300s |
| 104 | SSHLibrary.Login With Public Key ${USER} %{HOME}/.ssh/${SSH_KEY} any |
| 105 | #SSHLibrary.Login ${HOST_USER} ${HOST_PASSWORD} |
Kailash Khalasi | f6de259 | 2017-09-13 13:37:14 -0700 | [diff] [blame^] | 106 | SSHLibrary.Write ssh head1 |
Kailash Khalasi | b6e87fc | 2017-04-18 15:08:19 -0700 | [diff] [blame] | 107 | SSHLibrary.Read Until ${prompt} |
| 108 | SSHLibrary.Write docker logs -t ${container_id} |
| 109 | ${container_logs}= SSHLibrary.Read Until ${prompt} |
| 110 | SSHLibrary.Close Connection |
| 111 | Log ${container_logs} |
Kailash Khalasi | 2adbad8 | 2017-05-15 14:53:40 -0700 | [diff] [blame] | 112 | [Return] ${container_logs} |
Kailash Khalasi | 86e231e | 2017-06-06 13:13:43 -0700 | [diff] [blame] | 113 | |
| 114 | Remove Value From List |
| 115 | [Arguments] ${list} ${val} |
| 116 | ${length}= Get Length ${list} |
| 117 | : FOR ${INDEX} IN RANGE 0 ${length}-1 |
| 118 | \ Log ${list[${INDEX}]} |
| 119 | \ ${value}= Get Dictionary Values ${list[${INDEX}]} |
| 120 | \ Log ${value[0]} |
| 121 | \ Run Keyword If '${value[0]}' == '${val}' Remove From List ${list} ${INDEX} |