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 |
Kailash Khalasi | c930eac | 2018-09-05 12:18:23 -0700 | [diff] [blame] | 29 | ${conn_id}= SSHLibrary.Open Connection ${ip} prompt=${prompt} timeout=${prompt_timeout} |
| 30 | SSHLibrary.Login ${user} ${pass} |
Kailash Khalasi | b6e87fc | 2017-04-18 15:08:19 -0700 | [diff] [blame] | 31 | ${output}= SSHLibrary.Execute Command ${cmd} |
| 32 | SSHLibrary.Close Connection |
| 33 | Log ${output} |
| 34 | [Return] ${output} |
| 35 | |
Kailash Khalasi | c930eac | 2018-09-05 12:18:23 -0700 | [diff] [blame] | 36 | Run Sudo Command On Remote System |
| 37 | [Arguments] ${ip} ${cmd} ${user} ${pass} ${prompt}=$ ${prompt_timeout}=60s |
| 38 | ${conn_id}= SSHLibrary.Open Connection ${ip} prompt=${prompt} timeout=${prompt_timeout} |
| 39 | SSHLibrary.Login ${user} ${pass} |
| 40 | SSHLibrary.Write ${cmd} |
| 41 | Read Until [sudo] password for ${user}: |
| 42 | SSHLibrary.Write ${pass} |
| 43 | ${result}= Read Until ${prompt} |
| 44 | SSHLibrary.Close Connection |
| 45 | Log ${result} |
| 46 | [Return] ${result} |
| 47 | |
Kailash Khalasi | b6e87fc | 2017-04-18 15:08:19 -0700 | [diff] [blame] | 48 | Execute Command on CIAB Server in Specific VM |
Kailash Khalasi | 2adbad8 | 2017-05-15 14:53:40 -0700 | [diff] [blame] | 49 | [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] | 50 | [Documentation] SSHs into ${HOST} where CIAB is running and executes a command in the Prod Vagrant VM where all the containers are running |
| 51 | ${conn_id}= SSHLibrary.Open Connection ${system} prompt=${prompt} timeout=300s |
| 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.Write ssh ${vm} |
| 54 | SSHLibrary.Read Until Prompt |
| 55 | SSHLibrary.Write ${cmd} |
| 56 | ${output}= SSHLibrary.Read Until Prompt |
| 57 | SSHLibrary.Close Connection |
Kailash Khalasi | 2adbad8 | 2017-05-15 14:53:40 -0700 | [diff] [blame] | 58 | ${output_1}= Run Keyword If '${strip_line}' == 'True' Get Line ${output} 0 |
| 59 | ${output}= Set Variable If '${strip_line}' == 'True' ${output_1} ${output} |
Kailash Khalasi | b6e87fc | 2017-04-18 15:08:19 -0700 | [diff] [blame] | 60 | [Return] ${output} |
| 61 | |
| 62 | Execute Command on Compute Node in CIAB |
Kailash Khalasi | f6de259 | 2017-09-13 13:37:14 -0700 | [diff] [blame] | 63 | [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] | 64 | [Documentation] SSHs into ${HOST} where CIAB is running and executes a command in the Prod Vagrant VM where all the containers are running |
| 65 | ${conn_id}= SSHLibrary.Open Connection ${system} prompt=${prompt} timeout=300s |
| 66 | 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] | 67 | SSHLibrary.Write ssh ${node} |
Kailash Khalasi | b6e87fc | 2017-04-18 15:08:19 -0700 | [diff] [blame] | 68 | SSHLibrary.Read Until Prompt |
| 69 | SSHLibrary.Write ssh root@${hostname} |
| 70 | SSHLibrary.Read Until \# |
| 71 | SSHLibrary.Write ${cmd} |
| 72 | ${output}= SSHLibrary.Read Until \# |
| 73 | SSHLibrary.Close Connection |
| 74 | [Return] ${output} |
| 75 | |
Kailash Khalasi | 3a4e0f5 | 2017-06-01 16:35:59 -0700 | [diff] [blame] | 76 | Execute Command Locally |
| 77 | [Arguments] ${cmd} |
| 78 | ${output}= Run ${cmd} |
| 79 | [Return] ${output} |
| 80 | |
Kailash Khalasi | 2f567a4 | 2017-09-27 13:50:05 -0700 | [diff] [blame] | 81 | Execute ONOS Command |
| 82 | [Arguments] ${onos} ${port} ${cmd} ${user}=karaf ${pass}=karaf |
| 83 | ${conn_id}= SSHLibrary.Open Connection ${onos} port=${port} prompt=onos> timeout=300s |
| 84 | SSHLibrary.Login ${user} ${pass} |
| 85 | ${output}= SSHLibrary.Execute Command ${cmd} |
| 86 | SSHLibrary.Close Connection |
| 87 | [Return] ${output} |
| 88 | |
Kailash Khalasi | b6e87fc | 2017-04-18 15:08:19 -0700 | [diff] [blame] | 89 | Get Docker Container ID |
Kailash Khalasi | 2f567a4 | 2017-09-27 13:50:05 -0700 | [diff] [blame] | 90 | [Arguments] ${container_name} |
| 91 | [Documentation] Retrieves the id of the requested docker container running inside headnode |
| 92 | ${container_id}= Run docker ps | grep ${container_name} | awk '{print $1}' |
Kailash Khalasi | b6e87fc | 2017-04-18 15:08:19 -0700 | [diff] [blame] | 93 | Log ${container_id} |
| 94 | [Return] ${container_id} |
| 95 | |
| 96 | Get Docker Logs |
| 97 | [Arguments] ${system} ${container_id} ${user}=${USER} ${password}=${PASSWD} ${prompt}=prod:~$ |
| 98 | [Documentation] Retrieves the id of the requested docker container running inside given ${HOST} |
| 99 | ##In Ciab, all containers are run in the prod vm so we must log into that |
| 100 | ${conn_id}= SSHLibrary.Open Connection ${system} prompt=$ timeout=300s |
| 101 | SSHLibrary.Login With Public Key ${USER} %{HOME}/.ssh/${SSH_KEY} any |
| 102 | #SSHLibrary.Login ${HOST_USER} ${HOST_PASSWORD} |
Kailash Khalasi | f6de259 | 2017-09-13 13:37:14 -0700 | [diff] [blame] | 103 | SSHLibrary.Write ssh head1 |
Kailash Khalasi | b6e87fc | 2017-04-18 15:08:19 -0700 | [diff] [blame] | 104 | SSHLibrary.Read Until ${prompt} |
| 105 | SSHLibrary.Write docker logs -t ${container_id} |
| 106 | ${container_logs}= SSHLibrary.Read Until ${prompt} |
| 107 | SSHLibrary.Close Connection |
| 108 | Log ${container_logs} |
Kailash Khalasi | 2adbad8 | 2017-05-15 14:53:40 -0700 | [diff] [blame] | 109 | [Return] ${container_logs} |
Kailash Khalasi | 86e231e | 2017-06-06 13:13:43 -0700 | [diff] [blame] | 110 | |
| 111 | Remove Value From List |
| 112 | [Arguments] ${list} ${val} |
| 113 | ${length}= Get Length ${list} |
Kailash Khalasi | 2f567a4 | 2017-09-27 13:50:05 -0700 | [diff] [blame] | 114 | : FOR ${INDEX} IN RANGE 0 ${length} |
Kailash Khalasi | 86e231e | 2017-06-06 13:13:43 -0700 | [diff] [blame] | 115 | \ Log ${list[${INDEX}]} |
| 116 | \ ${value}= Get Dictionary Values ${list[${INDEX}]} |
| 117 | \ Log ${value[0]} |
| 118 | \ Run Keyword If '${value[0]}' == '${val}' Remove From List ${list} ${INDEX} |
Kailash Khalasi | 2f567a4 | 2017-09-27 13:50:05 -0700 | [diff] [blame] | 119 | \ Run Keyword If '${value[0]}' == '${val}' Exit For Loop |
| 120 | |
| 121 | Test Ping |
Kailash Khalasi | 422d1ab | 2018-09-18 09:54:26 -0700 | [diff] [blame] | 122 | [Arguments] ${status} ${src} ${user} ${pass} ${dest} ${interface} ${prompt}=$ ${prompt_timeout}=60s |
Kailash Khalasi | 55ca9f2 | 2018-09-17 17:36:55 -0700 | [diff] [blame] | 123 | [Documentation] SSH's into src and attempts to ping dest. Status determines if ping should pass | fail |
| 124 | ${conn_id}= SSHLibrary.Open Connection ${src} prompt=${prompt} timeout=${prompt_timeout} |
| 125 | SSHLibrary.Login ${user} ${pass} |
Kailash Khalasi | 422d1ab | 2018-09-18 09:54:26 -0700 | [diff] [blame] | 126 | ${result}= SSHLibrary.Execute Command ping -I ${interface} -c 5 ${dest} |
Kailash Khalasi | 55ca9f2 | 2018-09-17 17:36:55 -0700 | [diff] [blame] | 127 | SSHLibrary.Close Connection |
| 128 | Log ${result} |
| 129 | Run Keyword If '${status}' == 'PASS' Should Contain ${result} 64 bytes |
| 130 | Run Keyword If '${status}' == 'PASS' Should Contain ${result} 0% packet loss |
| 131 | Run Keyword If '${status}' == 'PASS' Should Not Contain ${result} 100% packet loss |
| 132 | Run Keyword If '${status}' == 'PASS' Should Not Contain ${result} 80% packet loss |
| 133 | Run Keyword If '${status}' == 'PASS' Should Not Contain ${result} 60% packet loss |
| 134 | Run Keyword If '${status}' == 'PASS' Should Not Contain ${result} 40% packet loss |
| 135 | Run Keyword If '${status}' == 'PASS' Should Not Contain ${result} 20% packet loss |
| 136 | Run Keyword If '${status}' == 'PASS' Should Not Contain ${result} Destination Host Unreachable |
| 137 | Run Keyword If '${status}' == 'FAIL' Should Not Contain ${result} 64 bytes |
| 138 | Run Keyword If '${status}' == 'FAIL' Should Contain ${result} 100% packet loss |
| 139 | Log To Console \n ${result} |
Kailash Khalasi | c930eac | 2018-09-05 12:18:23 -0700 | [diff] [blame] | 140 | |
| 141 | Clean Up Objects |
| 142 | [Arguments] ${model_api} |
Kailash Khalasi | c930eac | 2018-09-05 12:18:23 -0700 | [diff] [blame] | 143 | @{ids}= Create List |
| 144 | ${resp}= CORD Get ${model_api} |
| 145 | ${jsondata}= To Json ${resp.content} |
| 146 | Log ${jsondata} |
| 147 | ${length}= Get Length ${jsondata['items']} |
| 148 | : FOR ${INDEX} IN RANGE 0 ${length} |
| 149 | \ ${value}= Get From List ${jsondata['items']} ${INDEX} |
| 150 | \ ${id}= Get From Dictionary ${value} id |
| 151 | \ Append To List ${ids} ${id} |
| 152 | : FOR ${i} IN @{ids} |
| 153 | \ CORD Delete ${model_api} ${i} |
Kailash Khalasi | c930eac | 2018-09-05 12:18:23 -0700 | [diff] [blame] | 154 | |
| 155 | CORD Get |
| 156 | [Documentation] Make a GET call to XOS |
| 157 | [Arguments] ${service} |
| 158 | ${resp}= Get Request ${server_ip} ${service} |
| 159 | Log ${resp.content} |
| 160 | Should Be Equal As Strings ${resp.status_code} 200 |
| 161 | [Return] ${resp} |
| 162 | |
Kailash Khalasi | f3e0a9f | 2018-09-18 13:43:42 -0700 | [diff] [blame] | 163 | CORD Post |
| 164 | [Documentation] Make a POST call to XOS |
| 165 | [Arguments] ${service} ${data} |
| 166 | ${data}= Evaluate json.dumps(${data}) json |
| 167 | ${resp}= Post Request ${SERVER_IP} uri=${service} data=${data} |
| 168 | Log ${resp.content} |
| 169 | Should Be Equal As Strings ${resp.status_code} 200 |
| 170 | [Return] ${resp} |
| 171 | |
Kailash Khalasi | 16d95c1 | 2018-09-21 14:17:28 -0700 | [diff] [blame] | 172 | CORD Put |
| 173 | [Documentation] Make a PUT call to XOS |
| 174 | [Arguments] ${service} ${data} ${data_id} |
| 175 | ${data}= Evaluate json.dumps(${data}) json |
| 176 | ${resp}= Put Request ${SERVER_IP} uri=${service}/${data_id} data=${data} |
| 177 | Log ${resp.content} |
| 178 | Should Be Equal As Strings ${resp.status_code} 200 |
| 179 | ${id}= Get Json Value ${resp.content} /id |
| 180 | Set Suite Variable ${id} |
| 181 | [Return] ${resp} |
| 182 | |
Kailash Khalasi | c930eac | 2018-09-05 12:18:23 -0700 | [diff] [blame] | 183 | CORD Delete |
| 184 | [Documentation] Make a DELETE call to XOS |
| 185 | [Arguments] ${service} ${data_id} |
| 186 | ${resp}= Delete Request ${SERVER_IP} uri=${service}/${data_id} |
| 187 | Log ${resp.content} |
| 188 | Should Be Equal As Strings ${resp.status_code} 200 |
| 189 | [Return] ${resp} |
Kailash Khalasi | a0810ce | 2018-09-10 13:03:27 -0700 | [diff] [blame] | 190 | |
Kailash Khalasi | f3e0a9f | 2018-09-18 13:43:42 -0700 | [diff] [blame] | 191 | Get Service Owner Id |
| 192 | [Arguments] ${service} |
| 193 | ${resp}= CORD Get ${service} |
| 194 | ${jsondata}= To Json ${resp.content} |
| 195 | log ${jsondata} |
| 196 | ${length}= Get Length ${jsondata['items']} |
| 197 | : for ${INDEX} IN RANGE 0 ${length} |
| 198 | \ ${value}= Get From List ${jsondata['items']} ${INDEX} |
| 199 | \ ${id}= Get From Dictionary ${value} id |
| 200 | [Return] ${id} |
| 201 | |
Kailash Khalasi | a0810ce | 2018-09-10 13:03:27 -0700 | [diff] [blame] | 202 | Kill Linux Process |
| 203 | [Arguments] ${ip} ${user} ${pass} ${process} |
Kailash Khalasi | c8dfd0d | 2018-09-11 09:54:43 -0700 | [diff] [blame] | 204 | ${rc}= Run Sudo Command On Remote System ${ip} sudo kill $(ps aux | grep '${process}' | awk '{print $2}'); echo $? ${user} ${pass} |
Kailash Khalasi | 16d95c1 | 2018-09-21 14:17:28 -0700 | [diff] [blame] | 205 | Should Contain ${rc} 0 |
You Wang | aee3511 | 2018-09-28 16:07:49 -0700 | [diff] [blame] | 206 | |
You Wang | 0c2b366 | 2018-10-01 16:56:17 -0700 | [diff] [blame] | 207 | Check Remote File Contents |
| 208 | [Arguments] ${file_should_exist} ${conn_id} ${file_path} ${file_name} ${pattern} |
You Wang | aee3511 | 2018-09-28 16:07:49 -0700 | [diff] [blame] | 209 | SSHLibrary.Switch Connection ${conn_id} |
You Wang | 0c2b366 | 2018-10-01 16:56:17 -0700 | [diff] [blame] | 210 | SSHLibrary.Get File ${file_path}${file_name} /tmp/ |
| 211 | ${content}= OperatingSystem.Get File /tmp/${file_name} encoding_errors=ignore |
| 212 | Run Keyword If '${file_should_exist}' == 'True' Should Contain ${content} ${pattern} |
| 213 | Run Keyword If '${file_should_exist}' == 'False' Should Not Contain ${content} ${pattern} |
| 214 | |
| 215 | Check Remote System Reachability |
| 216 | [Arguments] ${reachable} ${ip} ${prompt}=$ ${prompt_timeout}=60s |
| 217 | [Documentation] Check if the specified IP address is reachable or not |
| 218 | ${result}= Run ping -c 3 -t 3 ${ip} |
| 219 | Log ${result} |
| 220 | Run Keyword If '${reachable}' == 'True' Should Contain ${result} 64 bytes |
| 221 | Run Keyword If '${reachable}' == 'True' Should Contain Any ${result} 0% packet loss 0.0% packet loss |
| 222 | Run Keyword If '${reachable}' == 'True' Should Not Contain Any ${result} 100% packet loss 100.0% packet loss |
| 223 | Run Keyword If '${reachable}' == 'False' Should Not Contain ${result} 64 bytes |
| 224 | Run Keyword If '${reachable}' == 'False' Should Contain Any ${result} 100% packet loss 100.0% packet loss |