blob: cf8a771c1502f9093615c66a0b1493a9cb4f7718 [file] [log] [blame]
Gunaseelaned0eb1b2017-08-08 08:12:12 -05001# 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 Khalasib6e87fc2017-04-18 15:08:19 -070015*** Settings ***
16Documentation Library for various utilities
17Library SSHLibrary
18Library HttpLibrary.HTTP
19Library String
20Library DateTime
21Library Process
22Library Collections
23Library RequestsLibrary
Kailash Khalasib6e87fc2017-04-18 15:08:19 -070024
25*** Keywords ***
26Run Command On Remote System
Kailash Khalasic930eac2018-09-05 12:18:23 -070027 [Arguments] ${ip} ${cmd} ${user} ${pass} ${prompt}=$ ${prompt_timeout}=60s
Kailash Khalasib6e87fc2017-04-18 15:08:19 -070028 [Documentation] SSH's into a remote host, executes command, and logs+returns output
Kailash Khalasic930eac2018-09-05 12:18:23 -070029 ${conn_id}= SSHLibrary.Open Connection ${ip} prompt=${prompt} timeout=${prompt_timeout}
30 SSHLibrary.Login ${user} ${pass}
Kailash Khalasib6e87fc2017-04-18 15:08:19 -070031 ${output}= SSHLibrary.Execute Command ${cmd}
32 SSHLibrary.Close Connection
33 Log ${output}
34 [Return] ${output}
35
Kailash Khalasic930eac2018-09-05 12:18:23 -070036Run 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 Khalasib6e87fc2017-04-18 15:08:19 -070048Execute Command on CIAB Server in Specific VM
Kailash Khalasi2adbad82017-05-15 14:53:40 -070049 [Arguments] ${system} ${vm} ${cmd} ${user}=${VM_USER} ${password}=${VM_PASS} ${prompt}=$ ${use_key}=True ${strip_line}=True
Kailash Khalasib6e87fc2017-04-18 15:08:19 -070050 [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 Khalasi2adbad82017-05-15 14:53:40 -070058 ${output_1}= Run Keyword If '${strip_line}' == 'True' Get Line ${output} 0
59 ${output}= Set Variable If '${strip_line}' == 'True' ${output_1} ${output}
Kailash Khalasib6e87fc2017-04-18 15:08:19 -070060 [Return] ${output}
61
62Execute Command on Compute Node in CIAB
Kailash Khalasif6de2592017-09-13 13:37:14 -070063 [Arguments] ${system} ${node} ${hostname} ${cmd} ${user}=${VM_USER} ${password}=${VM_PASS} ${prompt}=$ ${use_key}=True
Kailash Khalasib6e87fc2017-04-18 15:08:19 -070064 [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 Khalasif6de2592017-09-13 13:37:14 -070067 SSHLibrary.Write ssh ${node}
Kailash Khalasib6e87fc2017-04-18 15:08:19 -070068 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 Khalasi3a4e0f52017-06-01 16:35:59 -070076Execute Command Locally
77 [Arguments] ${cmd}
78 ${output}= Run ${cmd}
79 [Return] ${output}
80
Kailash Khalasi2f567a42017-09-27 13:50:05 -070081Execute 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 Khalasib6e87fc2017-04-18 15:08:19 -070089Get Docker Container ID
Kailash Khalasi2f567a42017-09-27 13:50:05 -070090 [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 Khalasib6e87fc2017-04-18 15:08:19 -070093 Log ${container_id}
94 [Return] ${container_id}
95
96Get 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 Khalasif6de2592017-09-13 13:37:14 -0700103 SSHLibrary.Write ssh head1
Kailash Khalasib6e87fc2017-04-18 15:08:19 -0700104 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 Khalasi2adbad82017-05-15 14:53:40 -0700109 [Return] ${container_logs}
Kailash Khalasi86e231e2017-06-06 13:13:43 -0700110
111Remove Value From List
112 [Arguments] ${list} ${val}
113 ${length}= Get Length ${list}
Kailash Khalasi2f567a42017-09-27 13:50:05 -0700114 : FOR ${INDEX} IN RANGE 0 ${length}
Kailash Khalasi86e231e2017-06-06 13:13:43 -0700115 \ 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 Khalasi2f567a42017-09-27 13:50:05 -0700119 \ Run Keyword If '${value[0]}' == '${val}' Exit For Loop
120
121Test Ping
Kailash Khalasi422d1ab2018-09-18 09:54:26 -0700122 [Arguments] ${status} ${src} ${user} ${pass} ${dest} ${interface} ${prompt}=$ ${prompt_timeout}=60s
Kailash Khalasi55ca9f22018-09-17 17:36:55 -0700123 [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 Khalasi422d1ab2018-09-18 09:54:26 -0700126 ${result}= SSHLibrary.Execute Command ping -I ${interface} -c 5 ${dest}
Kailash Khalasi55ca9f22018-09-17 17:36:55 -0700127 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 Khalasic930eac2018-09-05 12:18:23 -0700140
141Clean Up Objects
142 [Arguments] ${model_api}
Kailash Khalasic930eac2018-09-05 12:18:23 -0700143 @{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 Khalasic930eac2018-09-05 12:18:23 -0700154
155CORD 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 Khalasif3e0a9f2018-09-18 13:43:42 -0700163CORD 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 Khalasi16d95c12018-09-21 14:17:28 -0700172CORD 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 Khalasic930eac2018-09-05 12:18:23 -0700183CORD 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 Khalasia0810ce2018-09-10 13:03:27 -0700190
Kailash Khalasif3e0a9f2018-09-18 13:43:42 -0700191Get 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 Khalasia0810ce2018-09-10 13:03:27 -0700202Kill Linux Process
203 [Arguments] ${ip} ${user} ${pass} ${process}
Kailash Khalasic8dfd0d2018-09-11 09:54:43 -0700204 ${rc}= Run Sudo Command On Remote System ${ip} sudo kill $(ps aux | grep '${process}' | awk '{print $2}'); echo $? ${user} ${pass}
Kailash Khalasi16d95c12018-09-21 14:17:28 -0700205 Should Contain ${rc} 0
You Wangaee35112018-09-28 16:07:49 -0700206
You Wang0c2b3662018-10-01 16:56:17 -0700207Check Remote File Contents
208 [Arguments] ${file_should_exist} ${conn_id} ${file_path} ${file_name} ${pattern}
You Wangaee35112018-09-28 16:07:49 -0700209 SSHLibrary.Switch Connection ${conn_id}
You Wang0c2b3662018-10-01 16:56:17 -0700210 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
215Check 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