2 Documentation Library containing Keywords used for SXP cluster testing
4 Library RequestsLibrary
5 Resource ./ClusterManagement.robot
6 Resource ./CompareStream.robot
7 Resource ./SetupUtils.robot
8 Resource ./SxpLib.robot
11 @{SHARD_OPER_LIST} inventory topology default entity-ownership
12 @{SHARD_CONF_LIST} inventory topology default
13 @{SXP_PACKAGE} org.opendaylight.sxp
14 ${DEVICE_SESSION} device_1
15 ${CONTROLLER_SESSION} ClusterManagement__session_1
16 ${VIRTUAL_IP} ${TOOLS_SYSTEM_2_IP}
17 ${VIRTUAL_IP_MASK} 255.255.255.0
18 ${VIRTUAL_INTERFACE} dummy0
19 ${MAC_ADDRESS_TABLE} &{EMPTY}
20 ${DEVICE_NODE_ID} ${TOOLS_SYSTEM_IP}
21 ${CLUSTER_NODE_ID} ${TOOLS_SYSTEM_2_IP}
25 Setup SXP Cluster Session
26 [Documentation] Create sessions asociated with SXP cluster setup
27 ClusterManagement.ClusterManagement_Setup
28 SetupUtils.Setup_Utils_For_Setup_And_Teardown
29 SetupUtils.Setup_Logging_For_Debug_Purposes_On_List_Or_All DEBUG ${SXP_PACKAGE}
32 [Documentation] Create session on the SXP device
33 RequestsLibrary.Create Session ${DEVICE_SESSION} url=http://${DEVICE_NODE_ID}:${RESTCONFPORT} auth=${AUTH} timeout=${DEFAULT_TIMEOUT_HTTP} max_retries=0
35 Setup SXP Cluster Session With Device
36 [Documentation] Create sessions asociated with SXP cluster setup and one SXP device
37 Setup SXP Cluster Session
40 Clean SXP Cluster Session
41 [Documentation] Clean sessions asociated with SXP cluster setup
42 ClusterManagement.Flush_Iptables_From_List_Or_All
43 BuiltIn.Wait Until Keyword Succeeds 60x 1s ClusterManagement.Verify_Members_Are_Ready member_index_list=${EMPTY} verify_cluster_sync=True verify_restconf=True
44 ... verify_system_status=False service_list=@{EMPTY}
45 RequestsLibrary.Delete All Sessions
46 SetupUtils.Setup_Logging_For_Debug_Purposes_On_List_Or_All INFO ${SXP_PACKAGE}
49 [Documentation] Check Status for all shards in SXP application.
50 ClusterManagement.Check_Cluster_Is_In_Sync
51 CompareStream.Run_Keyword_If_At_Least_Phosphorus Collections.Remove Values From List ${SHARD_OPER_LIST} entity-ownership
52 Log ${SHARD_OPER_LIST}
53 ClusterManagement.Verify_Leader_Exists_For_Each_Shard shard_name_list=${SHARD_OPER_LIST} shard_type=operational
54 ClusterManagement.Verify_Leader_Exists_For_Each_Shard shard_name_list=${SHARD_CONF_LIST} shard_type=config
57 [Arguments] ${peer_mode}=listener
58 [Documentation] Setup and connect SXP cluster topology
59 SxpLib.Add Node ${DEVICE_NODE_ID} session=${DEVICE_SESSION}
60 BuiltIn.Wait Until Keyword Succeeds 240x 1s SxpLib.Check Node Started ${DEVICE_NODE_ID} session=${DEVICE_SESSION}
61 FOR ${i} IN RANGE ${NUM_ODL_SYSTEM}
62 SxpLib.Add Connection version4 ${peer_mode} ${ODL_SYSTEM_${i+1}_IP} 64999 node=${DEVICE_NODE_ID}
63 ... session=${DEVICE_SESSION}
65 ${cluster_mode} = Sxp.Get Opposing Mode ${peer_mode}
66 SxpLib.Add Node ${INADDR_ANY} session=${CONTROLLER_SESSION}
67 BuiltIn.Wait Until Keyword Succeeds 240x 1s Check Cluster Node Started ${INADDR_ANY} ip=${EMPTY}
68 SxpLib.Add Connection version4 ${cluster_mode} ${DEVICE_NODE_ID} 64999 ${INADDR_ANY} session=${CONTROLLER_SESSION}
69 BuiltIn.Wait Until Keyword Succeeds 480x 1s Check Device is Connected ${DEVICE_NODE_ID} session=${DEVICE_SESSION}
72 [Documentation] Disconnect SXP cluster topology
73 SxpLib.Delete Node ${DEVICE_NODE_ID} session=${DEVICE_SESSION}
74 BuiltIn.Wait Until Keyword Succeeds 240x 1s SxpLib.Check Node Stopped ${DEVICE_NODE_ID} session=${DEVICE_SESSION}
75 BuiltIn.Wait Until Keyword Succeeds 60x 1s SxpLib.Delete Node ${INADDR_ANY} session=${CONTROLLER_SESSION}
76 BuiltIn.Wait Until Keyword Succeeds 240x 1s SxpClusterLib.Check Cluster Node Stopped ${INADDR_ANY} ip=${EMPTY}
78 Check Cluster Node Started
79 [Arguments] ${node} ${port}=64999 ${ip}=${node}
80 [Documentation] Verify that SxpNode has data written to Operational datastore and Node is running on one of cluster nodes
81 ${resp} = RequestsLibrary.Get Request ${CONTROLLER_SESSION} /restconf/operational/network-topology:network-topology/topology/sxp/node/${node}/
82 BuiltIn.Should Be Equal As Strings ${resp.status_code} 200
83 ${started} = BuiltIn.Set Variable ${False}
84 FOR ${i} IN RANGE ${NUM_ODL_SYSTEM}
85 ${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}
86 ... prompt=${ODL_SYSTEM_PROMPT}
87 ${started} = BuiltIn.Set Variable If '${rc}' == '0' ${True} ${started}
89 BuiltIn.Should Be True ${started}
91 Check Cluster Node Stopped
92 [Arguments] ${node} ${port}=64999 ${ip}=${node}
93 [Documentation] Verify that SxpNode has data removed from Operational datastore and Node is stopped
94 ${resp} = RequestsLibrary.Get Request ${CONTROLLER_SESSION} /restconf/operational/network-topology:network-topology/topology/sxp/node/${node}/
95 BuiltIn.Should Be Equal As Strings ${resp.status_code} 404
96 ${stopped} = BuiltIn.Set Variable ${False}
97 FOR ${i} IN RANGE ${NUM_ODL_SYSTEM}
98 ${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}
99 ... prompt=${ODL_SYSTEM_PROMPT}
100 ${stopped} = BuiltIn.Set Variable If '${rc}' == '1' ${True} ${stopped}
102 BuiltIn.Should Be True ${stopped}
104 Check Device is Connected
105 [Arguments] ${node} ${version}=version4 ${port}=64999 ${session}=session
106 [Documentation] Checks if SXP device is connected to the cluster. It means it has connection in state "on" with one of the cluster members.
107 ${resp} = SxpLib.Get Connections node=${node} session=${session}
108 ${is_connected} = BuiltIn.Set Variable ${False}
109 FOR ${i} IN RANGE ${NUM_ODL_SYSTEM}
110 ${is_connected} = Sxp.Find Connection ${resp} ${version} any ${ODL_SYSTEM_${i+1}_IP}
112 BuiltIn.Exit For Loop If ${is_connected}
114 BuiltIn.Should Be True ${is_connected}
116 Check Cluster is Connected
117 [Arguments] ${node} ${version}=version4 ${port}=64999 ${mode}=speaker ${session}=session
118 [Documentation] Get SXP connections of cluster ${node} and verify that they contain a connection to the device ${DEVICE_NODE_ID} in state "on"
119 ${resp} = SxpLib.Get Connections node=${node} session=${session}
120 SxpLib.Should Contain Connection ${resp} ${DEVICE_NODE_ID} ${port} ${mode} ${version} on
123 [Arguments] ${running_member}=1
124 [Documentation] Find cluster controller that is marked as cluster owner by requesting ownership data from ${running_member} node of the cluster
125 ${owner} ${candidates} = BuiltIn.Wait Until Keyword Succeeds 60x 1s ClusterManagement.Get_Owner_And_Successors_For_Device org.opendaylight.sxp.controller.boot.SxpControllerInstance
126 ... Sxp ${running_member}
129 Get Not Owner Controller
130 [Documentation] Find cluster controller that is not marked as owner for SXP service in cluster
131 ${owner_controller} = Get Owner Controller
132 ${controller} = BuiltIn.Evaluate random.choice( filter( lambda i: i!=${owner_controller}, range(1, ${NUM_ODL_SYSTEM} + 1))) random
133 [Return] ${controller}
136 [Documentation] Get any controller from cluster range
137 ${follower} = BuiltIn.Evaluate random.choice( range(1, ${NUM_ODL_SYSTEM} + 1)) random
140 Map Followers To Mac Addresses
141 [Documentation] Creates Map containing ODL_SYSTEM_IP to corresponding MAC-ADDRESS
142 ${mac_addresses} = BuiltIn.Create dictionary
143 FOR ${i} IN RANGE ${NUM_ODL_SYSTEM}
144 ${mac_address} Find Mac Address Of Ip Address ${ODL_SYSTEM_${i+1}_IP}
145 Collections.Set To Dictionary ${mac_addresses} ${ODL_SYSTEM_${i+1}_IP} ${mac_address}
147 BuiltIn.Log ${mac_addresses}
148 [Return] ${mac_addresses}
150 Find Mac Address Of Ip Address
152 [Documentation] Finds out MAC-ADDRESS of specified IP by pinging it from TOOLS_SYSTEM machine
153 ${mac_address} = Utils.Run Command On Remote System And Log ${TOOLS_SYSTEM_IP} ping -c 10 -W 10 ${ip} >/dev/null && sudo ip neighbor show ${ip} | awk '{print $5}' ${TOOLS_SYSTEM_USER} ${TOOLS_SYSTEM_PASSWORD}
154 [Return] ${mac_address}
156 Ip Addres Should Not Be Routed To Follower
157 [Arguments] ${mac_addresses} ${ip_address} ${follower_index}
158 [Documentation] Verify that IP-ADDRESS is not routed to follower specified by ID
159 ${mac_address_assigned} = Collections.Get From Dictionary ${mac_addresses} ${ODL_SYSTEM_${follower_index}_IP}
160 ${mac_address_resolved} = Find Mac Address Of Ip Address ${ip_address}
161 BuiltIn.Should Not Be Equal As Strings ${mac_address_assigned} ${mac_address_resolved}
163 Ip Addres Should Be Routed To Follower
164 [Arguments] ${mac_addresses} ${ip_address} ${follower_index}
165 [Documentation] Verify that IP-ADDRESS is routed to follower specified by ID
166 ${mac_address_assigned} = Collections.Get From Dictionary ${mac_addresses} ${ODL_SYSTEM_${follower_index}_IP}
167 ${mac_address_resolved} = Find Mac Address Of Ip Address ${ip_address}
168 BuiltIn.Should Not Be Empty ${mac_address_resolved}
169 BuiltIn.Should Be Equal As Strings ${mac_address_assigned} ${mac_address_resolved}
172 [Arguments] ${ip_address}=${TOOLS_SYSTEM_2_IP} ${user}=${TOOLS_SYSTEM_USER} ${passwd}=${TOOLS_SYSTEM_PASSWORD}
173 [Documentation] Shutdown Tools node to avoid conflict in resolving virtual ip that is overlaping that node.
174 ${rc} = OperatingSystem.Run And Return Rc ping -q -c 3 ${ip_address}
175 ${stdout} = BuiltIn.Run Keyword And Return If ${rc} == 0 Utils.Run Command On Remote System ${ip_address} sudo shutdown -P 0 ${user}
177 BuiltIn.Log ${stdout}
179 Create Virtual Interface
180 [Documentation] Create virtual interface on all of the cluster nodes
181 FOR ${i} IN RANGE ${NUM_ODL_SYSTEM}
182 Utils.Run Command On Remote System ${ODL_SYSTEM_${i+1}_IP} sudo modprobe dummy ${ODL_SYSTEM_USER} ${ODL_SYSTEM_PASSWORD}
183 Utils.Run Command On Remote System And Log ${ODL_SYSTEM_${i+1}_IP} sudo ip link show ${ODL_SYSTEM_USER} ${ODL_SYSTEM_PASSWORD}
186 Delete Virtual Interface
187 [Documentation] Create virtual interface on all of the cluster nodes
188 FOR ${i} IN RANGE ${NUM_ODL_SYSTEM}
189 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}
190 Utils.Run Command On Remote System ${ODL_SYSTEM_${i+1}_IP} sudo rmmod dummy ${ODL_SYSTEM_USER} ${ODL_SYSTEM_PASSWORD}
191 Utils.Run Command On Remote System And Log ${ODL_SYSTEM_${i+1}_IP} sudo ip link show ${ODL_SYSTEM_USER} ${ODL_SYSTEM_PASSWORD}