blob: d19b89d140c6d50773df918c0699ac0b452ac3ec [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
29 BuiltIn.Log Attempting to execute command "${cmd}" on remote system "${system}"
Kailash Khalasic930eac2018-09-05 12:18:23 -070030 ${conn_id}= SSHLibrary.Open Connection ${ip} prompt=${prompt} timeout=${prompt_timeout}
31 SSHLibrary.Login ${user} ${pass}
Kailash Khalasib6e87fc2017-04-18 15:08:19 -070032 ${output}= SSHLibrary.Execute Command ${cmd}
33 SSHLibrary.Close Connection
34 Log ${output}
35 [Return] ${output}
36
Kailash Khalasic930eac2018-09-05 12:18:23 -070037Run 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 Khalasib6e87fc2017-04-18 15:08:19 -070049Execute Command on CIAB Server in Specific VM
Kailash Khalasi2adbad82017-05-15 14:53:40 -070050 [Arguments] ${system} ${vm} ${cmd} ${user}=${VM_USER} ${password}=${VM_PASS} ${prompt}=$ ${use_key}=True ${strip_line}=True
Kailash Khalasib6e87fc2017-04-18 15:08:19 -070051 [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 Khalasi2adbad82017-05-15 14:53:40 -070059 ${output_1}= Run Keyword If '${strip_line}' == 'True' Get Line ${output} 0
60 ${output}= Set Variable If '${strip_line}' == 'True' ${output_1} ${output}
Kailash Khalasib6e87fc2017-04-18 15:08:19 -070061 [Return] ${output}
62
63Execute Command on Compute Node in CIAB
Kailash Khalasif6de2592017-09-13 13:37:14 -070064 [Arguments] ${system} ${node} ${hostname} ${cmd} ${user}=${VM_USER} ${password}=${VM_PASS} ${prompt}=$ ${use_key}=True
Kailash Khalasib6e87fc2017-04-18 15:08:19 -070065 [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 Khalasif6de2592017-09-13 13:37:14 -070068 SSHLibrary.Write ssh ${node}
Kailash Khalasib6e87fc2017-04-18 15:08:19 -070069 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 Khalasi3a4e0f52017-06-01 16:35:59 -070077Execute Command Locally
78 [Arguments] ${cmd}
79 ${output}= Run ${cmd}
80 [Return] ${output}
81
Kailash Khalasi2f567a42017-09-27 13:50:05 -070082Execute 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 Khalasib6e87fc2017-04-18 15:08:19 -070090Get Docker Container ID
Kailash Khalasi2f567a42017-09-27 13:50:05 -070091 [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 Khalasib6e87fc2017-04-18 15:08:19 -070094 Log ${container_id}
95 [Return] ${container_id}
96
97Get 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 Khalasif6de2592017-09-13 13:37:14 -0700104 SSHLibrary.Write ssh head1
Kailash Khalasib6e87fc2017-04-18 15:08:19 -0700105 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 Khalasi2adbad82017-05-15 14:53:40 -0700110 [Return] ${container_logs}
Kailash Khalasi86e231e2017-06-06 13:13:43 -0700111
112Remove Value From List
113 [Arguments] ${list} ${val}
114 ${length}= Get Length ${list}
Kailash Khalasi2f567a42017-09-27 13:50:05 -0700115 : FOR ${INDEX} IN RANGE 0 ${length}
Kailash Khalasi86e231e2017-06-06 13:13:43 -0700116 \ 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 Khalasi2f567a42017-09-27 13:50:05 -0700120 \ Run Keyword If '${value[0]}' == '${val}' Exit For Loop
121
122Test 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 Khalasic930eac2018-09-05 12:18:23 -0700127 Should Not Contain ${result} Destination Host Unreachable
128
129Clean 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
147CORD 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
155CORD 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}
Kailash Khalasia0810ce2018-09-10 13:03:27 -0700162
163Kill Linux Process
164 [Arguments] ${ip} ${user} ${pass} ${process}
165 Run Sudo Command On Remote System ${ip} sudo kill $(ps aux | grep '${process}' | awk '{print $2}') ${user} ${pass}