Migrate Get Requests invocations(libraries)
[integration/test.git] / csit / suites / sxp / cluster-routing / 020_Sxp_Node_Switching.robot
1 *** Settings ***
2 Documentation       Test suite to test cluster connection and propagation switchover using virtual IP, this suite requires additional TOOLS_SYSTEM_2 VM.
3 ...                 VM is used for its assigned ip-address that will be overlayed by virtual-ip used in test suites.
4 ...                 Resources of this VM are not required. At suite start this node is shutted down to reduce routing conflicts.
5
6 Library             ../../../libraries/Sxp.py
7 Resource            ../../../libraries/ClusterManagement.robot
8 Resource            ../../../libraries/SxpClusterLib.robot
9
10 Suite Setup         Setup Custom SXP Cluster Session
11 Suite Teardown      Clean Custom SXP Cluster Session
12
13
14 *** Variables ***
15 ${BINDINGS}     4
16 ${NEW_OWNER}    ${EMPTY}
17
18
19 *** Test Cases ***
20 Isolation Of SXP Service Follower W/O Bindings Listener Test
21     [Documentation]    Device is listener. Connection between device and cluster must be established despite of cluster owner isolation
22     [Setup]    Setup Nodes And Connections    listener
23     ${cluster_owner} =    SxpClusterLib.Get Owner Controller
24     BuiltIn.Wait Until Keyword Succeeds
25     ...    240x
26     ...    1s
27     ...    SxpClusterLib.Ip Addres Should Be Routed To Follower
28     ...    ${MAC_ADDRESS_TABLE}
29     ...    ${VIRTUAL_IP}
30     ...    ${cluster_owner}
31     Check Connections    ${cluster_owner}    listener
32     Isolate SXP Controller    ${cluster_owner}
33     BuiltIn.Wait Until Keyword Succeeds
34     ...    240x
35     ...    1s
36     ...    SxpClusterLib.Ip Addres Should Be Routed To Follower
37     ...    ${MAC_ADDRESS_TABLE}
38     ...    ${VIRTUAL_IP}
39     ...    ${NEW_OWNER}
40     Check Connections    ${NEW_OWNER}    listener
41     [Teardown]    Clean Custom SXP Cluster
42
43 Isolation Of SXP Service Follower W/O Bindings Speaker Test
44     [Documentation]    Device is speaker. Connection between device and cluster must be established despite of cluster owner isolation
45     [Setup]    Setup Nodes And Connections    speaker
46     ${cluster_owner} =    SxpClusterLib.Get Owner Controller
47     BuiltIn.Wait Until Keyword Succeeds
48     ...    240x
49     ...    1s
50     ...    SxpClusterLib.Ip Addres Should Be Routed To Follower
51     ...    ${MAC_ADDRESS_TABLE}
52     ...    ${VIRTUAL_IP}
53     ...    ${cluster_owner}
54     Check Connections    ${cluster_owner}    speaker
55     Isolate SXP Controller    ${cluster_owner}
56     BuiltIn.Wait Until Keyword Succeeds
57     ...    240x
58     ...    1s
59     ...    SxpClusterLib.Ip Addres Should Be Routed To Follower
60     ...    ${MAC_ADDRESS_TABLE}
61     ...    ${VIRTUAL_IP}
62     ...    ${NEW_OWNER}
63     Check Connections    ${NEW_OWNER}    speaker
64     [Teardown]    Clean Custom SXP Cluster
65
66 Isolation Of SXP Service Follower Listener Test
67     [Documentation]    Device is listener. Cluster owner is isolated but bindings must be propagated to the device throught virtual IP
68     [Setup]    Setup Nodes And Connections    listener
69     ${cluster_owner} =    SxpClusterLib.Get Owner Controller
70     BuiltIn.Wait Until Keyword Succeeds
71     ...    240x
72     ...    1s
73     ...    SxpClusterLib.Ip Addres Should Be Routed To Follower
74     ...    ${MAC_ADDRESS_TABLE}
75     ...    ${VIRTUAL_IP}
76     ...    ${cluster_owner}
77     Check Connections    ${cluster_owner}    listener
78     Add Bindings To Node    ${CLUSTER_NODE_ID}    ClusterManagement__session_${cluster_owner}
79     BuiltIn.Wait Until Keyword Succeeds    240x    1s    Check Bindings    ${DEVICE_NODE_ID}    ${DEVICE_SESSION}
80     Isolate SXP Controller    ${cluster_owner}
81     BuiltIn.Wait Until Keyword Succeeds
82     ...    240x
83     ...    1s
84     ...    SxpClusterLib.Ip Addres Should Be Routed To Follower
85     ...    ${MAC_ADDRESS_TABLE}
86     ...    ${VIRTUAL_IP}
87     ...    ${NEW_OWNER}
88     Check Connections    ${NEW_OWNER}    listener
89     BuiltIn.Wait Until Keyword Succeeds    240x    1s    Check Bindings    ${DEVICE_NODE_ID}    ${DEVICE_SESSION}
90     [Teardown]    Clean Custom SXP Cluster
91
92 Isolation Of SXP Service Follower Speaker Test
93     [Documentation]    Device is speaker. Cluster owner is isolated but bindings must be propagated to the cluster throught virtual IP
94     [Setup]    Setup Nodes And Connections    speaker
95     ${cluster_owner} =    SxpClusterLib.Get Owner Controller
96     BuiltIn.Wait Until Keyword Succeeds
97     ...    240x
98     ...    1s
99     ...    SxpClusterLib.Ip Addres Should Be Routed To Follower
100     ...    ${MAC_ADDRESS_TABLE}
101     ...    ${VIRTUAL_IP}
102     ...    ${cluster_owner}
103     Check Connections    ${cluster_owner}    speaker
104     Add Bindings To Node    ${DEVICE_NODE_ID}    ${DEVICE_SESSION}
105     BuiltIn.Wait Until Keyword Succeeds
106     ...    240x
107     ...    1s
108     ...    Check Bindings
109     ...    ${CLUSTER_NODE_ID}
110     ...    ClusterManagement__session_${cluster_owner}
111     Isolate SXP Controller    ${cluster_owner}
112     BuiltIn.Wait Until Keyword Succeeds
113     ...    240x
114     ...    1s
115     ...    SxpClusterLib.Ip Addres Should Be Routed To Follower
116     ...    ${MAC_ADDRESS_TABLE}
117     ...    ${VIRTUAL_IP}
118     ...    ${NEW_OWNER}
119     Check Connections    ${NEW_OWNER}    speaker
120     BuiltIn.Wait Until Keyword Succeeds
121     ...    240x
122     ...    1s
123     ...    Check Bindings
124     ...    ${CLUSTER_NODE_ID}
125     ...    ClusterManagement__session_${NEW_OWNER}
126     [Teardown]    Clean Custom SXP Cluster
127
128
129 *** Keywords ***
130 Setup Custom SXP Cluster Session
131     [Documentation]    Prepare topology for testing, creates sessions and generate Route definitions based on Cluster nodes IP
132     SxpClusterLib.Shutdown Tools Node
133     SxpClusterLib.Create Virtual Interface
134     SxpClusterLib.Setup SXP Cluster Session
135     SxpClusterLib.Setup Device Session
136     Retrieve Mac-addresses
137     Setup Virtual IP
138
139 Retrieve Mac-addresses
140     [Documentation]    Create list of ODL nodes mac-addresses
141     ${mac_addresses} =    SxpClusterLib.Map Followers To Mac Addresses
142     BuiltIn.Set Suite Variable    ${MAC_ADDRESS_TABLE}    ${mac_addresses}
143
144 Setup Virtual IP
145     [Documentation]    Enable routing to cluster through virtual IP
146     ${route} =    Sxp.Route Definition Xml    ${VIRTUAL_IP}    ${VIRTUAL_IP_MASK}    ${VIRTUAL_INTERFACE}
147     ${routes} =    Sxp.Route Definitions Xml    ${route}
148     SxpLib.Put Routing Configuration To Controller    ${routes}    ${CONTROLLER_SESSION}
149
150 Setup Nodes And Connections
151     [Documentation]    Setup and connect SXP cluster topology and one device
152     [Arguments]    ${peer_mode}
153     SxpClusterLib.Check Shards Status
154     SxpLib.Add Node    ${DEVICE_NODE_ID}    session=${DEVICE_SESSION}    retry_open_timer=2
155     BuiltIn.Wait Until Keyword Succeeds
156     ...    240x
157     ...    1s
158     ...    SxpLib.Check Node Started
159     ...    ${DEVICE_NODE_ID}
160     ...    session=${DEVICE_SESSION}
161     SxpLib.Add Connection
162     ...    version4
163     ...    ${peer_mode}
164     ...    ${VIRTUAL_IP}
165     ...    64999
166     ...    ${DEVICE_NODE_ID}
167     ...    session=${DEVICE_SESSION}
168     ${cluster_mode} =    Sxp.Get Opposing Mode    ${peer_mode}
169     SxpLib.Add Node    ${CLUSTER_NODE_ID}    session=${CONTROLLER_SESSION}    retry_open_timer=5
170     BuiltIn.Wait Until Keyword Succeeds    240x    1s    SxpClusterLib.Check Cluster Node Started    ${CLUSTER_NODE_ID}
171     SxpLib.Add Connection
172     ...    version4
173     ...    ${cluster_mode}
174     ...    ${DEVICE_NODE_ID}
175     ...    64999
176     ...    ${CLUSTER_NODE_ID}
177     ...    session=${CONTROLLER_SESSION}
178
179 Clean Custom SXP Cluster Session
180     [Documentation]    Clean up resources generated by test
181     SxpLib.Clean Routing Configuration To Controller    ${CONTROLLER_SESSION}
182     SxpClusterLib.Clean SXP Cluster Session
183     SxpClusterLib.Delete Virtual Interface
184
185 Clean Custom SXP Cluster
186     [Documentation]    Disconnect SXP cluster topology
187     ClusterManagement.Flush_Iptables_From_List_Or_All
188     BuiltIn.Wait_Until_Keyword_Succeeds
189     ...    60
190     ...    1
191     ...    ClusterManagement.Verify_Members_Are_Ready
192     ...    member_index_list=${EMPTY}
193     ...    verify_cluster_sync=True
194     ...    verify_restconf=True
195     ...    verify_system_status=False
196     ...    service_list=${EMPTY_LIST}
197     SxpLib.Delete Node    ${DEVICE_NODE_ID}    session=${DEVICE_SESSION}
198     SxpLib.Delete Node    ${CLUSTER_NODE_ID}    session=${CONTROLLER_SESSION}
199
200 Add Bindings To Node
201     [Documentation]    Setup initial bindings to SXP device/controller ${node} with ${session}
202     [Arguments]    ${node}    ${session}
203     FOR    ${i}    IN RANGE    1    ${BINDINGS}
204         SxpLib.Add Bindings    ${i}0    ${i}.${i}.${i}.${i}/32    node=${node}    session=${session}
205     END
206
207 Isolate SXP Controller
208     [Documentation]    Isolate cluster node specified by ${controller_index} and find new owner
209     [Arguments]    ${controller_index}
210     @{running_members} =    ClusterManagement.Isolate_Member_From_List_Or_All    ${controller_index}
211     BuiltIn.Wait_Until_Keyword_Succeeds
212     ...    60
213     ...    1
214     ...    ClusterManagement.Verify_Members_Are_Ready
215     ...    member_index_list=${running_members}
216     ...    verify_cluster_sync=True
217     ...    verify_restconf=True
218     ...    verify_system_status=False
219     ...    service_list=${EMPTY_LIST}
220     BuiltIn.Wait Until Keyword Succeeds
221     ...    240x
222     ...    1s
223     ...    ClusterManagement.Sync_Status_Should_Be_False
224     ...    ${controller_index}
225     BuiltIn.Wait Until Keyword Succeeds
226     ...    240x
227     ...    1s
228     ...    SxpClusterLib.Ip Addres Should Not Be Routed To Follower
229     ...    ${MAC_ADDRESS_TABLE}
230     ...    ${VIRTUAL_IP}
231     ...    ${controller_index}
232     ${running_member} =    Collections.Get From List    ${running_members}    0
233     ${new_owner} =    SxpClusterLib.Get Owner Controller    ${running_member}
234     BuiltIn.Set Test Variable    ${NEW_OWNER}    ${new_owner}
235
236 Check Connections
237     [Documentation]    Check that connection is established between device and the cluster
238     [Arguments]    ${controller_index}    ${peer_mode}
239     ${cluster_mode} =    Sxp.Get Opposing Mode    ${peer_mode}
240     BuiltIn.Wait Until Keyword Succeeds
241     ...    480x
242     ...    1s
243     ...    SxpClusterLib.Check Cluster is Connected
244     ...    ${CLUSTER_NODE_ID}
245     ...    mode=${cluster_mode}
246     ...    session=ClusterManagement__session_${controller_index}
247     BuiltIn.Wait Until Keyword Succeeds
248     ...    480x
249     ...    1s
250     ...    Check Device is Connected
251     ...    ${DEVICE_NODE_ID}
252     ...    ${peer_mode}
253     ...    session=${DEVICE_SESSION}
254
255 Check Device is Connected
256     [Documentation]    Check if SXP device is connected to the cluster. It means it has connection to ${VIRTUAL_IP} in state "on"
257     [Arguments]    ${node}    ${mode}    ${session}    ${version}=version4    ${port}=64999
258     ${resp} =    SxpLib.Get Connections    node=${node}    session=${session}
259     SxpLib.Should Contain Connection    ${resp}    ${VIRTUAL_IP}    ${port}    ${mode}    ${version}    on
260
261 Check Bindings
262     [Documentation]    Check that bindings were propagated to the peer ${node}
263     [Arguments]    ${node}    ${session}
264     ${resp} =    SxpLib.Get Bindings    node=${node}    session=${session}
265     FOR    ${i}    IN RANGE    1    ${BINDINGS}
266         SxpLib.Should Contain Binding    ${resp}    ${i}0    ${i}.${i}.${i}.${i}/32
267     END