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 | |
Kailash Khalasi | b6e87fc | 2017-04-18 15:08:19 -0700 | [diff] [blame] | 15 | *** Settings *** |
| 16 | Documentation Library for various utilities |
| 17 | Library SSHLibrary |
| 18 | Library HttpLibrary.HTTP |
| 19 | Library String |
| 20 | Library DateTime |
| 21 | Library Process |
| 22 | Library Collections |
| 23 | Library RequestsLibrary |
Kailash Khalasi | b6e87fc | 2017-04-18 15:08:19 -0700 | [diff] [blame] | 24 | |
| 25 | *** Keywords *** |
| 26 | Run Command On Remote System |
Kailash Khalasi | c930eac | 2018-09-05 12:18:23 -0700 | [diff] [blame] | 27 | [Arguments] ${ip} ${cmd} ${user} ${pass} ${prompt}=$ ${prompt_timeout}=60s |
Kailash Khalasi | b6e87fc | 2017-04-18 15:08:19 -0700 | [diff] [blame] | 28 | [Documentation] SSH's into a remote host, executes command, and logs+returns output |
| 29 | BuiltIn.Log Attempting to execute command "${cmd}" on remote system "${system}" |
Kailash Khalasi | c930eac | 2018-09-05 12:18:23 -0700 | [diff] [blame] | 30 | ${conn_id}= SSHLibrary.Open Connection ${ip} prompt=${prompt} timeout=${prompt_timeout} |
| 31 | SSHLibrary.Login ${user} ${pass} |
Kailash Khalasi | b6e87fc | 2017-04-18 15:08:19 -0700 | [diff] [blame] | 32 | ${output}= SSHLibrary.Execute Command ${cmd} |
| 33 | SSHLibrary.Close Connection |
| 34 | Log ${output} |
| 35 | [Return] ${output} |
| 36 | |
Kailash Khalasi | c930eac | 2018-09-05 12:18:23 -0700 | [diff] [blame] | 37 | Run Sudo Command On Remote System |
| 38 | [Arguments] ${ip} ${cmd} ${user} ${pass} ${prompt}=$ ${prompt_timeout}=60s |
| 39 | ${conn_id}= SSHLibrary.Open Connection ${ip} prompt=${prompt} timeout=${prompt_timeout} |
| 40 | SSHLibrary.Login ${user} ${pass} |
| 41 | SSHLibrary.Write ${cmd} |
| 42 | Read Until [sudo] password for ${user}: |
| 43 | SSHLibrary.Write ${pass} |
| 44 | ${result}= Read Until ${prompt} |
| 45 | SSHLibrary.Close Connection |
| 46 | Log ${result} |
| 47 | [Return] ${result} |
| 48 | |
Kailash Khalasi | b6e87fc | 2017-04-18 15:08:19 -0700 | [diff] [blame] | 49 | Execute Command on CIAB Server in Specific VM |
Kailash Khalasi | 2adbad8 | 2017-05-15 14:53:40 -0700 | [diff] [blame] | 50 | [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] | 51 | [Documentation] SSHs into ${HOST} where CIAB is running and executes a command in the Prod Vagrant VM where all the containers are running |
| 52 | ${conn_id}= SSHLibrary.Open Connection ${system} prompt=${prompt} timeout=300s |
| 53 | Run Keyword If '${use_key}' == 'False' SSHLibrary.Login ${user} ${pass} ELSE SSHLibrary.Login With Public Key ${user} %{HOME}/.ssh/${SSH_KEY} any |
| 54 | SSHLibrary.Write ssh ${vm} |
| 55 | SSHLibrary.Read Until Prompt |
| 56 | SSHLibrary.Write ${cmd} |
| 57 | ${output}= SSHLibrary.Read Until Prompt |
| 58 | SSHLibrary.Close Connection |
Kailash Khalasi | 2adbad8 | 2017-05-15 14:53:40 -0700 | [diff] [blame] | 59 | ${output_1}= Run Keyword If '${strip_line}' == 'True' Get Line ${output} 0 |
| 60 | ${output}= Set Variable If '${strip_line}' == 'True' ${output_1} ${output} |
Kailash Khalasi | b6e87fc | 2017-04-18 15:08:19 -0700 | [diff] [blame] | 61 | [Return] ${output} |
| 62 | |
| 63 | Execute Command on Compute Node in CIAB |
Kailash Khalasi | f6de259 | 2017-09-13 13:37:14 -0700 | [diff] [blame] | 64 | [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] | 65 | [Documentation] SSHs into ${HOST} where CIAB is running and executes a command in the Prod Vagrant VM where all the containers are running |
| 66 | ${conn_id}= SSHLibrary.Open Connection ${system} prompt=${prompt} timeout=300s |
| 67 | 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] | 68 | SSHLibrary.Write ssh ${node} |
Kailash Khalasi | b6e87fc | 2017-04-18 15:08:19 -0700 | [diff] [blame] | 69 | SSHLibrary.Read Until Prompt |
| 70 | SSHLibrary.Write ssh root@${hostname} |
| 71 | SSHLibrary.Read Until \# |
| 72 | SSHLibrary.Write ${cmd} |
| 73 | ${output}= SSHLibrary.Read Until \# |
| 74 | SSHLibrary.Close Connection |
| 75 | [Return] ${output} |
| 76 | |
Kailash Khalasi | 3a4e0f5 | 2017-06-01 16:35:59 -0700 | [diff] [blame] | 77 | Execute Command Locally |
| 78 | [Arguments] ${cmd} |
| 79 | ${output}= Run ${cmd} |
| 80 | [Return] ${output} |
| 81 | |
Kailash Khalasi | 2f567a4 | 2017-09-27 13:50:05 -0700 | [diff] [blame] | 82 | Execute ONOS Command |
| 83 | [Arguments] ${onos} ${port} ${cmd} ${user}=karaf ${pass}=karaf |
| 84 | ${conn_id}= SSHLibrary.Open Connection ${onos} port=${port} prompt=onos> timeout=300s |
| 85 | SSHLibrary.Login ${user} ${pass} |
| 86 | ${output}= SSHLibrary.Execute Command ${cmd} |
| 87 | SSHLibrary.Close Connection |
| 88 | [Return] ${output} |
| 89 | |
Kailash Khalasi | b6e87fc | 2017-04-18 15:08:19 -0700 | [diff] [blame] | 90 | Get Docker Container ID |
Kailash Khalasi | 2f567a4 | 2017-09-27 13:50:05 -0700 | [diff] [blame] | 91 | [Arguments] ${container_name} |
| 92 | [Documentation] Retrieves the id of the requested docker container running inside headnode |
| 93 | ${container_id}= Run docker ps | grep ${container_name} | awk '{print $1}' |
Kailash Khalasi | b6e87fc | 2017-04-18 15:08:19 -0700 | [diff] [blame] | 94 | Log ${container_id} |
| 95 | [Return] ${container_id} |
| 96 | |
| 97 | Get Docker Logs |
| 98 | [Arguments] ${system} ${container_id} ${user}=${USER} ${password}=${PASSWD} ${prompt}=prod:~$ |
| 99 | [Documentation] Retrieves the id of the requested docker container running inside given ${HOST} |
| 100 | ##In Ciab, all containers are run in the prod vm so we must log into that |
| 101 | ${conn_id}= SSHLibrary.Open Connection ${system} prompt=$ timeout=300s |
| 102 | SSHLibrary.Login With Public Key ${USER} %{HOME}/.ssh/${SSH_KEY} any |
| 103 | #SSHLibrary.Login ${HOST_USER} ${HOST_PASSWORD} |
Kailash Khalasi | f6de259 | 2017-09-13 13:37:14 -0700 | [diff] [blame] | 104 | SSHLibrary.Write ssh head1 |
Kailash Khalasi | b6e87fc | 2017-04-18 15:08:19 -0700 | [diff] [blame] | 105 | SSHLibrary.Read Until ${prompt} |
| 106 | SSHLibrary.Write docker logs -t ${container_id} |
| 107 | ${container_logs}= SSHLibrary.Read Until ${prompt} |
| 108 | SSHLibrary.Close Connection |
| 109 | Log ${container_logs} |
Kailash Khalasi | 2adbad8 | 2017-05-15 14:53:40 -0700 | [diff] [blame] | 110 | [Return] ${container_logs} |
Kailash Khalasi | 86e231e | 2017-06-06 13:13:43 -0700 | [diff] [blame] | 111 | |
| 112 | Remove Value From List |
| 113 | [Arguments] ${list} ${val} |
| 114 | ${length}= Get Length ${list} |
Kailash Khalasi | 2f567a4 | 2017-09-27 13:50:05 -0700 | [diff] [blame] | 115 | : FOR ${INDEX} IN RANGE 0 ${length} |
Kailash Khalasi | 86e231e | 2017-06-06 13:13:43 -0700 | [diff] [blame] | 116 | \ Log ${list[${INDEX}]} |
| 117 | \ ${value}= Get Dictionary Values ${list[${INDEX}]} |
| 118 | \ Log ${value[0]} |
| 119 | \ Run Keyword If '${value[0]}' == '${val}' Remove From List ${list} ${INDEX} |
Kailash Khalasi | 2f567a4 | 2017-09-27 13:50:05 -0700 | [diff] [blame] | 120 | \ Run Keyword If '${value[0]}' == '${val}' Exit For Loop |
| 121 | |
| 122 | Test Ping |
| 123 | [Arguments] ${interface} ${host} |
| 124 | [Documentation] Ping hosts to check connectivity |
| 125 | ${result}= Run ping -I ${interface} -c 5 ${host} |
| 126 | Should Contain ${result} 64 bytes |
Kailash Khalasi | c930eac | 2018-09-05 12:18:23 -0700 | [diff] [blame] | 127 | Should Not Contain ${result} Destination Host Unreachable |
| 128 | |
| 129 | Clean Up Objects |
| 130 | [Arguments] ${model_api} |
| 131 | ${auth} = Create List admin@opencord.org letmein |
| 132 | ${HEADERS} Create Dictionary Content-Type=application/json |
| 133 | Create Session ${server_ip} http://${server_ip}:${server_port} auth=${AUTH} headers=${HEADERS} |
| 134 | @{ids}= Create List |
| 135 | ${resp}= CORD Get ${model_api} |
| 136 | ${jsondata}= To Json ${resp.content} |
| 137 | Log ${jsondata} |
| 138 | ${length}= Get Length ${jsondata['items']} |
| 139 | : FOR ${INDEX} IN RANGE 0 ${length} |
| 140 | \ ${value}= Get From List ${jsondata['items']} ${INDEX} |
| 141 | \ ${id}= Get From Dictionary ${value} id |
| 142 | \ Append To List ${ids} ${id} |
| 143 | : FOR ${i} IN @{ids} |
| 144 | \ CORD Delete ${model_api} ${i} |
| 145 | Delete All Sessions |
| 146 | |
| 147 | CORD Get |
| 148 | [Documentation] Make a GET call to XOS |
| 149 | [Arguments] ${service} |
| 150 | ${resp}= Get Request ${server_ip} ${service} |
| 151 | Log ${resp.content} |
| 152 | Should Be Equal As Strings ${resp.status_code} 200 |
| 153 | [Return] ${resp} |
| 154 | |
| 155 | CORD Delete |
| 156 | [Documentation] Make a DELETE call to XOS |
| 157 | [Arguments] ${service} ${data_id} |
| 158 | ${resp}= Delete Request ${SERVER_IP} uri=${service}/${data_id} |
| 159 | Log ${resp.content} |
| 160 | Should Be Equal As Strings ${resp.status_code} 200 |
| 161 | [Return] ${resp} |