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