| Felipe Vicens | f96bb45 | 2020-06-22 08:12:30 +0200 | [diff] [blame] | 1 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 2 | # you may not use this file except in compliance with the License. |
| 3 | # You may obtain a copy of the License at |
| 4 | # |
| 5 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | # |
| 7 | # Unless required by applicable law or agreed to in writing, software |
| 8 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 10 | # See the License for the specific language governing permissions and |
| 11 | # limitations under the License. |
| 12 | |
| 13 | *** Keywords *** |
| 14 | Test SSH Connection |
| 15 | [Arguments] ${host} ${username} ${password} ${privatekey} |
| 16 | |
| garciadeblas | f4ebaa8 | 2022-06-23 13:33:26 +0200 | [diff] [blame] | 17 | Open Connection ${host} |
| Felipe Vicens | f96bb45 | 2020-06-22 08:12:30 +0200 | [diff] [blame] | 18 | Run Keyword If '${password}'!='${EMPTY}' Login ${username} ${password} |
| 19 | ... ELSE Login With Public Key ${username} ${privatekey} |
| 20 | Execute Command hostname |
| 21 | Close All Connections |
| 22 | |
| 23 | Check If remote File Exists |
| 24 | [Arguments] ${host} ${username} ${password} ${privatekey} ${file} |
| 25 | |
| 26 | Open Connection ${host} |
| garciadeblas | f4ebaa8 | 2022-06-23 13:33:26 +0200 | [diff] [blame] | 27 | Run Keyword If '${password}'!='${EMPTY}' Login ${username} ${password} |
| 28 | ... ELSE Login With Public Key ${username} ${privatekey} |
| Felipe Vicens | f96bb45 | 2020-06-22 08:12:30 +0200 | [diff] [blame] | 29 | ${rc}= Execute Command ls ${file} >& /dev/null return_stdout=False return_rc=True |
| 30 | Close All Connections |
| 31 | Should Be Equal As Integers ${rc} 0 |
| 32 | |
| aticig | 6cd7480 | 2022-05-11 19:31:46 +0300 | [diff] [blame] | 33 | Check If Remote Folder Exists |
| 34 | [Arguments] ${host} ${username} ${password} ${privatekey} ${folder} |
| 35 | |
| 36 | Open Connection ${host} |
| garciadeblas | f4ebaa8 | 2022-06-23 13:33:26 +0200 | [diff] [blame] | 37 | Run Keyword If '${password}'!='${EMPTY}' Login ${username} ${password} |
| 38 | ... ELSE Login With Public Key ${username} ${privatekey} |
| aticig | 6cd7480 | 2022-05-11 19:31:46 +0300 | [diff] [blame] | 39 | ${output}= Execute Command ls -d ${folder} |
| 40 | Close All Connections |
| 41 | Should Be Equal As Strings ${output} ${folder} |
| 42 | |
| Felipe Vicens | f96bb45 | 2020-06-22 08:12:30 +0200 | [diff] [blame] | 43 | Get Remote File Content |
| garciadeblas | f4ebaa8 | 2022-06-23 13:33:26 +0200 | [diff] [blame] | 44 | [Arguments] ${host} ${username} ${password} ${privatekey} ${file} |
| Felipe Vicens | f96bb45 | 2020-06-22 08:12:30 +0200 | [diff] [blame] | 45 | |
| garciadeblas | f4ebaa8 | 2022-06-23 13:33:26 +0200 | [diff] [blame] | 46 | Open Connection ${host} |
| 47 | Run Keyword If '${password}'!='${EMPTY}' Login ${username} ${password} |
| 48 | ... ELSE Login With Public Key ${username} ${privatekey} |
| Felipe Vicens | f96bb45 | 2020-06-22 08:12:30 +0200 | [diff] [blame] | 49 | ${output}= Execute Command cat ${file} |
| 50 | Close All Connections |
| 51 | [Return] ${output} |
| 52 | |
| 53 | Ping Many |
| garciadeblas | f4ebaa8 | 2022-06-23 13:33:26 +0200 | [diff] [blame] | 54 | [Arguments] ${host} ${username} ${password} ${privatekey} @{ip_list} |
| Felipe Vicens | f96bb45 | 2020-06-22 08:12:30 +0200 | [diff] [blame] | 55 | |
| garciadeblas | f4ebaa8 | 2022-06-23 13:33:26 +0200 | [diff] [blame] | 56 | Open Connection ${host} |
| 57 | Run Keyword If '${password}'!='${EMPTY}' Login ${username} ${password} |
| 58 | ... ELSE Login With Public Key ${username} ${privatekey} |
| Felipe Vicens | f96bb45 | 2020-06-22 08:12:30 +0200 | [diff] [blame] | 59 | FOR ${ip} IN @{ip_list} |
| garciadeblas | f4ebaa8 | 2022-06-23 13:33:26 +0200 | [diff] [blame] | 60 | ${result}= Execute Command ping -c 5 -W 1 ${ip} > /dev/null && echo OK shell=True |
| 61 | Log ${result} |
| 62 | Should Contain ${result} OK |
| Felipe Vicens | f96bb45 | 2020-06-22 08:12:30 +0200 | [diff] [blame] | 63 | END |
| 64 | Close All Connections |
| 65 | |
| 66 | |
| 67 | Execute Remote Command Check Rc Return Output |
| 68 | [Arguments] ${host} ${username} ${password} ${privatekey} ${command} |
| 69 | |
| 70 | Open Connection ${host} |
| garciadeblas | f4ebaa8 | 2022-06-23 13:33:26 +0200 | [diff] [blame] | 71 | Run Keyword If '${password}'!='${EMPTY}' Login ${username} ${password} |
| 72 | ... ELSE Login With Public Key ${username} ${privatekey} |
| Felipe Vicens | f96bb45 | 2020-06-22 08:12:30 +0200 | [diff] [blame] | 73 | ${stdout} ${rc}= Execute Command ${command} return_rc=True return_stdout=True |
| garciadeblas | 321726f | 2022-12-21 11:43:06 +0100 | [diff] [blame] | 74 | Log ${rc} |
| 75 | Log ${stdout} |
| Felipe Vicens | f96bb45 | 2020-06-22 08:12:30 +0200 | [diff] [blame] | 76 | Close All Connections |
| 77 | Should Be Equal As Integers ${rc} 0 |
| 78 | [Return] ${stdout} |
| 79 | |