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
15 ${VIRTUAL_IP} ${TOOLS_SYSTEM_2_IP}
16 ${VIRTUAL_IP_MASK} 255.255.255.0
17 ${VIRTUAL_INTERFACE} dummy0
18 ${MAC_ADDRESS_TABLE} &{EMPTY}
19 ${DEVICE_NODE_ID} ${TOOLS_SYSTEM_IP}
20 ${CLUSTER_NODE_ID} ${TOOLS_SYSTEM_2_IP}
24 Setup SXP Cluster Session
25 [Documentation] Create sessions asociated with SXP cluster setup
26 ClusterManagement.ClusterManagement_Setup
27 SetupUtils.Setup_Utils_For_Setup_And_Teardown
28 SetupUtils.Setup_Logging_For_Debug_Purposes_On_List_Or_All ${SXP_LOG_LEVEL} ${SXP_PACKAGE}
31 [Documentation] Create session on the SXP device
32 RequestsLibrary.Create Session ${DEVICE_SESSION} url=http://${DEVICE_NODE_ID}:${RESTCONFPORT} auth=${AUTH} timeout=${DEFAULT_TIMEOUT_HTTP} max_retries=0
34 Setup SXP Cluster Session With Device
35 [Documentation] Create sessions asociated with SXP cluster setup and one SXP device
36 Setup SXP Cluster Session
39 Clean SXP Cluster Session
40 [Documentation] Clean sessions asociated with SXP cluster setup
41 ClusterManagement.Flush_Iptables_From_List_Or_All
42 RequestsLibrary.Delete All Sessions
43 SetupUtils.Setup_Logging_For_Debug_Purposes_On_List_Or_All INFO ${SXP_PACKAGE}
46 [Documentation] Check Status for all shards in SXP application.
47 ClusterManagement.Check_Cluster_Is_In_Sync
48 ClusterManagement.Verify_Leader_Exists_For_Each_Shard shard_name_list=${SHARD_OPER_LIST} shard_type=operational
49 ClusterManagement.Verify_Leader_Exists_For_Each_Shard shard_name_list=${SHARD_CONF_LIST} shard_type=config
52 [Arguments] ${peer_mode}=listener
53 [Documentation] Setup and connect SXP cluster topology
54 SxpLib.Add Node ${DEVICE_NODE_ID} session=${DEVICE_SESSION}
55 : FOR ${i} IN RANGE ${NUM_ODL_SYSTEM}
56 \ SxpLib.Add Connection version4 ${peer_mode} ${ODL_SYSTEM_${i+1}_IP} 64999 node=${DEVICE_NODE_ID}
57 \ ... session=${DEVICE_SESSION}
58 ${cluster_mode} = Sxp.Get Opposing Mode ${peer_mode}
59 SxpLib.Add Node ${INADDR_ANY} session=${CONTROLLER_SESSION}
60 SxpLib.Add Connection version4 ${cluster_mode} ${DEVICE_NODE_ID} 64999 ${INADDR_ANY} session=${CONTROLLER_SESSION}
61 BuiltIn.Wait Until Keyword Succeeds 12x 10s SxpLib.Check Node Started ${DEVICE_NODE_ID} session=${DEVICE_SESSION}
62 BuiltIn.Wait Until Keyword Succeeds 12x 10s Check Cluster Node started ${INADDR_ANY} ip=${EMPTY}
63 BuiltIn.Wait Until Keyword Succeeds 48x 10s Check Device is Connected ${DEVICE_NODE_ID} session=${DEVICE_SESSION}
66 [Documentation] Disconnect SXP cluster topology
67 SxpLib.Delete Node ${DEVICE_NODE_ID} session=${DEVICE_SESSION}
68 BuiltIn.Wait Until Keyword Succeeds 3x 10s SxpLib.Delete Node ${INADDR_ANY} session=${CONTROLLER_SESSION}
70 Check Cluster Node started
71 [Arguments] ${node} ${port}=64999 ${ip}=${node}
72 [Documentation] Verify that SxpNode has data written to Operational datastore and Node is running on one of cluster nodes
73 ${started} = BuiltIn.Set Variable ${False}
74 : FOR ${i} IN RANGE ${NUM_ODL_SYSTEM}
75 \ ${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}
76 \ ... prompt=${ODL_SYSTEM_PROMPT}
77 \ ${started} = BuiltIn.Set Variable If '${rc}' == '0' ${True} ${started}
78 BuiltIn.Should Be True ${started}
80 Check Cluster Node stopped
81 [Arguments] ${node} ${port}=64999 ${ip}=${node}
82 [Documentation] Verify that SxpNode has data removed from Operational datastore and Node is stopped
83 ${stopped} = 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 \ ${stopped} = BuiltIn.Set Variable If '${rc}' == '1' ${True} ${stopped}
88 BuiltIn.Should Be True ${stopped}
90 Check Device is Connected
91 [Arguments] ${node} ${version}=version4 ${port}=64999 ${session}=session
92 [Documentation] Checks if SXP device is connected to the cluster. It means it has connection in state "on" with one of the cluster members.
93 ${resp} = SxpLib.Get Connections node=${node} session=${session}
94 ${is_connected} = BuiltIn.Set Variable ${False}
95 : FOR ${i} IN RANGE ${NUM_ODL_SYSTEM}
96 \ ${is_connected} = Sxp.Find Connection ${resp} ${version} any ${ODL_SYSTEM_${i+1}_IP}
98 \ BuiltIn.Exit For Loop If ${is_connected}
99 BuiltIn.Should Be True ${is_connected}
101 Check Cluster is Connected
102 [Arguments] ${node} ${version}=version4 ${port}=64999 ${mode}=speaker ${session}=session
103 [Documentation] Get SXP connections of cluster ${node} and verify that they contain a connection to the device ${DEVICE_NODE_ID} in state "on"
104 ${resp} = SxpLib.Get Connections node=${node} session=${session}
105 SxpLib.Should Contain Connection ${resp} ${DEVICE_NODE_ID} ${port} ${mode} ${version} on
108 [Arguments] ${running_member}=1
109 [Documentation] Find cluster controller that is marked as cluster owner by requesting ownership data from ${running_member} node of the cluster
110 ${owner} ${candidates} = BuiltIn.Wait Until Keyword Succeeds 5x 2s ClusterManagement.Get_Owner_And_Successors_For_Device org.opendaylight.sxp.controller.boot.SxpControllerInstance
111 ... Sxp ${running_member}
114 Get Not Owner Controller
115 [Documentation] Find cluster controller that is not marked as owner for SXP service in cluster
116 ${owner_controller} = Get Owner Controller
117 ${controller} = BuiltIn.Evaluate random.choice( filter( lambda i: i!=${owner_controller}, range(1, ${NUM_ODL_SYSTEM} + 1))) random
118 [Return] ${controller}
121 [Documentation] Get any controller from cluster range
122 ${follower} = BuiltIn.Evaluate random.choice( range(1, ${NUM_ODL_SYSTEM} + 1)) random
125 Map Followers To Mac Addresses
126 [Documentation] Creates Map containing ODL_SYSTEM_IP to corresponding MAC-ADDRESS
127 ${mac_addresses} = BuiltIn.Create dictionary
128 : FOR ${i} IN RANGE ${NUM_ODL_SYSTEM}
129 \ ${mac_address} Find Mac Address Of Ip Address ${ODL_SYSTEM_${i+1}_IP}
130 \ Collections.Set To Dictionary ${mac_addresses} ${ODL_SYSTEM_${i+1}_IP} ${mac_address}
131 BuiltIn.Log ${mac_addresses}
132 [Return] ${mac_addresses}
134 Find Mac Address Of Ip Address
136 [Documentation] Finds out MAC-ADDRESS of specified IP by pinging it from TOOLS_SYSTEM machine
137 ${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}
138 [Return] ${mac_address}
140 Ip Addres Should Not Be Routed To Follower
141 [Arguments] ${mac_addresses} ${ip_address} ${follower_index}
142 [Documentation] Verify that IP-ADDRESS is not routed to follower specified by ID
143 ${mac_address_assigned} = Collections.Get From Dictionary ${mac_addresses} ${ODL_SYSTEM_${follower_index}_IP}
144 ${mac_address_resolved} = Find Mac Address Of Ip Address ${ip_address}
145 BuiltIn.Should Not Be Equal As Strings ${mac_address_assigned} ${mac_address_resolved}
147 Ip Addres Should Be Routed To Follower
148 [Arguments] ${mac_addresses} ${ip_address} ${follower_index}
149 [Documentation] Verify that IP-ADDRESS is routed to follower specified by ID
150 ${mac_address_assigned} = Collections.Get From Dictionary ${mac_addresses} ${ODL_SYSTEM_${follower_index}_IP}
151 ${mac_address_resolved} = Find Mac Address Of Ip Address ${ip_address}
152 BuiltIn.Should Not Be Empty ${mac_address_resolved}
153 BuiltIn.Should Be Equal As Strings ${mac_address_assigned} ${mac_address_resolved}
156 [Arguments] ${ip_address}=${TOOLS_SYSTEM_2_IP} ${user}=${TOOLS_SYSTEM_USER} ${passwd}=${TOOLS_SYSTEM_PASSWORD}
157 [Documentation] Shutdown Tools node to avoid conflict in resolving virtual ip that is overlaping that node.
158 ${rc} = OperatingSystem.Run And Return Rc ping -q -c 3 ${ip_address}
159 ${stdout} = BuiltIn.Run Keyword And Return If ${rc} == 0 Utils.Run Command On Remote System ${ip_address} sudo shutdown -P 0 ${user}
161 BuiltIn.Log ${stdout}
163 Create Virtual Interface
164 [Documentation] Create virtual interface on all of the cluster nodes
165 : FOR ${i} IN RANGE ${NUM_ODL_SYSTEM}
166 \ Utils.Run Command On Remote System ${ODL_SYSTEM_${i+1}_IP} sudo modprobe dummy ${ODL_SYSTEM_USER} ${ODL_SYSTEM_PASSWORD}
167 \ Utils.Run Command On Remote System And Log ${ODL_SYSTEM_${i+1}_IP} sudo ip link show ${ODL_SYSTEM_USER} ${ODL_SYSTEM_PASSWORD}
169 Delete Virtual Interface
170 [Documentation] Create virtual interface on all of the cluster nodes
171 : FOR ${i} IN RANGE ${NUM_ODL_SYSTEM}
172 \ 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}
173 \ Utils.Run Command On Remote System ${ODL_SYSTEM_${i+1}_IP} sudo rmmod dummy ${ODL_SYSTEM_USER} ${ODL_SYSTEM_PASSWORD}
174 \ Utils.Run Command On Remote System And Log ${ODL_SYSTEM_${i+1}_IP} sudo ip link show ${ODL_SYSTEM_USER} ${ODL_SYSTEM_PASSWORD}