Add more time to fill table stats
[integration/test.git] / csit / suites / openflowplugin / EntityOwnership / 020_Cluster_Node_Failure.robot
1 *** Settings ***
2 Documentation     Test suite for entity ownership service and openflowplugin. Makes changes on controller side (restart karaf)
3 Suite Setup       Start Suite
4 Suite Teardown    End Suite
5 Test Setup        SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
6 Test Template     Restarting Karaf Scenario
7 Library           SSHLibrary
8 Library           RequestsLibrary
9 Library           XML
10 Resource          ${CURDIR}/../../../libraries/SetupUtils.robot
11 Resource          ${CURDIR}/../../../libraries/Utils.robot
12 Resource          ${CURDIR}/../../../libraries/FlowLib.robot
13 Resource          ${CURDIR}/../../../libraries/OvsManager.robot
14 Resource          ${CURDIR}/../../../libraries/ClusterManagement.robot
15 Resource          ${CURDIR}/../../../libraries/ClusterOpenFlow.robot
16 Library           Collections
17
18 *** Variables ***
19 ${SWITCHES}       1
20 ${START_CMD}      sudo mn --topo linear,${SWITCHES}
21 ${KARAF_HOME}     ${WORKSPACE}${/}${BUNDLEFOLDER}
22
23 *** Test Cases ***
24 Switches To Be Connected To All Nodes
25     [Documentation]    Initial check for correct connected topology.
26     [Template]    NONE
27     BuiltIn.Wait Until Keyword Succeeds    5x    3s    Check All Switches Connected To All Cluster Nodes
28
29 Restarting Owner Of Switch s1
30     s1
31
32 Switches Still Be Connected To All Nodes
33     [Template]    NONE
34     BuiltIn.Wait Until Keyword Succeeds    5x    3s    Check All Switches Connected To All Cluster Nodes
35
36 *** Keywords ***
37 Start Suite
38     SetupUtils.Setup_Utils_For_Setup_And_Teardown
39     ${mininet_conn_id}=    SSHLibrary.Open Connection    ${TOOLS_SYSTEM_IP}    prompt=${TOOLS_SYSTEM_PROMPT}
40     BuiltIn.Set Suite Variable    ${mininet_conn_id}
41     SSHLibrary.Login With Public Key    ${TOOLS_SYSTEM_USER}    ${USER_HOME}/.ssh/id_rsa    any
42     SSHLibrary.Put File    ${CURDIR}/../../../libraries/DynamicMininet.py    .
43     SSHLibrary.Execute Command    sudo ovs-vsctl set-manager ptcp:6644
44     SSHLibrary.Execute Command    sudo mn -c
45     SSHLibrary.Write    ${START_CMD}
46     SSHLibrary.Read Until    mininet>
47     ${cntls_list}    BuiltIn.Create List    ${ODL_SYSTEM_1_IP}    ${ODL_SYSTEM_2_IP}    ${ODL_SYSTEM_3_IP}
48     ${switch_list}    BuiltIn.Create List
49     : FOR    ${i}    IN RANGE    0    ${SWITCHES}
50     \    ${sid}=    BuiltIn.Evaluate    ${i}+1
51     \    Collections.Append To List    ${switch_list}    s${sid}
52     BuiltIn.Set Suite Variable    ${active_member}    1
53     OvsManager.Setup Clustered Controller For Switches    ${switch_list}    ${cntls_list}
54     BuiltIn.Wait Until Keyword Succeeds    10s    1s    ClusterOpenFlow.Verify Switch Connections Running On Member    ${SWITCHES}    1
55
56 End Suite
57     RequestsLibrary.Delete All Sessions
58     Utils.Stop Mininet
59
60 Check All Switches Connected To All Cluster Nodes
61     [Documentation]    Verifies all switches are connected to all cluster nodes
62     OvsManager.Get Ovsdb Data
63     : FOR    ${i}    IN RANGE    0    ${SWITCHES}
64     \    ${sid}=    BuiltIn.Evaluate    ${i}+1
65     \    OvsManager.Should Be Connected    s${sid}    ${ODL_SYSTEM_1_IP}    update_data=${False}
66     \    OvsManager.Should Be Connected    s${sid}    ${ODL_SYSTEM_2_IP}    update_data=${False}
67     \    OvsManager.Should Be Connected    s${sid}    ${ODL_SYSTEM_3_IP}    update_data=${False}
68
69 Restarting Karaf Scenario
70     [Arguments]    ${switch_name}
71     [Documentation]    Disconnect and connect owner and successor and check switch data to be consistent
72     ${idx}=    BuiltIn.Evaluate    str("${switch_name}"[1:])
73     BuiltIn.Set Test Variable    ${idx}
74     Kill Switchs Old Owner    ${switch_name}
75     Restart Switchs Old Owner    ${switch_name}
76     Kill Switchs Successor    ${switch_name}
77     Restart Switchs Successor    ${switch_name}
78     [Teardown]    Run Keyword If    "${stopped_karaf}"!="${Empty}"    Start Controller Node And Verify    ${stopped_karaf}
79
80 Kill Switchs Old Owner
81     [Arguments]    ${switch_name}
82     BuiltIn.Set Test Variable    ${stopped_karaf}    ${Empty}
83     ${old_owner}    ${old_successors}=    ClusterOpenFlow.Get OpenFlow Entity Owner Status For One Device    openflow:${idx}    ${active_member}
84     ${old_master}=    BuiltIn.Set Variable    ${ODL_SYSTEM_${old_owner}_IP}
85     ${active_member}=    Collections.Get From List    ${old_successors}    0
86     BuiltIn.Set Suite Variable    ${active_member}
87     Stop Controller Node And Verify    ${old_owner}
88     BuiltIn.Set Test Variable    ${stopped_karaf}    ${old_owner}
89     ClusterOpenFlow.Check OpenFlow Shards Status After Cluster Event    ${old_successors}
90     ${new_master}=    BuiltIn.Wait Until Keyword Succeeds    5x    3s    Verify New Master Controller Node    ${switch_name}    ${old_master}
91     ${owner}    ${successors}=    ClusterOpenFlow.Get OpenFlow Entity Owner Status For One Device    openflow:${idx}    ${active_member}    ${old_successors}    after_stop=True
92     BuiltIn.Should Be Equal As Strings    ${new_master}    ${ODL_SYSTEM_${owner}_IP}
93     BuiltIn.Set Suite Variable    ${active_member}    ${owner}
94     BuiltIn.Set Test Variable    ${old_owner}
95     BuiltIn.Set Test Variable    ${old_successors}
96     BuiltIn.Set Test Variable    ${old_master}
97     BuiltIn.Set Test Variable    ${owner}
98     BuiltIn.Set Test Variable    ${new_master}
99
100 Restart Switchs Old Owner
101     [Arguments]    ${switch_name}
102     Start Controller Node And Verify    ${old_owner}
103     BuiltIn.Set Test Variable    ${stopped_karaf}    ${Empty}
104     ClusterOpenFlow.Check OpenFlow Shards Status After Cluster Event
105     ${new_owner}    ${new_successors}=    ClusterOpenFlow.Get OpenFlow Entity Owner Status For One Device    openflow:${idx}    ${active_member}
106     BuiltIn.Should Be Equal    ${owner}    ${new_owner}
107
108 Kill Switchs Successor
109     [Arguments]    ${switch_name}
110     ${old_owner}    ${old_successors}=    ClusterOpenFlow.Get OpenFlow Entity Owner Status For One Device    openflow:${idx}    ${active_member}
111     ${old_successor}=    Collections.Get From List    ${old_successors}    0
112     ${old_slave}=    BuiltIn.Set Variable    ${ODL_SYSTEM_${old_successor}_IP}
113     Stop Controller Node And Verify    ${old_successor}
114     BuiltIn.Set Test Variable    ${stopped_karaf}    ${old_successor}
115     ${tmp_candidates}=    BuiltIn.Create List    @{ClusterManagement__member_index_list}
116     Collections.Remove Values From List    ${tmp_candidates}    ${old_successor}
117     ClusterOpenFlow.Check OpenFlow Shards Status After Cluster Event    ${tmp_candidates}
118     ${owner}    ${successor}=    ClusterOpenFlow.Get OpenFlow Entity Owner Status For One Device    openflow:${idx}    ${active_member}    ${tmp_candidates}    after_stop=True
119     BuiltIn.Should Be Equal    ${owner}    ${old_owner}
120     BuiltIn.Should Be Equal As Strings    ${new_master}    ${ODL_SYSTEM_${owner}_IP}
121     BuiltIn.Set Test Variable    ${old_owner}
122     BuiltIn.Set Test Variable    ${old_successors}
123     BuiltIn.Set Test Variable    ${old_successor}
124     BuiltIn.Set Test Variable    ${old_slave}
125     BuiltIn.Set Test Variable    ${owner}
126
127 Restart Switchs Successor
128     [Arguments]    ${switch_name}
129     Start Controller Node And Verify    ${old_successor}
130     BuiltIn.Set Test Variable    ${stopped_karaf}    ${Empty}
131     ClusterOpenFlow.Check OpenFlow Shards Status After Cluster Event
132     ${new_owner}    ${new_successors}=    ClusterOpenFlow.Get OpenFlow Entity Owner Status For One Device    openflow:${idx}    ${active_member}
133     BuiltIn.Should Be Equal    ${old_owner}    ${new_owner}
134
135 Verify New Master Controller Node
136     [Arguments]    ${switch_name}    ${old_master}
137     [Documentation]    Checks if given node is different from actual master
138     ${idx}=    BuiltIn.Evaluate    "${switch_name}"[1:]
139     ${owner}    ${successors}=    ClusterManagement.Get Owner And Candidates For Device    openflow:${idx}    openflow    ${active_member}
140     ${new_master}    BuiltIn.Set Variable    ${ODL_SYSTEM_${owner}_IP}
141     BuiltIn.Should Not Be Equal    ${old_master}    ${new_master}
142     Return From Keyword    ${new_master}
143
144 Stop Controller Node And Verify
145     [Arguments]    ${node}
146     [Documentation]    Stops the given node
147     ClusterManagement.Stop Single Member    ${node}
148     [Teardown]    SSHLibrary.Switch Connection    ${mininet_conn_id}
149
150 Start Controller Node And Verify
151     [Arguments]    ${node}
152     [Documentation]    Starts the given node
153     ClusterManagement.Start Single Member    ${node}
154     [Teardown]    SSHLibrary.Switch Connection    ${mininet_conn_id}