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