Zack Williams | 821c502 | 2020-01-15 15:11:46 -0700 | [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 | |
| 15 | *** Settings *** |
| 16 | Documentation Library for CORD-in-a-Box |
| 17 | Library SSHLibrary |
| 18 | Resource utils.resource |
| 19 | |
| 20 | *** Keywords *** |
| 21 | Execute Command on CIAB Server in Specific VM |
| 22 | [Documentation] SSHs into ${HOST} where CIAB is running and executes a |
| 23 | ... command in the Prod Vagrant VM where all the containers are running |
| 24 | [Arguments] ${system} ${vm} ${cmd} |
| 25 | ... ${user}=${VM_USER} ${password}=${VM_PASS} |
| 26 | ... ${prompt}=$ ${use_key}=True ${strip_line}=True |
| 27 | ${conn_id}= SSHLibrary.Open Connection ${system} prompt=${prompt} timeout=300s |
| 28 | Run Keyword If '${use_key}' == 'False' |
| 29 | ... SSHLibrary.Login ${user} ${pass} |
| 30 | ... ELSE |
| 31 | ... SSHLibrary.Login With Public Key ${user} %{HOME}/.ssh/${SSH_KEY} any |
| 32 | SSHLibrary.Write ssh ${vm} |
| 33 | SSHLibrary.Read Until Prompt |
| 34 | SSHLibrary.Write ${cmd} |
| 35 | ${output}= SSHLibrary.Read Until Prompt |
| 36 | SSHLibrary.Close Connection |
| 37 | ${output_1}= Run Keyword If '${strip_line}' == 'True' Get Line ${output} 0 |
| 38 | ${output}= Set Variable If '${strip_line}' == 'True' ${output_1} ${output} |
| 39 | [Return] ${output} |
| 40 | |
| 41 | Execute Command on Compute Node in CIAB |
| 42 | [Documentation] SSHs into ${system} where CIAB is running and executes a |
| 43 | ... command in the Prod Vagrant VM where all the containers are running |
| 44 | [Arguments] ${system} ${node} ${hostname} ${cmd} |
| 45 | ... ${user}=${VM_USER} ${password}=${VM_PASS} ${prompt}=$ ${use_key}=True |
| 46 | ${conn_id}= SSHLibrary.Open Connection ${system} prompt=${prompt} timeout=300s |
| 47 | # FIXME: Truthy comparison of strings |
| 48 | Run Keyword If '${use_key}' == 'False' |
| 49 | ... SSHLibrary.Login ${user} ${pass} |
| 50 | ... ELSE |
| 51 | ... SSHLibrary.Login With Public Key ${user} %{HOME}/.ssh/${SSH_KEY} any |
| 52 | SSHLibrary.Write ssh ${node} |
| 53 | SSHLibrary.Read Until Prompt |
| 54 | SSHLibrary.Write ssh root@${hostname} |
| 55 | SSHLibrary.Read Until \# |
| 56 | SSHLibrary.Write ${cmd} |
| 57 | ${output}= SSHLibrary.Read Until \# |
| 58 | SSHLibrary.Close Connection |
| 59 | [Return] ${output} |
| 60 | |
| 61 | Get Docker Logs |
| 62 | ##In Ciab, all containers are run in the prod vm so we must log into that |
| 63 | [Documentation] Retrieves the logs of a docker container running inside |
| 64 | ... given ${system} |
| 65 | [Arguments] ${system} ${container_id} |
| 66 | ... ${user}=${USER} ${password}=${PASSWD} ${prompt}=prod:~$ |
| 67 | ${conn_id}= SSHLibrary.Open Connection ${system} prompt=$ timeout=300s |
| 68 | SSHLibrary.Login With Public Key ${USER} %{HOME}/.ssh/${SSH_KEY} any |
| 69 | #SSHLibrary.Login ${HOST_USER} ${HOST_PASSWORD} |
| 70 | SSHLibrary.Write ssh head1 |
| 71 | SSHLibrary.Read Until ${prompt} |
| 72 | SSHLibrary.Write docker logs -t ${container_id} |
| 73 | ${container_logs}= SSHLibrary.Read Until ${prompt} |
| 74 | SSHLibrary.Close Connection |
| 75 | Log ${container_logs} |
| 76 | [Return] ${container_logs} |