Remove Start/Stop Suite from Utils.robot
[integration/test.git] / csit / suites / openflowplugin / EntityOwnership / 030_Cluster_Sync_Problems.robot
1 *** Settings ***
2 Documentation     Test suite for entity ownership service and openflowplugin. Makes changes on controller side (isolating cluster node)
3 Suite Setup       Start Suite
4 Suite Teardown    End Suite
5 Test Template     Isolating Node 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 @{CONTROLLER_NODES}    ${ODL_SYSTEM_1_IP}    ${ODL_SYSTEM_2_IP}    ${ODL_SYSTEM_3_IP}
20 @{cntls_idx_list}    ${1}    ${2}    ${3}
21
22 *** Test Cases ***
23 Start Mininet To All Nodes
24     [Template]    NONE
25     ${mininet_conn_id}=    SSHLibrary.Open Connection    ${TOOLS_SYSTEM_IP}    prompt=${TOOLS_SYSTEM_PROMPT}
26     BuiltIn.Set Suite Variable    ${mininet_conn_id}
27     SSHLibrary.Login With Public Key    ${TOOLS_SYSTEM_USER}    ${USER_HOME}/.ssh/id_rsa    any
28     SSHLibrary.Put File    ${CURDIR}/../../../libraries/DynamicMininet.py    .
29     SSHLibrary.Execute Command    sudo ovs-vsctl set-manager ptcp:6644
30     SSHLibrary.Execute Command    sudo mn -c
31     SSHLibrary.Write    ${START_CMD}
32     SSHLibrary.Read Until    mininet>
33     ${cntls_list}    BuiltIn.Create List    ${ODL_SYSTEM_1_IP}    ${ODL_SYSTEM_2_IP}    ${ODL_SYSTEM_3_IP}
34     ${switch_list}    BuiltIn.Create List
35     : FOR    ${i}    IN RANGE    0    ${SWITCHES}
36     \    ${sid}=    BuiltIn.Evaluate    ${i}+1
37     \    Collections.Append To List    ${switch_list}    s${sid}
38     BuiltIn.Set Suite Variable    ${active_member}    1
39     OvsManager.Setup Clustered Controller For Switches    ${switch_list}    ${cntls_list}
40     BuiltIn.Wait Until Keyword Succeeds    15s    1s    Are Switches Connected Topo
41
42 Switches To Be Connected To All Nodes
43     [Documentation]    Initial check for correct connected topology.
44     [Template]    NONE
45     BuiltIn.Wait Until Keyword Succeeds    15x    1s    Check All Switches Connected To All Cluster Nodes
46
47 Isolating Owner Of Switch s1
48     s1
49     [Teardown]    Report_Failure_Due_To_Bug    6177
50
51 Switches Still Be Connected To All Nodes
52     [Template]    NONE
53     BuiltIn.Wait Until Keyword Succeeds    15x    1s    Check All Switches Connected To All Cluster Nodes
54     [Teardown]    Report_Failure_Due_To_Bug    6177
55
56 Stop Mininet And Verify No Owners
57     [Template]    NONE
58     Utils.Stop Mininet
59     BuiltIn.Wait Until Keyword Succeeds    15x    1s    Check No Owners In Controller
60     [Teardown]    Report_Failure_Due_To_Bug    6177
61
62 *** Keywords ***
63 Start Suite
64     ClusterManagement.ClusterManagement Setup
65
66 End Suite
67     ClusterManagement.Flush Iptables From List Or All
68     RequestsLibrary.Delete All Sessions
69
70 Are Switches Connected Topo
71     [Documentation]    Checks wheather switches are connected to controller
72     ${resp}=    ClusterManagement.Get From Member    ${OPERATIONAL_TOPO_API}/topology/flow:1    ${active_member}    access=${ACCEPT_XML}
73     BuiltIn.Log    ${resp}
74     ${count}=    XML.Get Element Count    ${resp}    xpath=node
75     BuiltIn.Should Be Equal As Numbers    ${count}    ${SWITCHES}
76
77 Check All Switches Connected To All Cluster Nodes
78     [Documentation]    Verifies all switches are connected to all cluster nodes
79     OvsManager.Get Ovsdb Data
80     : FOR    ${i}    IN RANGE    0    ${SWITCHES}
81     \    ${sid}=    BuiltIn.Evaluate    ${i}+1
82     \    OvsManager.Should Be Connected    s${sid}    ${ODL_SYSTEM_1_IP}    update_data=${False}
83     \    OvsManager.Should Be Connected    s${sid}    ${ODL_SYSTEM_2_IP}    update_data=${False}
84     \    OvsManager.Should Be Connected    s${sid}    ${ODL_SYSTEM_3_IP}    update_data=${False}
85
86 Isolating Node Scenario
87     [Arguments]    ${switch_name}
88     [Documentation]    Disconnect and connect owner and successor and check switch data to be consistent
89     ${idx}=    BuiltIn.Evaluate    str("${switch_name}"[1:])
90     BuiltIn.Set Test Variable    ${idx}
91     Isolate Switchs Old Owner    ${switch_name}
92     Rejoin Switchs Old Owner    ${switch_name}
93     Isolate Switchs Successor    ${switch_name}
94     Rejoin Switchs Successor    ${switch_name}
95     [Teardown]    Run Keyword If    "${isol_node}"!="${Empty}"    Rejoin Controller To The Cluster    ${isol_node}
96
97 Isolate Switchs Old Owner
98     [Arguments]    ${switch_name}
99     BuiltIn.Set Test Variable    ${isol_node}    ${Empty}
100     ${old_owner}    ${old_successors}=    ClusterOpenFlow.Get OpenFlow Entity Owner Status For One Device    openflow:${idx}    ${active_member}
101     ${old_master}=    BuiltIn.Set Variable    ${ODL_SYSTEM_${old_owner}_IP}
102     ${active_member}=    Collections.Get From List    ${old_successors}    0
103     BuiltIn.Set Suite Variable    ${active_member}
104     Isolate Controller From The Cluster    ${old_owner}
105     BuiltIn.Set Test Variable    ${isol_node}    ${old_owner}
106     ClusterOpenFlow.Check OpenFlow Shards Status After Cluster Event    ${old_successors}
107     ${new_master}=    BuiltIn.Wait Until Keyword Succeeds    10x    3s    Verify New Master Controller Node    ${switch_name}    ${old_master}
108     ${owner}    ${successors}=    ClusterOpenFlow.Get OpenFlow Entity Owner Status For One Device    openflow:${idx}    ${active_member}    ${old_successors}
109     BuiltIn.Should Be Equal As Strings    ${new_master}    ${ODL_SYSTEM_${owner}_IP}
110     BuiltIn.Set Suite Variable    ${active_member}    ${owner}
111     BuiltIn.Set Test Variable    ${old_owner}
112     BuiltIn.Set Test Variable    ${old_successors}
113     BuiltIn.Set Test Variable    ${old_master}
114     BuiltIn.Set Test Variable    ${owner}
115     BuiltIn.Set Test Variable    ${new_master}
116
117 Rejoin Switchs Old Owner
118     [Arguments]    ${switch_name}
119     Rejoin Controller To The Cluster    ${old_owner}
120     BuiltIn.Set Test Variable    ${isol_node}    ${Empty}
121     ClusterOpenFlow.Check OpenFlow Shards Status After Cluster Event
122     ${new_owner}    ${new_successors}=    BuiltIn.Wait Until Keyword Succeeds    6x    10s    ClusterOpenFlow.Get OpenFlow Entity Owner Status For One Device    openflow:${idx}
123     ...    ${active_member}
124     BuiltIn.Should Be Equal    ${owner}    ${new_owner}
125
126 Isolate Switchs Successor
127     [Arguments]    ${switch_name}
128     ${old_owner}    ${old_successors}=    ClusterOpenFlow.Get OpenFlow Entity Owner Status For One Device    openflow:${idx}    ${active_member}
129     ${old_successor}=    Collections.Get From List    ${old_successors}    0
130     ${old_slave}=    BuiltIn.Set Variable    ${ODL_SYSTEM_${old_successor}_IP}
131     Isolate Controller From The Cluster    ${old_successor}
132     BuiltIn.Set Test Variable    ${isol_cntl}    ${old_slave}
133     ${tmp_candidates}=    BuiltIn.Create List    @{ClusterManagement__member_index_list}
134     Collections.Remove Values From List    ${tmp_candidates}    ${old_successor}
135     ClusterOpenFlow.Check OpenFlow Shards Status After Cluster Event    ${tmp_candidates}
136     ${owner}    ${successors}=    ClusterOpenFlow.Get OpenFlow Entity Owner Status For One Device    openflow:${idx}    ${active_member}    ${tmp_candidates}
137     BuiltIn.Should Be Equal    ${owner}    ${old_owner}
138     BuiltIn.Should Be Equal As Strings    ${new_master}    ${ODL_SYSTEM_${owner}_IP}
139     BuiltIn.Set Test Variable    ${old_owner}
140     BuiltIn.Set Test Variable    ${old_successors}
141     BuiltIn.Set Test Variable    ${old_successor}
142     BuiltIn.Set Test Variable    ${old_slave}
143     BuiltIn.Set Test Variable    ${owner}
144
145 Rejoin Switchs Successor
146     [Arguments]    ${switch_name}
147     Rejoin Controller To The Cluster    ${old_successor}
148     BuiltIn.Set Test Variable    ${isol_node}    ${Empty}
149     ClusterOpenFlow.Check OpenFlow Shards Status After Cluster Event
150     ${new_owner}    ${new_successors}=    BuiltIn.Wait Until Keyword Succeeds    6x    10s    ClusterOpenFlow.Get OpenFlow Entity Owner Status For One Device    openflow:${idx}
151     ...    ${active_member}
152     BuiltIn.Should Be Equal    ${old_owner}    ${new_owner}
153
154 Rejoin Controller To The Cluster
155     [Arguments]    ${isolated_node}
156     ClusterManagement.Rejoin Member From List Or All    ${isolated_node}
157     [Teardown]    SSHLibrary.Switch Connection    ${mininet_conn_id}
158
159 Isolate Controller From The Cluster
160     [Arguments]    ${isolated_node}
161     ClusterManagement.Isolate Member From List Or All    ${isolated_node}
162     [Teardown]    SSHLibrary.Switch Connection    ${mininet_conn_id}
163
164 Check No Owners In Controller
165     [Documentation]    Check there is no owners in controllers
166     ${session} =    Resolve_Http_Session_For_Member    member_index=${active_member}
167     ${data} =    TemplatedRequests.Get_As_Json_From_Uri    uri=${ENTITY_OWNER_URI}    session=${session}
168     BuiltIn.Should Not Contain    ${data}    member
169
170 Verify New Master Controller Node
171     [Arguments]    ${switch_name}    ${old_master}
172     [Documentation]    Checks if given node is different from actual master
173     ${idx}=    BuiltIn.Evaluate    "${switch_name}"[1:]
174     ${owner}    ${successors}=    ClusterManagement.Get Owner And Candidates For Device    openflow:${idx}    openflow    ${active_member}
175     ${new_master}    BuiltIn.Set Variable    ${ODL_SYSTEM_${owner}_IP}
176     BuiltIn.Should Not Be Equal    ${old_master}    ${new_master}
177     Return From Keyword    ${new_master}