2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at
6 # http://www.apache.org/licenses/LICENSE-2.0
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
16 Documentation Library providing keywords to interact with NF via SSH.
22 [Documentation] Test the SSH connection to the host with the user and credentials passed as arguments.
23 [Arguments] ${host} ${username} ${password} ${privatekey}
24 Open Connection ${host}
25 IF "${password}" != "${EMPTY}"
26 Login ${username} ${password}
28 Login With Public Key ${username} ${privatekey}
30 Execute Command hostname
33 Check If Remote File Exists
34 [Documentation] Check via SSH if a file exists in in the remote host, using the user and credentials passed as arguments.
35 [Arguments] ${host} ${username} ${password} ${privatekey} ${file}
36 Open Connection ${host}
37 IF "${password}" != "${EMPTY}"
38 Login ${username} ${password}
40 Login With Public Key ${username} ${privatekey}
42 ${rc}= Execute Command ls ${file} >& /dev/null return_stdout=False return_rc=True
44 Should Be Equal As Integers ${rc} 0
46 Check If Remote Folder Exists
47 [Documentation] Check via SSH if a folder exists in in the remote host, using the user and credentials passed as arguments.
48 [Arguments] ${host} ${username} ${password} ${privatekey} ${folder}
49 Open Connection ${host}
50 IF "${password}" != "${EMPTY}"
51 Login ${username} ${password}
53 Login With Public Key ${username} ${privatekey}
55 ${output}= Execute Command ls -d ${folder}
57 Should Be Equal As Strings ${output} ${folder}
59 Get Remote File Content
60 [Documentation] Get via SSH the content of a remote file and return it.
61 [Arguments] ${host} ${username} ${password} ${privatekey} ${file}
62 Open Connection ${host}
63 IF "${password}" != "${EMPTY}"
64 Login ${username} ${password}
66 Login With Public Key ${username} ${privatekey}
68 ${output}= Execute Command cat ${file}
73 [Documentation] Connect via SSH to a remote host and test ping to a list of IP addresses, passed as argument.
74 [Arguments] ${host} ${username} ${password} ${privatekey} @{ip_list}
75 Open Connection ${host}
76 IF "${password}" != "${EMPTY}"
77 Login ${username} ${password}
79 Login With Public Key ${username} ${privatekey}
81 FOR ${ip} IN @{ip_list}
82 ${result}= Execute Command ping -c 5 -W 1 ${ip} > /dev/null && echo OK shell=True
84 Should Contain ${result} OK
88 Execute Remote Command Check Rc Return Output
89 [Documentation] Execute via SSH a command in a remote host and, if the command succeeds, return the output.
90 [Arguments] ${host} ${username} ${password} ${privatekey} ${command}
91 Open Connection ${host}
92 IF "${password}" != "${EMPTY}"
93 Login ${username} ${password}
95 Login With Public Key ${username} ${privatekey}
97 ${stdout} ${rc}= Execute Command ${command} return_rc=True return_stdout=True
100 Close All Connections
101 Should Be Equal As Integers ${rc} 0