blob: 2bf46f88a7e5c9c5ba7e1fac176ac4ab61b75647 [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 Khalasib6e87fc2017-04-18 15:08:19 -070092Get Docker Container ID
93 [Arguments] ${system} ${container_name} ${user}=${USER} ${password}=${PASSWD}
94 [Documentation] Retrieves the id of the requested docker container running inside given ${HOST}
Kailash Khalasic713e452017-09-13 13:37:14 -070095 ${container_id}= Execute Command on CIAB Server in Specific VM ${system} head1 docker ps | grep ${container_name} | awk '{print $1}' ${user} ${password}
Kailash Khalasib6e87fc2017-04-18 15:08:19 -070096 Log ${container_id}
97 [Return] ${container_id}
98
99Get Docker Logs
100 [Arguments] ${system} ${container_id} ${user}=${USER} ${password}=${PASSWD} ${prompt}=prod:~$
101 [Documentation] Retrieves the id of the requested docker container running inside given ${HOST}
102 ##In Ciab, all containers are run in the prod vm so we must log into that
103 ${conn_id}= SSHLibrary.Open Connection ${system} prompt=$ timeout=300s
104 SSHLibrary.Login With Public Key ${USER} %{HOME}/.ssh/${SSH_KEY} any
105 #SSHLibrary.Login ${HOST_USER} ${HOST_PASSWORD}
Kailash Khalasic713e452017-09-13 13:37:14 -0700106 SSHLibrary.Write ssh head1
Kailash Khalasib6e87fc2017-04-18 15:08:19 -0700107 SSHLibrary.Read Until ${prompt}
108 SSHLibrary.Write docker logs -t ${container_id}
109 ${container_logs}= SSHLibrary.Read Until ${prompt}
110 SSHLibrary.Close Connection
111 Log ${container_logs}
Kailash Khalasi2adbad82017-05-15 14:53:40 -0700112 [Return] ${container_logs}
Kailash Khalasi86e231e2017-06-06 13:13:43 -0700113
114Remove Value From List
115 [Arguments] ${list} ${val}
116 ${length}= Get Length ${list}
117 : FOR ${INDEX} IN RANGE 0 ${length}-1
118 \ Log ${list[${INDEX}]}
119 \ ${value}= Get Dictionary Values ${list[${INDEX}]}
120 \ Log ${value[0]}
121 \ Run Keyword If '${value[0]}' == '${val}' Remove From List ${list} ${INDEX}