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 | 2f567a4 | 2017-09-27 13:50:05 -0700 | [diff] [blame] | 92 | Execute ONOS Command |
| 93 | [Arguments] ${onos} ${port} ${cmd} ${user}=karaf ${pass}=karaf |
| 94 | ${conn_id}= SSHLibrary.Open Connection ${onos} port=${port} prompt=onos> timeout=300s |
| 95 | SSHLibrary.Login ${user} ${pass} |
| 96 | ${output}= SSHLibrary.Execute Command ${cmd} |
| 97 | SSHLibrary.Close Connection |
| 98 | [Return] ${output} |
| 99 | |
Kailash Khalasi | b6e87fc | 2017-04-18 15:08:19 -0700 | [diff] [blame] | 100 | Get Docker Container ID |
Kailash Khalasi | 2f567a4 | 2017-09-27 13:50:05 -0700 | [diff] [blame] | 101 | [Arguments] ${container_name} |
| 102 | [Documentation] Retrieves the id of the requested docker container running inside headnode |
| 103 | ${container_id}= Run docker ps | grep ${container_name} | awk '{print $1}' |
Kailash Khalasi | b6e87fc | 2017-04-18 15:08:19 -0700 | [diff] [blame] | 104 | Log ${container_id} |
| 105 | [Return] ${container_id} |
| 106 | |
| 107 | Get Docker Logs |
| 108 | [Arguments] ${system} ${container_id} ${user}=${USER} ${password}=${PASSWD} ${prompt}=prod:~$ |
| 109 | [Documentation] Retrieves the id of the requested docker container running inside given ${HOST} |
| 110 | ##In Ciab, all containers are run in the prod vm so we must log into that |
| 111 | ${conn_id}= SSHLibrary.Open Connection ${system} prompt=$ timeout=300s |
| 112 | SSHLibrary.Login With Public Key ${USER} %{HOME}/.ssh/${SSH_KEY} any |
| 113 | #SSHLibrary.Login ${HOST_USER} ${HOST_PASSWORD} |
Kailash Khalasi | f6de259 | 2017-09-13 13:37:14 -0700 | [diff] [blame] | 114 | SSHLibrary.Write ssh head1 |
Kailash Khalasi | b6e87fc | 2017-04-18 15:08:19 -0700 | [diff] [blame] | 115 | SSHLibrary.Read Until ${prompt} |
| 116 | SSHLibrary.Write docker logs -t ${container_id} |
| 117 | ${container_logs}= SSHLibrary.Read Until ${prompt} |
| 118 | SSHLibrary.Close Connection |
| 119 | Log ${container_logs} |
Kailash Khalasi | 2adbad8 | 2017-05-15 14:53:40 -0700 | [diff] [blame] | 120 | [Return] ${container_logs} |
Kailash Khalasi | 86e231e | 2017-06-06 13:13:43 -0700 | [diff] [blame] | 121 | |
| 122 | Remove Value From List |
| 123 | [Arguments] ${list} ${val} |
| 124 | ${length}= Get Length ${list} |
Kailash Khalasi | 2f567a4 | 2017-09-27 13:50:05 -0700 | [diff] [blame] | 125 | : FOR ${INDEX} IN RANGE 0 ${length} |
Kailash Khalasi | 86e231e | 2017-06-06 13:13:43 -0700 | [diff] [blame] | 126 | \ Log ${list[${INDEX}]} |
| 127 | \ ${value}= Get Dictionary Values ${list[${INDEX}]} |
| 128 | \ Log ${value[0]} |
| 129 | \ Run Keyword If '${value[0]}' == '${val}' Remove From List ${list} ${INDEX} |
Kailash Khalasi | 2f567a4 | 2017-09-27 13:50:05 -0700 | [diff] [blame] | 130 | \ Run Keyword If '${value[0]}' == '${val}' Exit For Loop |
| 131 | |
| 132 | Test Ping |
| 133 | [Arguments] ${interface} ${host} |
| 134 | [Documentation] Ping hosts to check connectivity |
| 135 | ${result}= Run ping -I ${interface} -c 5 ${host} |
| 136 | Should Contain ${result} 64 bytes |
| 137 | Should Not Contain ${result} Destination Host Unreachable |