3610be8a0f859851d7a57584efacd80d04654155
[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
8 *** Keywords ***
9 Start Suite
10     [Documentation]    Basic setup/cleanup work that can be done safely before any system
11     ...    is run.
12     Log    Start the test on the base edition
13     ${mininet_conn_id}=     Open Connection    ${MININET}    prompt=>    timeout=30s
14     Set Suite Variable  ${mininet_conn_id}
15     Login With Public Key    ${MININET_USER}    ${USER_HOME}/.ssh/id_rsa    any
16     Write    sudo ovs-vsctl set-manager ptcp:6644
17     Read Until    >
18     Write    sudo mn -c
19     Read Until    >
20     Write    ${start}
21     Read Until    mininet>
22     Sleep    6
23
24 Stop Suite
25     [Documentation]    Cleanup/Shutdown work that should be done at the completion of all
26     ...    tests
27     Log    Stop the test on the base edition
28     Switch Connection   ${mininet_conn_id}
29     Read
30     Write    exit
31     Read Until    >
32     Close Connection
33
34 Ensure All Nodes Are In Response
35     [Arguments]    ${URI}    ${node_list}
36     [Documentation]    A GET is made to the supplied ${URI} and every item in the ${node_list}
37     ...    is verified to exist in the repsonse. This keyword currently implies that it's node
38     ...    specific but any list of strings can be given in ${node_list}. Refactoring of this
39     ...    to make it more generic should be done. (see keyword "Check For Elements At URI")
40     : FOR    ${node}    IN    @{node_list}
41     \    ${resp}    RequestsLibrary.Get    session    ${URI}
42     \    Should Be Equal As Strings    ${resp.status_code}    200
43     \    Should Contain    ${resp.content}    ${node}
44
45 Check Nodes Stats
46     [Arguments]    ${node}
47     [Documentation]    A GET on the /node/${node} API is made and specific flow stat
48     ...    strings are checked for existence.
49     ${resp}    RequestsLibrary.Get    session    ${REST_CONTEXT}/node/${node}
50     Should Be Equal As Strings    ${resp.status_code}    200
51     Should Contain    ${resp.content}    flow-capable-node-connector-statistics
52     Should Contain    ${resp.content}    flow-table-statistics
53
54 Check That Port Count Is Ok
55     [Arguments]    ${node}    ${count}
56     [Documentation]    A GET on the /port API is made and the specified port ${count} is
57     ...    verified. A more generic Keyword "Check For Specific Number Of Elements At URI"
58     ...    also does this work and further consolidation should be done.
59     ${resp}    RequestsLibrary.Get    session    ${REST_CONTEXT}/${CONTAINER}/port
60     Log    ${resp.content}
61     Should Be Equal As Strings    ${resp.status_code}    200
62     Should Contain X Times    ${resp.content}    ${node}    ${count}
63
64 Check For Specific Number Of Elements At URI
65     [Arguments]    ${uri}    ${element}    ${expected_count}
66     [Documentation]    A GET is made to the specified ${URI} and the specific count of a
67     ...    given element is done (as supplied by ${element} and ${expected_count})
68     ${resp}    RequestsLibrary.Get    session    ${uri}
69     Log    ${resp.content}
70     Should Be Equal As Strings    ${resp.status_code}    200
71     Should Contain X Times    ${resp.content}    ${element}    ${expected_count}
72
73 Check For Elements At URI
74     [Arguments]    ${uri}    ${elements}
75     [Documentation]    A GET is made at the supplied ${URI} and every item in the list of
76     ...    ${elements} is verified to exist in the response
77     ${resp}    RequestsLibrary.Get    session    ${uri}
78     Log    ${resp.content}
79     Should Be Equal As Strings    ${resp.status_code}    200
80     : FOR    ${i}    IN    @{elements}
81     \    Should Contain    ${resp.content}    ${i}
82
83 Check For Elements Not At URI
84     [Arguments]    ${uri}    ${elements}
85     [Documentation]    A GET is made at the supplied ${URI} and every item in the list of
86     ...    ${elements} is verified to NOT exist in the response
87     ${resp}    RequestsLibrary.Get    session    ${uri}
88     Log    ${resp.content}
89     Should Be Equal As Strings    ${resp.status_code}    200
90     : FOR    ${i}    IN    @{elements}
91     \    Should Not Contain    ${resp.content}    ${i}
92
93 Extract Value From Content
94     [Arguments]    ${content}    ${index}    ${strip}=nostrip
95     [Documentation]    Will take the given response content and return the value at the given index as a string
96     ${value}=    Get Json Value    ${content}    ${index}
97     ${value}=    Convert To String    ${value}
98     ${value}=    Run Keyword If    '${strip}' == 'strip'    Strip Quotes    ${value}
99     [Return]    ${value}
100
101 Strip Quotes
102     [Arguments]    ${string_to_strip}
103     [Documentation]    Will strip ALL quotes from given string and return the new string
104     ${string_to_return}=    Replace String    ${string_to_strip}    "    \    count=-1
105     [Return]    ${string_to_return}