Add Nexus artifact deployment initialization keyword
[integration/test.git] / csit / libraries / SSHKeywords.robot
1 *** Settings ***
2 Documentation     Resource enhancing SSHLibrary with Keywords used in multiple suites.
3 ...
4 ...               Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
5 ...
6 ...               This program and the accompanying materials are made available under the
7 ...               terms of the Eclipse Public License v1.0 which accompanies this distribution,
8 ...               and is available at http://www.eclipse.org/legal/epl-v10.html
9 ...
10 ...
11 ...               Some suites evolved utility Keywords re-usable with other suites.
12 ...               When the Keywords assume a SSH session is active,
13 ...               and if the Keywords do not fit into a more specific Resource,
14 ...               you can place them here.
15 Library           SSHLibrary
16 Resource          ${CURDIR}/Utils.robot
17
18 *** Keywords ***
19 Open_Connection_To_Tools_System
20     [Documentation]    Open a connection to the tools system and return its identifier.
21     ${tools}=    SSHLibrary.Open_Connection    ${TOOLS_SYSTEM_IP}    prompt=${TOOLS_SYSTEM_PROMPT}
22     Utils.Flexible_Mininet_Login
23     [Return]    ${tools}
24
25 Execute_Command_Passes
26     [Arguments]    ${command}
27     [Documentation]    Execute command via SSH. If RC is nonzero, log everything. Retrun bool string of command success.
28     ${stdout}    ${stderr}    ${rc} =    SSHLibrary.Execute_Command    ${command}    return_stderr=True    return_rc=True
29     BuiltIn.Return_From_Keyword_If    ${rc} == 0    True
30     BuiltIn.Log    ${stdout}
31     BuiltIn.Log    ${stderr}
32     BuiltIn.Log    ${rc}
33     [Return]    False
34
35 Require_Python
36     [Documentation]    Verify current SSH connection leads to machine with python working. Fatal fail otherwise.
37     ${passed} =    Execute_Command_Passes    python --help
38     BuiltIn.Return_From_Keyword_If    ${passed}
39     BuiltIn.Fatal_Error    Python is not installed!
40
41 Assure_Library_Ipaddr
42     [Arguments]    ${target_dir}=.
43     [Documentation]    Tests whether ipaddr module is present on ssh-connected machine, Puts ipaddr.py to target_dir if not.
44     ${passed} =    Execute_Command_Passes    bash -c 'cd "${target_dir}" && python -c "import ipaddr"'
45     BuiltIn.Return_From_Keyword_If    ${passed}
46     SSHLibrary.Put_File    ${CURDIR}/ipaddr.py    ${target_dir}/
47
48 Assure_Library_Counter
49     [Arguments]    ${target_dir}=.
50     [Documentation]    Tests whether Counter is present in collections on ssh-connected machine, Puts Counter.py to workspace if not.
51     ${passed} =    Execute_Command_Passes    bash -c 'cd "${target_dir}" && python -c "from collections import Counter"'
52     # TODO: Move the bash-cd wrapper to separate keyword?
53     BuiltIn.Return_From_Keyword_If    ${passed}
54     SSHLibrary.Put_File    ${CURDIR}/Counter.py    ${target_dir}/
55
56 Count_Port_Occurences
57     [Arguments]    ${port}    ${state}    ${name}
58     [Documentation]    Run 'netstat' on the remote machine and count occurences of given port in the given state connected to process with the given name.
59     ${output}=    SSHLibrary.Execute_Command    netstat -natp 2> /dev/null | grep -E ":${port} .+ ${state} .+${name}" | wc -l
60     [Return]    ${output}