Initial tests contributions
[osm/tests.git] / robot-systest / lib / ssh_lib.robot
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
17     Open Connection     ${host}
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}
27     Run Keyword If   '${password}'!='${EMPTY}'  Login  ${username}  ${password}
28     ...   ELSE   Login With Public Key  ${username}  ${privatekey}
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
33 Get Remote File Content
34     [Arguments]  ${host}  ${username}  ${password}  ${privatekey}   ${file}
35
36     Open Connection     ${host}
37     Run Keyword If   '${password}'!='${EMPTY}'  Login  ${username}  ${password}
38     ...   ELSE   Login With Public Key  ${username}  ${privatekey}
39     ${output}=   Execute Command   cat ${file}
40     Close All Connections
41     [Return]   ${output}
42
43 Ping Many
44     [Arguments]  ${host}  ${username}  ${password}  ${privatekey}   @{ip_list}
45
46     Open Connection     ${host}
47     Run Keyword If   '${password}'!='${EMPTY}'  Login  ${username}  ${password}
48     ...   ELSE   Login With Public Key  ${username}  ${privatekey}
49     FOR   ${ip}   IN   @{ip_list}
50         ${result}=   Execute Command   ping -c 5 -W 1 ${ip} > /dev/null && echo OK  shell=True
51         Log     ${result}
52         Should Contain  ${result}  OK
53     END
54     Close All Connections
55
56
57 Execute Remote Command Check Rc Return Output
58     [Arguments]   ${host}   ${username}   ${password}   ${privatekey}   ${command}
59
60     Open Connection   ${host}
61     Run Keyword If   '${password}'!='${EMPTY}'  Login  ${username}  ${password}
62     ...   ELSE   Login With Public Key  ${username}  ${privatekey}
63     ${stdout}   ${rc}=   Execute Command   ${command}   return_rc=True   return_stdout=True
64     log   ${rc}
65     log   ${stdout}
66     Close All Connections
67     Should Be Equal As Integers   ${rc}   0
68     [Return]   ${stdout}
69