Convert arguments of CompareStream into String
[integration/test.git] / csit / libraries / WorkflowsL2switch.robot
1 *** Settings ***
2 Documentation     Resource for L2switch workflows. TODO: Refactor KWs once this test works in public.
3 Library           SSHLibrary
4 Library           RequestsLibrary
5 Library           String
6 Library           Collections
7 Library           SwitchClasses/BaseSwitch.py
8 Resource          Utils.robot
9 Resource          FlowLib.robot
10 Variables         ../variables/Variables.py
11
12 *** Keywords ***
13 Find Max Hosts
14     [Arguments]    ${begin}    ${stop}    ${step}    ${sustain_time}=0
15     [Documentation]    Will find out max hosts starting from ${begin} till reaching ${stop} and in steps defined by ${step}.
16     ...    The network is hold for ${sustain_time} seconds after everything is checked successful.
17     ${max-hosts}    Set Variable    ${0}
18     ${stop}    Convert to Integer    ${stop}
19     ${step}    Convert to Integer    ${step}
20     : FOR    ${hosts}    IN RANGE    ${begin}    ${stop+1}    ${step}
21     \    Log To Console    Starting mininet with one switch and ${hosts} hosts
22     \    ${status}    ${result}    Run Keyword And Ignore Error    Start Mininet With One Switch And ${hosts} hosts
23     \    Exit For Loop If    '${status}' == 'FAIL'
24     \    Log To Console    Checking ${switches} switches
25     \    ${status}    ${result}    Run Keyword And Ignore Error    Wait Until Keyword Succeeds    120s    30s
26     \    ...    FlowLib.Check Switches In Inventory    ${1}
27     \    Exit For Loop If    '${status}' == 'FAIL'
28     \    Log To Console    Ping all hosts
29     \    @{host_list}=    Get Mininet Hosts
30     \    ${status}=    Ping All Hosts    @{host_list}
31     \    Exit For Loop If    ${status} != ${0}
32     \    Log To Console    Verify controller is OK
33     \    ${status}    ${result}    Run Keyword And Ignore Error    Verify Controller Is Not Dead    ${ODL_SYSTEM_IP}
34     \    Exit For Loop If    '${status}' == 'FAIL'
35     \    ${status}    ${result}    Run Keyword And Ignore Error    Verify Controller Has No Null Pointer Exceptions    ${ODL_SYSTEM_IP}
36     \    Exit For Loop If    '${status}' == 'FAIL'
37     \    Log To Console    Check number of hosts in inventory is ${hosts}
38     \    ${status}    ${result}    Run Keyword And Ignore Error    Wait Until Keyword Succeeds    120s    30s
39     \    ...    Check Number Of Hosts    ${hosts}
40     \    Exit For Loop If    '${status}' == 'FAIL'
41     \    Log To Console    Sleep for ${sustain_time} seconds
42     \    Sleep    ${sustain_time}
43     \    Log To Console    Stopping Mininet
44     \    ${status}    ${result}    Run Keyword And Ignore Error    Stop Mininet Simulation
45     \    Exit For Loop If    '${status}' == 'FAIL'
46     \    Log To Console    Checking No Switches
47     \    ${status}    ${result}    Run Keyword And Ignore Error    FlowLib.Check No Switches In Inventory
48     \    Exit For Loop If    '${status}' == 'FAIL'
49     \    Log To Console    Checking no hosts are present in operational database
50     \    ${status}    ${result}    Run Keyword And Ignore Error    Check No Hosts
51     \    Exit For Loop If    '${status}' == 'FAIL'
52     \    ${max-hosts}    Convert To String    ${hosts}
53     [Return]    ${max-hosts}
54
55 Get Mininet Hosts
56     [Documentation]    Get all the hosts from mininet
57     ${host_list}=    Create List
58     Write    nodes
59     ${out}=    Read Until    mininet>
60     @{words}=    Split String    ${out}    ${SPACE}
61     : FOR    ${item}    IN    @{words}
62     \    ${h}=    Get Lines Matching Regexp    ${item.rstrip()}    .*h[0-9]*s.
63     \    Run Keyword If    '${h}' != '${EMPTY}'    Append To List    ${host_list}    ${h}
64     [Return]    ${host_list}
65
66 Ping All Hosts
67     [Arguments]    @{host_list}
68     [Documentation]    Do one round of ping from one host to all other hosts in mininet
69     ${source}=    Get From List    ${host_list}    ${0}
70     : FOR    ${h}    IN    @{host_list}
71     \    ${status}=    Ping Two Hosts    ${source}    ${h}    1
72     \    Exit For Loop If    ${status}!=${0}
73     [Return]    ${status}
74
75 Start Mininet With One Switch And ${hosts} hosts
76     [Documentation]    Start mininet with one switch and ${hosts} hosts
77     Log    Starting mininet with one switch and ${hosts} hosts
78     ${mininet_conn_id}=    Open Connection    ${TOOLS_SYSTEM_IP}    prompt=${DEFAULT_LINUX_PROMPT}    timeout=${hosts*3}
79     Set Suite Variable    ${mininet_conn_id}
80     Login With Public Key    ${TOOLS_SYSTEM_USER}    ${USER_HOME}/.ssh/${SSH_KEY}    any
81     Write    sudo mn --controller=remote,ip=${ODL_SYSTEM_IP} --topo linear,1,${hosts} --switch ovsk,protocols=OpenFlow13
82     Read Until    mininet>
83
84 Check Number Of Hosts
85     [Arguments]    ${hosts}
86     [Documentation]    Check number of hosts in inventory
87     ${resp}=    RequestsLibrary.Get Request    session    ${OPERATIONAL_TOPO_API}
88     Log    Check number of hosts in inventory is ${hosts}
89     Should Be Equal As Strings    ${resp.status_code}    200
90     ${count}=    Get Count    ${resp.content}    "node-id":"host:
91     Should Be Equal As Integers    ${count}    ${hosts}
92
93 Ping Two Hosts
94     [Arguments]    ${host1}    ${host2}    ${pingcount}=2    ${connection_index}=${EMPTY}    ${connection_alias}=${EMPTY}
95     [Documentation]    Ping between mininet hosts. Must be used only after a mininet session is in place.Returns non zero value if there is 100% packet loss.
96     Run Keyword If    '${connection_index}'    !=    '${EMPTY}'    Switch Connection    ${connection_index}
97     Run Keyword If    '${connection_alias}'    !=    '${EMPTY}'    Switch Connection    ${connection_alias}
98     Write    ${host1} ping -c ${pingcount} ${host2}
99     ${out}=    Read Until    mininet>
100     ${ret}=    Get Lines Matching Regexp    ${out}    .*100% packet loss.*
101     ${len}=    Get Length    ${ret}
102     [Return]    ${len}
103
104 Check No Hosts
105     [Documentation]    Check if all hosts are deleted from inventory
106     ${resp}=    RequestsLibrary.Get Request    session    ${OPERATIONAL_TOPO_API}
107     Log    Checking no hosts are present in operational database
108     Should Be Equal As Strings    ${resp.status_code}    200
109     Should Not Contain    ${resp.content}    "node-id":"host:
110
111 Stop Mininet Simulation
112     [Documentation]    Stop mininet
113     Switch Connection    ${mininet_conn_id}
114     Read
115     Write    exit
116     Read Until    ${DEFAULT_LINUX_PROMPT}
117     Close Connection
118
119 Scalability Suite Teardown
120     Run Keyword And Ignore Error    RequestsLibrary.Delete Request    session    ${CONFIG_NODES_API}
121     Delete All Sessions
122     Clean Mininet System