Upgrade RF syntax for v3.2 compatibility
[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 Suite Setup       Setup Custom SXP Cluster Session
6 Suite Teardown    Clean Custom SXP Cluster Session
7 Library           ../../../libraries/Sxp.py
8 Resource          ../../../libraries/ClusterManagement.robot
9 Resource          ../../../libraries/SxpClusterLib.robot
10
11 *** Variables ***
12 ${BINDINGS}       4
13 ${NEW_OWNER}      ${EMPTY}
14
15 *** Test Cases ***
16 Isolation Of SXP Service Follower W/O Bindings Listener Test
17     [Documentation]    Device is listener. Connection between device and cluster must be established despite of cluster owner isolation
18     [Setup]    Setup Nodes And Connections    listener
19     ${cluster_owner} =    SxpClusterLib.Get Owner Controller
20     BuiltIn.Wait Until Keyword Succeeds    240x    1s    SxpClusterLib.Ip Addres Should Be Routed To Follower    ${MAC_ADDRESS_TABLE}    ${VIRTUAL_IP}    ${cluster_owner}
21     Check Connections    ${cluster_owner}    listener
22     Isolate SXP Controller    ${cluster_owner}
23     BuiltIn.Wait Until Keyword Succeeds    240x    1s    SxpClusterLib.Ip Addres Should Be Routed To Follower    ${MAC_ADDRESS_TABLE}    ${VIRTUAL_IP}    ${NEW_OWNER}
24     Check Connections    ${NEW_OWNER}    listener
25     [Teardown]    Clean Custom SXP Cluster
26
27 Isolation Of SXP Service Follower W/O Bindings Speaker Test
28     [Documentation]    Device is speaker. Connection between device and cluster must be established despite of cluster owner isolation
29     [Setup]    Setup Nodes And Connections    speaker
30     ${cluster_owner} =    SxpClusterLib.Get Owner Controller
31     BuiltIn.Wait Until Keyword Succeeds    240x    1s    SxpClusterLib.Ip Addres Should Be Routed To Follower    ${MAC_ADDRESS_TABLE}    ${VIRTUAL_IP}    ${cluster_owner}
32     Check Connections    ${cluster_owner}    speaker
33     Isolate SXP Controller    ${cluster_owner}
34     BuiltIn.Wait Until Keyword Succeeds    240x    1s    SxpClusterLib.Ip Addres Should Be Routed To Follower    ${MAC_ADDRESS_TABLE}    ${VIRTUAL_IP}    ${NEW_OWNER}
35     Check Connections    ${NEW_OWNER}    speaker
36     [Teardown]    Clean Custom SXP Cluster
37
38 Isolation Of SXP Service Follower Listener Test
39     [Documentation]    Device is listener. Cluster owner is isolated but bindings must be propagated to the device throught virtual IP
40     [Setup]    Setup Nodes And Connections    listener
41     ${cluster_owner} =    SxpClusterLib.Get Owner Controller
42     BuiltIn.Wait Until Keyword Succeeds    240x    1s    SxpClusterLib.Ip Addres Should Be Routed To Follower    ${MAC_ADDRESS_TABLE}    ${VIRTUAL_IP}    ${cluster_owner}
43     Check Connections    ${cluster_owner}    listener
44     Add Bindings To Node    ${CLUSTER_NODE_ID}    ClusterManagement__session_${cluster_owner}
45     BuiltIn.Wait Until Keyword Succeeds    240x    1s    Check Bindings    ${DEVICE_NODE_ID}    ${DEVICE_SESSION}
46     Isolate SXP Controller    ${cluster_owner}
47     BuiltIn.Wait Until Keyword Succeeds    240x    1s    SxpClusterLib.Ip Addres Should Be Routed To Follower    ${MAC_ADDRESS_TABLE}    ${VIRTUAL_IP}    ${NEW_OWNER}
48     Check Connections    ${NEW_OWNER}    listener
49     BuiltIn.Wait Until Keyword Succeeds    240x    1s    Check Bindings    ${DEVICE_NODE_ID}    ${DEVICE_SESSION}
50     [Teardown]    Clean Custom SXP Cluster
51
52 Isolation Of SXP Service Follower Speaker Test
53     [Documentation]    Device is speaker. Cluster owner is isolated but bindings must be propagated to the cluster throught virtual IP
54     [Setup]    Setup Nodes And Connections    speaker
55     ${cluster_owner} =    SxpClusterLib.Get Owner Controller
56     BuiltIn.Wait Until Keyword Succeeds    240x    1s    SxpClusterLib.Ip Addres Should Be Routed To Follower    ${MAC_ADDRESS_TABLE}    ${VIRTUAL_IP}    ${cluster_owner}
57     Check Connections    ${cluster_owner}    speaker
58     Add Bindings To Node    ${DEVICE_NODE_ID}    ${DEVICE_SESSION}
59     BuiltIn.Wait Until Keyword Succeeds    240x    1s    Check Bindings    ${CLUSTER_NODE_ID}    ClusterManagement__session_${cluster_owner}
60     Isolate SXP Controller    ${cluster_owner}
61     BuiltIn.Wait Until Keyword Succeeds    240x    1s    SxpClusterLib.Ip Addres Should Be Routed To Follower    ${MAC_ADDRESS_TABLE}    ${VIRTUAL_IP}    ${NEW_OWNER}
62     Check Connections    ${NEW_OWNER}    speaker
63     BuiltIn.Wait Until Keyword Succeeds    240x    1s    Check Bindings    ${CLUSTER_NODE_ID}    ClusterManagement__session_${NEW_OWNER}
64     [Teardown]    Clean Custom SXP Cluster
65
66 *** Keywords ***
67 Setup Custom SXP Cluster Session
68     [Documentation]    Prepare topology for testing, creates sessions and generate Route definitions based on Cluster nodes IP
69     SxpClusterLib.Shutdown Tools Node
70     SxpClusterLib.Create Virtual Interface
71     SxpClusterLib.Setup SXP Cluster Session
72     SxpClusterLib.Setup Device Session
73     Retrieve Mac-addresses
74     Setup Virtual IP
75
76 Retrieve Mac-addresses
77     [Documentation]    Create list of ODL nodes mac-addresses
78     ${mac_addresses} =    SxpClusterLib.Map Followers To Mac Addresses
79     BuiltIn.Set Suite Variable    ${MAC_ADDRESS_TABLE}    ${mac_addresses}
80
81 Setup Virtual IP
82     [Documentation]    Enable routing to cluster through virtual IP
83     ${route} =    Sxp.Route Definition Xml    ${VIRTUAL_IP}    ${VIRTUAL_IP_MASK}    ${VIRTUAL_INTERFACE}
84     ${routes} =    Sxp.Route Definitions Xml    ${route}
85     SxpLib.Put Routing Configuration To Controller    ${routes}    ${CONTROLLER_SESSION}
86
87 Setup Nodes And Connections
88     [Arguments]    ${peer_mode}
89     [Documentation]    Setup and connect SXP cluster topology and one device
90     SxpClusterLib.Check Shards Status
91     SxpLib.Add Node    ${DEVICE_NODE_ID}    session=${DEVICE_SESSION}    retry_open_timer=2
92     BuiltIn.Wait Until Keyword Succeeds    240x    1s    SxpLib.Check Node Started    ${DEVICE_NODE_ID}    session=${DEVICE_SESSION}
93     SxpLib.Add Connection    version4    ${peer_mode}    ${VIRTUAL_IP}    64999    ${DEVICE_NODE_ID}    session=${DEVICE_SESSION}
94     ${cluster_mode} =    Sxp.Get Opposing Mode    ${peer_mode}
95     SxpLib.Add Node    ${CLUSTER_NODE_ID}    session=${CONTROLLER_SESSION}    retry_open_timer=5
96     BuiltIn.Wait Until Keyword Succeeds    240x    1s    SxpClusterLib.Check Cluster Node Started    ${CLUSTER_NODE_ID}
97     SxpLib.Add Connection    version4    ${cluster_mode}    ${DEVICE_NODE_ID}    64999    ${CLUSTER_NODE_ID}    session=${CONTROLLER_SESSION}
98
99 Clean Custom SXP Cluster Session
100     [Documentation]    Clean up resources generated by test
101     SxpLib.Clean Routing Configuration To Controller    ${CONTROLLER_SESSION}
102     SxpClusterLib.Clean SXP Cluster Session
103     SxpClusterLib.Delete Virtual Interface
104
105 Clean Custom SXP Cluster
106     [Documentation]    Disconnect SXP cluster topology
107     ClusterManagement.Flush_Iptables_From_List_Or_All
108     BuiltIn.Wait_Until_Keyword_Succeeds    60    1    ClusterManagement.Verify_Members_Are_Ready    member_index_list=${EMPTY}    verify_cluster_sync=True    verify_restconf=True
109     ...    verify_system_status=False    service_list=${EMPTY_LIST}
110     SxpLib.Delete Node    ${DEVICE_NODE_ID}    session=${DEVICE_SESSION}
111     SxpLib.Delete Node    ${CLUSTER_NODE_ID}    session=${CONTROLLER_SESSION}
112
113 Add Bindings To Node
114     [Arguments]    ${node}    ${session}
115     [Documentation]    Setup initial bindings to SXP device/controller ${node} with ${session}
116     FOR    ${i}    IN RANGE    1    ${BINDINGS}
117         SxpLib.Add Bindings    ${i}0    ${i}.${i}.${i}.${i}/32    node=${node}    session=${session}
118     END
119
120 Isolate SXP Controller
121     [Arguments]    ${controller_index}
122     [Documentation]    Isolate cluster node specified by ${controller_index} and find new owner
123     @{running_members} =    ClusterManagement.Isolate_Member_From_List_Or_All    ${controller_index}
124     BuiltIn.Wait_Until_Keyword_Succeeds    60    1    ClusterManagement.Verify_Members_Are_Ready    member_index_list=${running_members}    verify_cluster_sync=True    verify_restconf=True
125     ...    verify_system_status=False    service_list=${EMPTY_LIST}
126     BuiltIn.Wait Until Keyword Succeeds    240x    1s    ClusterManagement.Sync_Status_Should_Be_False    ${controller_index}
127     BuiltIn.Wait Until Keyword Succeeds    240x    1s    SxpClusterLib.Ip Addres Should Not Be Routed To Follower    ${MAC_ADDRESS_TABLE}    ${VIRTUAL_IP}    ${controller_index}
128     ${running_member} =    Collections.Get From List    ${running_members}    0
129     ${new_owner} =    SxpClusterLib.Get Owner Controller    ${running_member}
130     BuiltIn.Set Test Variable    ${NEW_OWNER}    ${new_owner}
131
132 Check Connections
133     [Arguments]    ${controller_index}    ${peer_mode}
134     [Documentation]    Check that connection is established between device and the cluster
135     ${cluster_mode} =    Sxp.Get Opposing Mode    ${peer_mode}
136     BuiltIn.Wait Until Keyword Succeeds    480x    1s    SxpClusterLib.Check Cluster is Connected    ${CLUSTER_NODE_ID}    mode=${cluster_mode}    session=ClusterManagement__session_${controller_index}
137     BuiltIn.Wait Until Keyword Succeeds    480x    1s    Check Device is Connected    ${DEVICE_NODE_ID}    ${peer_mode}    session=${DEVICE_SESSION}
138
139 Check Device is Connected
140     [Arguments]    ${node}    ${mode}    ${session}    ${version}=version4    ${port}=64999
141     [Documentation]    Check if SXP device is connected to the cluster. It means it has connection to ${VIRTUAL_IP} in state "on"
142     ${resp} =    SxpLib.Get Connections    node=${node}    session=${session}
143     SxpLib.Should Contain Connection    ${resp}    ${VIRTUAL_IP}    ${port}    ${mode}    ${version}    on
144
145 Check Bindings
146     [Arguments]    ${node}    ${session}
147     [Documentation]    Check that bindings were propagated to the peer ${node}
148     ${resp} =    SxpLib.Get Bindings    node=${node}    session=${session}
149     FOR    ${i}    IN RANGE    1    ${BINDINGS}
150         SxpLib.Should Contain Binding    ${resp}    ${i}0    ${i}.${i}.${i}.${i}/32
151     END