2 Documentation Library containing Keywords used for SXP cluster testing
3 Library RequestsLibrary
4 Resource ./ClusterManagement.robot
5 Resource ./SetupUtils.robot
6 Resource ./SxpLib.robot
9 @{SHARD_OPER_LIST} inventory topology default entity-ownership
10 @{SHARD_CONF_LIST} inventory topology default
11 @{SXP_PACKAGE} org.opendaylight.sxp
12 ${DEVICE_SESSION} device_1
13 ${CONTROLLER_SESSION} ClusterManagement__session_1
14 ${DEVICE_NODE_ID} 1.1.1.1
15 ${CLUSTER_NODE_ID} 2.2.2.2
17 ${VIRTUAL_IP} ${TOOLS_SYSTEM_2_IP}
18 ${VIRTUAL_IP_MASK} 255.255.255.0
19 ${VIRTUAL_INTERFACE} eth0
20 ${MAC_ADDRESS_TABLE} &{EMPTY}
23 Setup SXP Cluster Session
24 [Documentation] Create sessions asociated with SXP cluster setup
25 ClusterManagement.ClusterManagement_Setup
26 SetupUtils.Setup_Utils_For_Setup_And_Teardown
27 SetupUtils.Setup_Logging_For_Debug_Purposes_On_List_Or_All ${SXP_LOG_LEVEL} ${SXP_PACKAGE}
29 Clean SXP Cluster Session
30 [Documentation] Clean sessions asociated with SXP cluster setup
31 ClusterManagement.Flush_Iptables_From_List_Or_All
32 ClusterManagement.Check_Cluster_Is_In_Sync
33 SxpLib.Clean SXP Session
34 SetupUtils.Setup_Logging_For_Debug_Purposes_On_List_Or_All INFO ${SXP_PACKAGE}
37 [Documentation] Check Status for all shards in SXP application.
38 ClusterManagement.Check_Cluster_Is_In_Sync
39 ClusterManagement.Verify_Leader_Exists_For_Each_Shard shard_name_list=${SHARD_OPER_LIST} shard_type=operational
40 ClusterManagement.Verify_Leader_Exists_For_Each_Shard shard_name_list=${SHARD_CONF_LIST} shard_type=config
43 [Arguments] ${peer_mode}=listener
44 [Documentation] Setup and connect SXP cluster topology
45 SxpLib.Add Node ${DEVICE_NODE_ID} ip=0.0.0.0 session=${DEVICE_SESSION}
46 BuiltIn.Wait Until Keyword Succeeds 20 1 SxpLib.Check Node Started ${DEVICE_NODE_ID} session=${DEVICE_SESSION} system=${TOOLS_SYSTEM_IP}
48 ${cluster_mode} = Sxp.Get Opposing Mode ${peer_mode}
49 : FOR ${i} IN RANGE ${NUM_ODL_SYSTEM}
50 \ SxpLib.Add Connection version4 ${peer_mode} ${ODL_SYSTEM_${i+1}_IP} 64999 ${DEVICE_NODE_ID}
51 \ ... session=${DEVICE_SESSION}
52 ${controller_id} = Get Any Controller
53 SxpLib.Add Node ${CLUSTER_NODE_ID} ip=0.0.0.0 session=controller${controller_id}
54 BuiltIn.Wait Until Keyword Succeeds 20 1 Check Cluster Node started ${CLUSTER_NODE_ID}
55 SxpLib.Add Connection version4 ${cluster_mode} ${TOOLS_SYSTEM_IP} 64999 ${CLUSTER_NODE_ID} session=controller${controller_id}
56 BuiltIn.Wait Until Keyword Succeeds 120 1 Check Device is Connected ${DEVICE_NODE_ID} session=${DEVICE_SESSION}
59 [Documentation] Disconnect SXP cluster topology
60 ClusterManagement.Flush_Iptables_From_List_Or_All
61 : FOR ${i} IN RANGE ${NUM_ODL_SYSTEM}
62 \ BuiltIn.Wait Until Keyword Succeeds 240 1 ClusterManagement.Sync_Status_Should_Be_True ${i+1}
63 ${controller_index} = Get Owner Controller
64 SxpLib.Delete Node ${DEVICE_NODE_ID} session=${DEVICE_SESSION}
65 SxpLib.Delete Node ${CLUSTER_NODE_ID} session=controller${controller_index}
67 Check Cluster Node started
68 [Arguments] ${node} ${port}=64999 ${ip}=${EMPTY}
69 [Documentation] Verify that SxpNode has data written to Operational datastore and Node is running on one of cluster nodes
70 ${started} = BuiltIn.Set Variable ${False}
71 : FOR ${i} IN RANGE ${NUM_ODL_SYSTEM}
72 \ ${rc} = Utils.Run Command On Remote System ${ODL_SYSTEM_${i+1}_IP} netstat -tln | grep -q ${ip}:${port} && echo 0 || echo 1 ${ODL_SYSTEM_USER} ${ODL_SYSTEM_PASSWORD}
73 \ ... prompt=${ODL_SYSTEM_PROMPT}
74 \ ${started} = BuiltIn.Set Variable If '${rc}' == '0' ${True} ${started}
75 BuiltIn.Should Be True ${started}
77 Check Device is Connected
78 [Arguments] ${node} ${version}=version4 ${port}=64999 ${session}=session
79 [Documentation] Checks if SXP device is connected to at least one cluster node
80 ${is_connected} = BuiltIn.Set Variable ${False}
81 ${resp} = SxpLib.Get Connections node=${node} session=${session}
82 : FOR ${i} IN RANGE ${NUM_ODL_SYSTEM}
83 \ ${follower} = Sxp.Find Connection ${resp} ${version} any ${ODL_SYSTEM_${i+1}_IP}
85 \ ${is_connected} = BuiltIn.Run Keyword If ${follower} BuiltIn.Set Variable ${True}
86 \ ... ELSE BuiltIn.Set Variable ${is_connected}
87 BuiltIn.Should Be True ${is_connected}
89 Check Cluster is Connected
90 [Arguments] ${node} ${version}=version4 ${port}=64999 ${mode}=speaker ${session}=session
91 [Documentation] Checks if SXP device is connected to at least one cluster node
92 ${resp} = SxpLib.Get Connections node=${node} session=${session}
93 SxpLib.Should Contain Connection ${resp} ${TOOLS_SYSTEM_IP} ${port} ${mode} ${version}
96 [Arguments] ${running_member}=1
97 [Documentation] Find cluster controller that is marked as cluster owner by requesting ownership data from ${running_member} node of the cluster
98 ${owner} ${candidates} = BuiltIn.Wait_Until_Keyword_Succeeds 5x 2s ClusterManagement.Get_Owner_And_Successors_For_Device org.opendaylight.sxp.controller.boot.SxpControllerInstance
99 ... Sxp ${running_member}
102 Get Not Owner Controller
103 [Documentation] Find cluster controller that is not marked as owner for SXP service in cluster
104 ${owner_controller} = Get Owner Controller
105 ${controller} = BuiltIn.Evaluate random.choice( filter( lambda i: i!=${owner_controller}, range(1, ${NUM_ODL_SYSTEM} + 1))) random
106 [Return] ${controller}
109 [Documentation] Get any controller from cluster range
110 ${follower} = BuiltIn.Evaluate random.choice( range(1, ${NUM_ODL_SYSTEM} + 1)) random
113 Map Followers To Mac Addresses
114 [Documentation] Creates Map containing ODL_SYSTEM_IP to corresponding MAC-ADDRESS
115 ${mac_addresses} = BuiltIn.Create dictionary
116 : FOR ${i} IN RANGE ${NUM_ODL_SYSTEM}
117 \ ${mac_address} Find Mac Address Of Ip Address ${ODL_SYSTEM_${i+1}_IP}
118 \ Collections.Set To Dictionary ${mac_addresses} ${ODL_SYSTEM_${i+1}_IP} ${mac_address}
119 BuiltIn.Log ${mac_addresses}
120 [Return] ${mac_addresses}
122 Find Mac Address Of Ip Address
124 [Documentation] Finds out MAC-ADDRESS of specified IP by pinging it from TOOLS_SYSTEM machine
125 ${mac_address} = Utils.Run Command On Remote System ${TOOLS_SYSTEM_IP} ping -c 1 -W 1 ${ip} >/dev/null && arp -n | grep ${ip} | awk '{print $3}' ${TOOLS_SYSTEM_USER} ${TOOLS_SYSTEM_PASSWORD}
126 [Return] ${mac_address}
128 Ip Addres Should Not Be Routed To Follower
129 [Arguments] ${mac_addresses} ${ip_address} ${follower_index}
130 [Documentation] Verify that IP-ADDRESS is not routed to follower specified by ID
131 ${mac_address_assigned} = Collections.Get From Dictionary ${mac_addresses} ${ODL_SYSTEM_${follower_index}_IP}
132 ${mac_address_resolved} = Find Mac Address Of Ip Address ${ip_address}
133 BuiltIn.Should Not Be Equal As Strings ${mac_address_assigned} ${mac_address_resolved}
135 Ip Addres Should Be Routed To Follower
136 [Arguments] ${mac_addresses} ${ip_address} ${follower_index}
137 [Documentation] Verify that IP-ADDRESS is routed to follower specified by ID
138 ${mac_address_assigned} = Collections.Get From Dictionary ${mac_addresses} ${ODL_SYSTEM_${follower_index}_IP}
139 ${mac_address_resolved} = Find Mac Address Of Ip Address ${ip_address}
140 BuiltIn.Should Not Be Empty ${mac_address_resolved}
141 BuiltIn.Should Be Equal As Strings ${mac_address_assigned} ${mac_address_resolved}
144 [Arguments] ${ip_address}=${TOOLS_SYSTEM_2_IP} ${user}=${TOOLS_SYSTEM_USER} ${passwd}=${TOOLS_SYSTEM_PASSWORD}
145 [Documentation] Shutdown Tools node to avoid conflict in resolving virtual ip that is overlaping that node.
146 ${rc} = OperatingSystem.Run And Return Rc ping -q -c 3 ${ip_address}
147 ${stdout} = BuiltIn.Run Keyword And Return If ${rc} == 0 Utils.Run Command On Remote System ${ip_address} sudo shutdown -P 0 ${user}
149 BuiltIn.Log ${stdout}
151 Create Virtual Interface
152 [Documentation] Create virtual interface on all of the cluster nodes
153 : FOR ${i} IN RANGE ${NUM_ODL_SYSTEM}
154 \ Utils.Run Command On Remote System ${ODL_SYSTEM_${i+1}_IP} sudo modprobe dummy ${ODL_SYSTEM_USER} ${ODL_SYSTEM_PASSWORD}
155 \ Utils.Run Command On Remote System ${ODL_SYSTEM_${i+1}_IP} sudo ip link set name ${VIRTUAL_INTERFACE} dev dummy0 ${ODL_SYSTEM_USER} ${ODL_SYSTEM_PASSWORD}
156 \ Utils.Run Command On Remote System And Log ${ODL_SYSTEM_${i+1}_IP} sudo ip link show ${ODL_SYSTEM_USER} ${ODL_SYSTEM_PASSWORD}
158 Delete Virtual Interface
159 [Documentation] Create virtual interface on all of the cluster nodes
160 : FOR ${i} IN RANGE ${NUM_ODL_SYSTEM}
161 \ Utils.Run Command On Remote System ${ODL_SYSTEM_${i+1}_IP} sudo ip link delete ${VIRTUAL_INTERFACE} type dummy ${ODL_SYSTEM_USER} ${ODL_SYSTEM_PASSWORD}
162 \ Utils.Run Command On Remote System ${ODL_SYSTEM_${i+1}_IP} sudo rmmod dummy ${ODL_SYSTEM_USER} ${ODL_SYSTEM_PASSWORD}
163 \ Utils.Run Command On Remote System And Log ${ODL_SYSTEM_${i+1}_IP} sudo ip link show ${ODL_SYSTEM_USER} ${ODL_SYSTEM_PASSWORD}