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