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