blob: db559e56133dec2b1eff6e7f7420d40ad2cea220 [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
15# Copyright 2017-present Radisys Corporation
16#
17# Licensed under the Apache License, Version 2.0 (the "License");
18# you may not use this file except in compliance with the License.
19# You may obtain a copy of the License at
20#
21# http://www.apache.org/licenses/LICENSE-2.0
22#
23# Unless required by applicable law or agreed to in writing, software
24# distributed under the License is distributed on an "AS IS" BASIS,
25# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
26# See the License for the specific language governing permissions and
27# limitations under the License.
28
29
30
Kailash Khalasib6e87fc2017-04-18 15:08:19 -070031*** Settings ***
32Documentation Library for various utilities
33Library SSHLibrary
34Library HttpLibrary.HTTP
35Library String
36Library DateTime
37Library Process
38Library Collections
39Library RequestsLibrary
40#Library ${CURDIR}/readProperties.py
41#Resource ${CURDIR}/utils.py
Gunaseelaned0eb1b2017-08-08 08:12:12 -050042*** Variables ***
43${SSH_KEY}= id_rsa
Kailash Khalasib6e87fc2017-04-18 15:08:19 -070044
45*** Keywords ***
46Run Command On Remote System
47 [Arguments] ${system} ${cmd} ${user}=${VM_USER} ${pass}=${VM_PASS} ${prompt}=$ ${prompt_timeout}=60s ${use_key}=False
48 [Documentation] SSH's into a remote host, executes command, and logs+returns output
49 BuiltIn.Log Attempting to execute command "${cmd}" on remote system "${system}"
Gunaseelaned0eb1b2017-08-08 08:12:12 -050050 BuiltIn.Log ${pass}
Kailash Khalasib6e87fc2017-04-18 15:08:19 -070051 ${conn_id}= SSHLibrary.Open Connection ${system} prompt=${prompt} timeout=${prompt_timeout}
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.Login ${user} ${pass}
54 ${output}= SSHLibrary.Execute Command ${cmd}
55 SSHLibrary.Close Connection
56 Log ${output}
57 [Return] ${output}
58
59Execute Command on CIAB Server in Specific VM
Kailash Khalasi2adbad82017-05-15 14:53:40 -070060 [Arguments] ${system} ${vm} ${cmd} ${user}=${VM_USER} ${password}=${VM_PASS} ${prompt}=$ ${use_key}=True ${strip_line}=True
Kailash Khalasib6e87fc2017-04-18 15:08:19 -070061 [Documentation] SSHs into ${HOST} where CIAB is running and executes a command in the Prod Vagrant VM where all the containers are running
62 ${conn_id}= SSHLibrary.Open Connection ${system} prompt=${prompt} timeout=300s
63 Run Keyword If '${use_key}' == 'False' SSHLibrary.Login ${user} ${pass} ELSE SSHLibrary.Login With Public Key ${user} %{HOME}/.ssh/${SSH_KEY} any
64 SSHLibrary.Write ssh ${vm}
65 SSHLibrary.Read Until Prompt
66 SSHLibrary.Write ${cmd}
67 ${output}= SSHLibrary.Read Until Prompt
68 SSHLibrary.Close Connection
Kailash Khalasi2adbad82017-05-15 14:53:40 -070069 ${output_1}= Run Keyword If '${strip_line}' == 'True' Get Line ${output} 0
70 ${output}= Set Variable If '${strip_line}' == 'True' ${output_1} ${output}
Kailash Khalasib6e87fc2017-04-18 15:08:19 -070071 [Return] ${output}
72
73Execute Command on Compute Node in CIAB
Kailash Khalasic713e452017-09-13 13:37:14 -070074 [Arguments] ${system} ${node} ${hostname} ${cmd} ${user}=${VM_USER} ${password}=${VM_PASS} ${prompt}=$ ${use_key}=True
Kailash Khalasib6e87fc2017-04-18 15:08:19 -070075 [Documentation] SSHs into ${HOST} where CIAB is running and executes a command in the Prod Vagrant VM where all the containers are running
76 ${conn_id}= SSHLibrary.Open Connection ${system} prompt=${prompt} timeout=300s
77 Run Keyword If '${use_key}' == 'False' SSHLibrary.Login ${user} ${pass} ELSE SSHLibrary.Login With Public Key ${user} %{HOME}/.ssh/${SSH_KEY} any
Kailash Khalasic713e452017-09-13 13:37:14 -070078 SSHLibrary.Write ssh ${node}
Kailash Khalasib6e87fc2017-04-18 15:08:19 -070079 SSHLibrary.Read Until Prompt
80 SSHLibrary.Write ssh root@${hostname}
81 SSHLibrary.Read Until \#
82 SSHLibrary.Write ${cmd}
83 ${output}= SSHLibrary.Read Until \#
84 SSHLibrary.Close Connection
85 [Return] ${output}
86
Kailash Khalasi3a4e0f52017-06-01 16:35:59 -070087Execute Command Locally
88 [Arguments] ${cmd}
89 ${output}= Run ${cmd}
90 [Return] ${output}
91
Kailash Khalasi8c34e852017-09-27 13:50:05 -070092Execute ONOS Command
93 [Arguments] ${onos} ${port} ${cmd} ${user}=karaf ${pass}=karaf
94 ${conn_id}= SSHLibrary.Open Connection ${onos} port=${port} prompt=onos> timeout=300s
95 SSHLibrary.Login ${user} ${pass}
96 ${output}= SSHLibrary.Execute Command ${cmd}
97 SSHLibrary.Close Connection
98 [Return] ${output}
99
Kailash Khalasib6e87fc2017-04-18 15:08:19 -0700100Get Docker Container ID
Kailash Khalasi8c34e852017-09-27 13:50:05 -0700101 [Arguments] ${container_name}
102 [Documentation] Retrieves the id of the requested docker container running inside headnode
103 ${container_id}= Run docker ps | grep ${container_name} | awk '{print $1}'
Kailash Khalasib6e87fc2017-04-18 15:08:19 -0700104 Log ${container_id}
105 [Return] ${container_id}
106
107Get Docker Logs
108 [Arguments] ${system} ${container_id} ${user}=${USER} ${password}=${PASSWD} ${prompt}=prod:~$
109 [Documentation] Retrieves the id of the requested docker container running inside given ${HOST}
110 ##In Ciab, all containers are run in the prod vm so we must log into that
111 ${conn_id}= SSHLibrary.Open Connection ${system} prompt=$ timeout=300s
112 SSHLibrary.Login With Public Key ${USER} %{HOME}/.ssh/${SSH_KEY} any
113 #SSHLibrary.Login ${HOST_USER} ${HOST_PASSWORD}
Kailash Khalasic713e452017-09-13 13:37:14 -0700114 SSHLibrary.Write ssh head1
Kailash Khalasib6e87fc2017-04-18 15:08:19 -0700115 SSHLibrary.Read Until ${prompt}
116 SSHLibrary.Write docker logs -t ${container_id}
117 ${container_logs}= SSHLibrary.Read Until ${prompt}
118 SSHLibrary.Close Connection
119 Log ${container_logs}
Kailash Khalasi2adbad82017-05-15 14:53:40 -0700120 [Return] ${container_logs}
Kailash Khalasi86e231e2017-06-06 13:13:43 -0700121
122Remove Value From List
123 [Arguments] ${list} ${val}
124 ${length}= Get Length ${list}
Kailash Khalasi8c34e852017-09-27 13:50:05 -0700125 : FOR ${INDEX} IN RANGE 0 ${length}
Kailash Khalasi86e231e2017-06-06 13:13:43 -0700126 \ Log ${list[${INDEX}]}
127 \ ${value}= Get Dictionary Values ${list[${INDEX}]}
128 \ Log ${value[0]}
129 \ Run Keyword If '${value[0]}' == '${val}' Remove From List ${list} ${INDEX}
Kailash Khalasi8c34e852017-09-27 13:50:05 -0700130 \ Run Keyword If '${value[0]}' == '${val}' Exit For Loop
131
132Test Ping
133 [Arguments] ${interface} ${host}
134 [Documentation] Ping hosts to check connectivity
135 ${result}= Run ping -I ${interface} -c 5 ${host}
136 Should Contain ${result} 64 bytes
137 Should Not Contain ${result} Destination Host Unreachable