Migrate Get Requests invocations(libraries)
[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
4 Library             SSHLibrary
5 Library             RequestsLibrary
6 Library             XML
7 Library             Collections
8 Library             ${CURDIR}/../../../libraries/ClusterEntities.py
9 Resource            ${CURDIR}/../../../libraries/SetupUtils.robot
10 Resource            ${CURDIR}/../../../libraries/Utils.robot
11 Resource            ${CURDIR}/../../../libraries/FlowLib.robot
12 Resource            ${CURDIR}/../../../libraries/OvsManager.robot
13 Resource            ${CURDIR}/../../../libraries/ClusterManagement.robot
14 Resource            ${CURDIR}/../../../libraries/ClusterOpenFlow.robot
15 Resource            ${CURDIR}/../../../variables/openflowplugin/Variables.robot
16
17 Suite Setup         Start Suite
18 Suite Teardown      End Suite
19 Test Setup          SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
20 Test Template       Isolating Node Scenario
21
22
23 *** Variables ***
24 ${SWITCHES}             1
25 ${START_CMD}            sudo mn --topo linear,${SWITCHES}
26 @{CONTROLLER_NODES}     ${ODL_SYSTEM_1_IP}    ${ODL_SYSTEM_2_IP}    ${ODL_SYSTEM_3_IP}
27 @{cntls_idx_list}       ${1}    ${2}    ${3}
28
29
30 *** Test Cases ***
31 Start Mininet To All Nodes
32     [Template]    NONE
33     ${mininet_conn_id}=    SSHLibrary.Open Connection    ${TOOLS_SYSTEM_IP}    prompt=${TOOLS_SYSTEM_PROMPT}
34     BuiltIn.Set Suite Variable    ${mininet_conn_id}
35     SSHLibrary.Login With Public Key    ${TOOLS_SYSTEM_USER}    ${USER_HOME}/.ssh/id_rsa    any
36     SSHLibrary.Put File    ${CURDIR}/../../../libraries/DynamicMininet.py    .
37     SSHLibrary.Execute Command    sudo ovs-vsctl set-manager ptcp:6644
38     SSHLibrary.Execute Command    sudo mn -c
39     SSHLibrary.Write    ${START_CMD}
40     SSHLibrary.Read Until    mininet>
41     ${cntls_list}=    BuiltIn.Create List    ${ODL_SYSTEM_1_IP}    ${ODL_SYSTEM_2_IP}    ${ODL_SYSTEM_3_IP}
42     ${switch_list}=    BuiltIn.Create List
43     FOR    ${i}    IN RANGE    0    ${SWITCHES}
44         ${sid}=    BuiltIn.Evaluate    ${i}+1
45         Collections.Append To List    ${switch_list}    s${sid}
46     END
47     BuiltIn.Set Suite Variable    ${active_member}    1
48     OvsManager.Setup Clustered Controller For Switches    ${switch_list}    ${cntls_list}
49     BuiltIn.Wait Until Keyword Succeeds
50     ...    15s
51     ...    1s
52     ...    ClusterOpenFlow.Verify Switch Connections Running On Member
53     ...    ${SWITCHES}
54     ...    1
55 Switches To Be Connected To All Nodes
56     [Documentation]    Initial check for correct connected topology.
57     [Template]    NONE
58     BuiltIn.Wait Until Keyword Succeeds    15x    1s    Check All Switches Connected To All Cluster Nodes
59 Isolating Owner Of Switch s1
60     s1
61     [Teardown]    Report_Failure_Due_To_Bug    6177
62 Switches Still Be Connected To All Nodes
63     [Template]    NONE
64     BuiltIn.Wait Until Keyword Succeeds    15x    1s    Check All Switches Connected To All Cluster Nodes
65     [Teardown]    Report_Failure_Due_To_Bug    6177
66 Stop Mininet And Verify No Owners
67     [Template]    NONE
68     Utils.Stop Mininet
69     BuiltIn.Wait Until Keyword Succeeds    15x    1s    Check No Device Owners In Controller
70     [Teardown]    Report_Failure_Due_To_Bug    6177
71
72
73 *** Keywords ***
74 Start Suite
75     SetupUtils.Setup_Utils_For_Setup_And_Teardown
76
77 End Suite
78     ClusterManagement.Flush Iptables From List Or All
79     RequestsLibrary.Delete All Sessions
80
81 Check All Switches Connected To All Cluster Nodes
82     [Documentation]    Verifies all switches are connected to all cluster nodes
83     OvsManager.Get Ovsdb Data
84     FOR    ${i}    IN RANGE    0    ${SWITCHES}
85         ${sid}=    BuiltIn.Evaluate    ${i}+1
86         OvsManager.Should Be Connected    s${sid}    ${ODL_SYSTEM_1_IP}    update_data=${False}
87         OvsManager.Should Be Connected    s${sid}    ${ODL_SYSTEM_2_IP}    update_data=${False}
88         OvsManager.Should Be Connected    s${sid}    ${ODL_SYSTEM_3_IP}    update_data=${False}
89     END
90
91 Isolating Node Scenario
92     [Documentation]    Disconnect and connect owner and successor and check switch data to be consistent
93     [Arguments]    ${switch_name}
94     BuiltIn.Set Test Variable    ${isol_node}    ${Empty}
95     ${idx}=    BuiltIn.Evaluate    str("${switch_name}"[1:])
96     BuiltIn.Set Test Variable    ${idx}
97     Isolate Switchs Old Owner    ${switch_name}
98     Rejoin Switchs Old Owner    ${switch_name}
99     Isolate Switchs Successor    ${switch_name}
100     Rejoin Switchs Successor    ${switch_name}
101     [Teardown]    Run Keyword If    "${isol_node}"!="${Empty}"    Rejoin Controller To The Cluster    ${isol_node}
102
103 Isolate Switchs Old Owner
104     [Arguments]    ${switch_name}
105     ${old_owner}    ${old_successors}=    ClusterOpenFlow.Get OpenFlow Entity Owner Status For One Device
106     ...    openflow:${idx}
107     ...    ${active_member}
108     ${old_master}=    BuiltIn.Set Variable    ${ODL_SYSTEM_${old_owner}_IP}
109     ${active_member}=    Collections.Get From List    ${old_successors}    0
110     BuiltIn.Set Suite Variable    ${active_member}
111     Isolate Controller From The Cluster    ${old_owner}
112     BuiltIn.Set Test Variable    ${isol_node}    ${old_owner}
113     ClusterOpenFlow.Check OpenFlow Shards Status After Cluster Event    ${old_successors}
114     ${new_master}=    BuiltIn.Wait Until Keyword Succeeds
115     ...    10x
116     ...    3s
117     ...    Verify New Master Controller Node
118     ...    ${switch_name}
119     ...    ${old_master}
120     ${owner}    ${successors}=    ClusterOpenFlow.Get OpenFlow Entity Owner Status For One Device
121     ...    openflow:${idx}
122     ...    ${active_member}
123     ...    ${old_successors}
124     BuiltIn.Should Be Equal As Strings    ${new_master}    ${ODL_SYSTEM_${owner}_IP}
125     BuiltIn.Set Suite Variable    ${active_member}    ${owner}
126     BuiltIn.Set Test Variable    ${old_owner}
127     BuiltIn.Set Test Variable    ${old_successors}
128     BuiltIn.Set Test Variable    ${old_master}
129     BuiltIn.Set Test Variable    ${owner}
130     BuiltIn.Set Test Variable    ${new_master}
131
132 Rejoin Switchs Old Owner
133     [Arguments]    ${switch_name}
134     Rejoin Controller To The Cluster    ${old_owner}
135     BuiltIn.Set Test Variable    ${isol_node}    ${Empty}
136     ClusterOpenFlow.Check OpenFlow Shards Status After Cluster Event
137     ${new_owner}    ${new_successors}=    BuiltIn.Wait Until Keyword Succeeds
138     ...    6x
139     ...    10s
140     ...    ClusterOpenFlow.Get OpenFlow Entity Owner Status For One Device
141     ...    openflow:${idx}
142     ...    ${active_member}
143
144 Isolate Switchs Successor
145     [Arguments]    ${switch_name}
146     ${old_owner}    ${old_successors}=    ClusterOpenFlow.Get OpenFlow Entity Owner Status For One Device
147     ...    openflow:${idx}
148     ...    ${active_member}
149     ${old_successor}=    Collections.Get From List    ${old_successors}    0
150     ${old_slave}=    BuiltIn.Set Variable    ${ODL_SYSTEM_${old_successor}_IP}
151     Isolate Controller From The Cluster    ${old_successor}
152     BuiltIn.Set Test Variable    ${isol_node}    ${old_successor}
153     ${tmp_candidates}=    BuiltIn.Create List    @{ClusterManagement__member_index_list}
154     Collections.Remove Values From List    ${tmp_candidates}    ${old_successor}
155     ClusterOpenFlow.Check OpenFlow Shards Status After Cluster Event    ${tmp_candidates}
156     ${owner}    ${successors}=    ClusterOpenFlow.Get OpenFlow Entity Owner Status For One Device
157     ...    openflow:${idx}
158     ...    ${active_member}
159     ...    ${tmp_candidates}
160     BuiltIn.Should Be Equal    ${owner}    ${old_owner}
161     BuiltIn.Set Test Variable    ${old_owner}
162     BuiltIn.Set Test Variable    ${old_successors}
163     BuiltIn.Set Test Variable    ${old_successor}
164     BuiltIn.Set Test Variable    ${old_slave}
165     BuiltIn.Set Test Variable    ${owner}
166
167 Rejoin Switchs Successor
168     [Arguments]    ${switch_name}
169     Rejoin Controller To The Cluster    ${old_successor}
170     BuiltIn.Set Test Variable    ${isol_node}    ${Empty}
171     ClusterOpenFlow.Check OpenFlow Shards Status After Cluster Event
172     ${new_owner}    ${new_successors}=    BuiltIn.Wait Until Keyword Succeeds
173     ...    6x
174     ...    10s
175     ...    ClusterOpenFlow.Get OpenFlow Entity Owner Status For One Device
176     ...    openflow:${idx}
177     ...    ${active_member}
178
179 Rejoin Controller To The Cluster
180     [Arguments]    ${isolated_node}
181     ClusterManagement.Rejoin Member From List Or All    ${isolated_node}
182     [Teardown]    SSHLibrary.Switch Connection    ${mininet_conn_id}
183
184 Isolate Controller From The Cluster
185     [Arguments]    ${isolated_node}
186     ClusterManagement.Isolate Member From List Or All    ${isolated_node}
187     [Teardown]    SSHLibrary.Switch Connection    ${mininet_conn_id}
188
189 Check No Device Owners In Controller
190     [Documentation]    Check there is no owners in controllers
191     ${ip}=    Resolve_IP_Address_For_Member    member_index=${active_member}
192     ${url}=    BuiltIn.Catenate    SEPARATOR=    http://    ${ip}    :8181    ${RFC8040_RESTCONF_ROOT}
193     ${data}=    ClusterEntities.Get_Entities    ${url}
194     ${data}=    BuiltIn.Convert_To_String    ${data}
195     #ofp-topology-manager entity is introduced in the OPNFLWPLUG-1022 bug fix, and this entity will
196     #always be present in the EOS output. All 3 controller nodes will be candidate, so EOS output will
197     #contain 6 members (members show 2 times).
198     BuiltIn.Should Contain X Times    ${data}    member    6
199
200 Verify New Master Controller Node
201     [Documentation]    Checks if given node is different from actual master
202     [Arguments]    ${switch_name}    ${old_master}
203     ${idx}=    BuiltIn.Evaluate    "${switch_name}"[1:]
204     ${owner}    ${successors}=    ClusterManagement.Get Owner And Candidates For Device
205     ...    openflow:${idx}
206     ...    openflow
207     ...    ${active_member}
208     ${new_master}=    BuiltIn.Set Variable    ${ODL_SYSTEM_${owner}_IP}
209     BuiltIn.Should Not Be Equal    ${old_master}    ${new_master}
210     RETURN    ${new_master}