Merge "Cluster sanity test using openflow plugin"
[integration/test.git] / test / csit / libraries / Utils.txt
1 *** Settings ***
2 Library           SSHLibrary
3 Library           ./UtilLibrary.py
4
5 *** Variables ***
6 ${start}          sudo mn --controller=remote,ip=${CONTROLLER} --topo tree,1 --switch ovsk,protocols=OpenFlow13
7 ${linux_prompt}   >
8
9 *** Keywords ***
10 Start Suite
11     [Documentation]    Basic setup/cleanup work that can be done safely before any system
12     ...    is run.
13     Log    Start the test on the base edition
14     ${mininet_conn_id}=     Open Connection    ${MININET}    prompt=${linux_prompt}    timeout=30s
15     Set Suite Variable  ${mininet_conn_id}
16     Login With Public Key    ${MININET_USER}    ${USER_HOME}/.ssh/id_rsa    any
17     Write    sudo ovs-vsctl set-manager ptcp:6644
18     Read Until    ${linux_prompt}
19     Write    sudo mn -c
20     Read Until    ${linux_prompt}
21     Write    ${start}
22     Read Until    mininet>
23     Sleep    6
24
25 Stop Suite
26     [Documentation]    Cleanup/Shutdown work that should be done at the completion of all
27     ...    tests
28     Log    Stop the test on the base edition
29     Switch Connection   ${mininet_conn_id}
30     Read
31     Write    exit
32     Read Until    ${linux_prompt}
33     Close Connection
34
35 Ensure All Nodes Are In Response
36     [Arguments]    ${URI}    ${node_list}
37     [Documentation]    A GET is made to the supplied ${URI} and every item in the ${node_list}
38     ...    is verified to exist in the repsonse. This keyword currently implies that it's node
39     ...    specific but any list of strings can be given in ${node_list}. Refactoring of this
40     ...    to make it more generic should be done. (see keyword "Check For Elements At URI")
41     : FOR    ${node}    IN    @{node_list}
42     \    ${resp}    RequestsLibrary.Get    session    ${URI}
43     \    Should Be Equal As Strings    ${resp.status_code}    200
44     \    Should Contain    ${resp.content}    ${node}
45
46 Check Nodes Stats
47     [Arguments]    ${node}
48     [Documentation]    A GET on the /node/${node} API is made and specific flow stat
49     ...    strings are checked for existence.
50     ${resp}    RequestsLibrary.Get    session    ${REST_CONTEXT}/node/${node}
51     Should Be Equal As Strings    ${resp.status_code}    200
52     Should Contain    ${resp.content}    flow-capable-node-connector-statistics
53     Should Contain    ${resp.content}    flow-table-statistics
54
55 Check That Port Count Is Ok
56     [Arguments]    ${node}    ${count}
57     [Documentation]    A GET on the /port API is made and the specified port ${count} is
58     ...    verified. A more generic Keyword "Check For Specific Number Of Elements At URI"
59     ...    also does this work and further consolidation should be done.
60     ${resp}    RequestsLibrary.Get    session    ${REST_CONTEXT}/${CONTAINER}/port
61     Log    ${resp.content}
62     Should Be Equal As Strings    ${resp.status_code}    200
63     Should Contain X Times    ${resp.content}    ${node}    ${count}
64
65 Check For Specific Number Of Elements At URI
66     [Arguments]    ${uri}    ${element}    ${expected_count}
67     [Documentation]    A GET is made to the specified ${URI} and the specific count of a
68     ...    given element is done (as supplied by ${element} and ${expected_count})
69     ${resp}    RequestsLibrary.Get    session    ${uri}
70     Log    ${resp.content}
71     Should Be Equal As Strings    ${resp.status_code}    200
72     Should Contain X Times    ${resp.content}    ${element}    ${expected_count}
73
74 Check For Elements At URI
75     [Arguments]    ${uri}    ${elements}
76     [Documentation]    A GET is made at the supplied ${URI} and every item in the list of
77     ...    ${elements} is verified to exist in the response
78     ${resp}    RequestsLibrary.Get    session    ${uri}
79     Log    ${resp.content}
80     Should Be Equal As Strings    ${resp.status_code}    200
81     : FOR    ${i}    IN    @{elements}
82     \    Should Contain    ${resp.content}    ${i}
83
84 Check For Elements Not At URI
85     [Arguments]    ${uri}    ${elements}
86     [Documentation]    A GET is made at the supplied ${URI} and every item in the list of
87     ...    ${elements} is verified to NOT exist in the response
88     ${resp}    RequestsLibrary.Get    session    ${uri}
89     Log    ${resp.content}
90     Should Be Equal As Strings    ${resp.status_code}    200
91     : FOR    ${i}    IN    @{elements}
92     \    Should Not Contain    ${resp.content}    ${i}
93
94 Extract Value From Content
95     [Arguments]    ${content}    ${index}    ${strip}=nostrip
96     [Documentation]    Will take the given response content and return the value at the given index as a string
97     ${value}=    Get Json Value    ${content}    ${index}
98     ${value}=    Convert To String    ${value}
99     ${value}=    Run Keyword If    '${strip}' == 'strip'    Strip Quotes    ${value}
100     [Return]    ${value}
101
102 Strip Quotes
103     [Arguments]    ${string_to_strip}
104     [Documentation]    Will strip ALL quotes from given string and return the new string
105     ${string_to_return}=    Replace String    ${string_to_strip}    "    \    count=-1
106     [Return]    ${string_to_return}
107
108 Run Command On Remote System
109     [Arguments]     ${remote_system}    ${cmd}  ${user}=${MININET_USER}    ${prompt}=${LINUX_PROMPT}   ${prompt_timeout}=30s
110     [Documentation]     Reduces the common work of running a command on a remote system to a single higher level robot keyword,
111     ...     taking care to log in with a public key and.  The command given is written and the output returned.  No test conditions
112     ...     are checked.
113     Log    Attempting to execute ${cmd} on ${remote_system}
114     ${conn_id}=     Open Connection    ${remote_system}    prompt=${prompt}    timeout=${prompt_timeout}
115     Login With Public Key    ${user}    ${USER_HOME}/.ssh/id_rsa    any
116     Write    ${cmd}
117     ${output}=  Read Until    ${linux_prompt}
118     [Return]    ${output}
119
120 Verify File Exists On Remote System
121     [Arguments]  ${remote_system}    ${file}  ${user}=${MININET_USER}    ${prompt}=${LINUX_PROMPT}   ${prompt_timeout}=5s
122     [Documentation]     Will create connection with public key and will PASS if the given ${file} exists, otherwise will FAIL
123     ${conn_id}=     Open Connection    ${remote_system}    prompt=${prompt}    timeout=${prompt_timeout}
124     Login With Public Key    ${user}    ${USER_HOME}/.ssh/id_rsa    any
125     SSHLibrary.File Should Exist   ${file}