2 Documentation Library containing Keywords used for SXP cluster testing
3 Library RequestsLibrary
5 Resource ./SxpLib.robot
6 Resource ./ClusterManagement.robot
7 Resource ./SetupUtils.robot
8 Resource ../variables/Variables.robot
11 @{SHARD_OPER_LIST} inventory topology default entity-ownership
12 @{SHARD_CONF_LIST} inventory topology default
13 ${DEVICE_SESSION} device_1
14 ${DEVICE_NODE_ID} 1.1.1.1
15 ${CLUSTER_NODE_ID} 2.2.2.2
17 @{SXP_PACKAGE} org.opendaylight.sxp
20 Setup SXP Cluster Session
21 [Documentation] Create sessions asociated with SXP cluster setup
22 BuiltIn.Wait Until Keyword Succeeds 120 10 SxpLib.Prepare SSH Keys On Karaf ${TOOLS_SYSTEM_IP} ${TOOLS_SYSTEM_USER} ${TOOLS_SYSTEM_PASSWORD}
23 ... ${TOOLS_SYSTEM_PROMPT} /tmp
24 SxpLib.Setup SXP Session ${DEVICE_SESSION} ${TOOLS_SYSTEM_IP}
25 : FOR ${i} IN RANGE ${NUM_ODL_SYSTEM}
26 \ BuiltIn.Wait Until Keyword Succeeds 120 10 SxpLib.Prepare SSH Keys On Karaf ${ODL_SYSTEM_${i+1}_IP}
27 \ SxpLib.Setup SXP Session controller${i+1} ${ODL_SYSTEM_${i+1}_IP}
28 ClusterManagement.ClusterManagement_Setup
29 SetupUtils.Setup_Utils_For_Setup_And_Teardown
30 SetupUtils.Setup_Logging_For_Debug_Purposes_On_List_Or_All ${SXP_LOG_LEVEL} ${SXP_PACKAGE}
32 Clean SXP Cluster Session
33 [Documentation] Clean sessions asociated with SXP cluster setup
34 ClusterManagement.Flush_Iptables_From_List_Or_All
35 : FOR ${i} IN RANGE ${NUM_ODL_SYSTEM}
36 \ BuiltIn.Wait Until Keyword Succeeds 240 1 ClusterManagement.Sync_Status_Should_Be_True ${i+1}
37 SxpLib.Clean SXP Session
38 SetupUtils.Setup_Logging_For_Debug_Purposes_On_List_Or_All INFO ${SXP_PACKAGE}
41 [Documentation] Check Status for all shards in SXP application.
42 ClusterManagement.Check_Cluster_Is_In_Sync
43 ClusterManagement.Verify_Leader_Exists_For_Each_Shard shard_name_list=${SHARD_OPER_LIST} shard_type=operational
44 ClusterManagement.Verify_Leader_Exists_For_Each_Shard shard_name_list=${SHARD_CONF_LIST} shard_type=config
47 [Arguments] ${peer_mode}=listener
48 [Documentation] Setup and connect SXP cluster topology
49 SxpLib.Add Node ${DEVICE_NODE_ID} ip=0.0.0.0 session=${DEVICE_SESSION}
50 BuiltIn.Wait Until Keyword Succeeds 20 1 SxpLib.Check Node Started ${DEVICE_NODE_ID} session=${DEVICE_SESSION} system=${TOOLS_SYSTEM_IP}
52 ${cluster_mode} Sxp.Get Opposing Mode ${peer_mode}
53 : FOR ${i} IN RANGE ${NUM_ODL_SYSTEM}
54 \ SxpLib.Add Connection version4 ${peer_mode} ${ODL_SYSTEM_${i+1}_IP} 64999 ${DEVICE_NODE_ID}
55 \ ... session=${DEVICE_SESSION}
56 ${controller_id} Get Any Controller
57 SxpLib.Add Node ${CLUSTER_NODE_ID} ip=0.0.0.0 session=controller${controller_id}
58 BuiltIn.Wait Until Keyword Succeeds 20 1 Check Cluster Node started ${CLUSTER_NODE_ID}
59 SxpLib.Add Connection version4 ${cluster_mode} ${TOOLS_SYSTEM_IP} 64999 ${CLUSTER_NODE_ID} session=controller${controller_id}
60 BuiltIn.Wait Until Keyword Succeeds 120 1 Check Device is Connected ${DEVICE_NODE_ID} session=${DEVICE_SESSION}
63 [Documentation] Disconnect SXP cluster topology
64 ClusterManagement.Flush_Iptables_From_List_Or_All
65 : FOR ${i} IN RANGE ${NUM_ODL_SYSTEM}
66 \ BuiltIn.Wait Until Keyword Succeeds 240 1 ClusterManagement.Sync_Status_Should_Be_True ${i+1}
67 ${controller_index} Get Active Controller
68 SxpLib.Delete Node ${DEVICE_NODE_ID} session=${DEVICE_SESSION}
69 SxpLib.Delete Node ${CLUSTER_NODE_ID} session=controller${controller_index}
71 Check Cluster Node started
72 [Arguments] ${node} ${port}=64999 ${ip}=${EMPTY}
73 [Documentation] Verify that SxpNode has data written to Operational datastore and Node is running on one of cluster nodes
74 ${started} BuiltIn.Set Variable ${False}
75 : FOR ${i} IN RANGE ${NUM_ODL_SYSTEM}
76 \ ${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}
77 \ ... prompt=${ODL_SYSTEM_PROMPT}
78 \ ${started} BuiltIn.Set Variable If '${rc}' == '0' ${True} ${started}
79 BuiltIn.Should Be True ${started}
81 Check Device is Connected
82 [Arguments] ${node} ${version}=version4 ${port}=64999 ${session}=session
83 [Documentation] Checks if SXP device is connected to at least one cluster node
84 ${is_connected} BuiltIn.Set Variable ${False}
85 ${resp} SxpLib.Get Connections node=${node} session=${session}
86 : FOR ${i} IN RANGE ${NUM_ODL_SYSTEM}
87 \ ${follower} Sxp.Find Connection ${resp} ${version} any ${ODL_SYSTEM_${i+1}_IP}
89 \ ${is_connected} BuiltIn.Run Keyword If ${follower} BuiltIn.Set Variable ${True}
90 \ ... ELSE BuiltIn.Set Variable ${is_connected}
91 BuiltIn.Should Be True ${is_connected}
93 Check Cluster is Connected
94 [Arguments] ${node} ${version}=version4 ${port}=64999 ${mode}=speaker ${session}=session
95 [Documentation] Checks if SXP device is connected to at least one cluster node
96 ${resp} SxpLib.Get Connections node=${node} session=${session}
97 SxpLib.Should Contain Connection ${resp} ${TOOLS_SYSTEM_IP} ${port} ${mode} ${version}
100 [Documentation] Find cluster controller that is marked as leader for SXP service in cluster
101 @{votes} BuiltIn.Create List
102 : FOR ${i} IN RANGE ${NUM_ODL_SYSTEM}
103 \ ${resp} RequestsLibrary.Get Request controller${i+1} /restconf/operational/entity-owners:entity-owners
104 \ BuiltIn.Continue For Loop If ${resp.status_code} != 200
105 \ ${controller} Sxp.Get Active Controller From Json ${resp.content} SxpControllerInstance
106 \ Collections.Append To List ${votes} ${controller}
107 ${length} BuiltIn.Get Length ${votes}
108 BuiltIn.Should Not Be Equal As Integers ${length} 0
109 ${active_controller} BuiltIn.Evaluate collections.Counter(${votes}).most_common(1)[0][0] collections
110 [Return] ${active_controller}
112 Get Inactive Controller
113 [Documentation] Find cluster controller that is not marked as leader for SXP service in cluster
114 ${active_controller} Get Active Controller
115 ${controller} BuiltIn.Evaluate random.choice( filter( lambda i: i!=${active_controller}, range(1, ${NUM_ODL_SYSTEM} + 1))) random
116 [Return] ${controller}
119 [Documentation] Get any controller from cluster range
120 ${follower} BuiltIn.Evaluate random.choice( range(1, ${NUM_ODL_SYSTEM} + 1)) random
123 Map Followers To Mac Addresses
124 [Documentation] Creates Map containing ODL_SYSTEM_IP to corresponding MAC-ADDRESS
125 ${mac_addresses} BuiltIn.Create dictionary
126 : FOR ${i} IN RANGE ${NUM_ODL_SYSTEM}
127 \ ${mac_address} Find Mac Address Of Ip Address ${ODL_SYSTEM_${i+1}_IP}
128 \ Collections.Set To Dictionary ${mac_addresses} ${ODL_SYSTEM_${i+1}_IP} ${mac_address}
129 BuiltIn.Log ${mac_addresses}
130 [Return] ${mac_addresses}
132 Find Mac Address Of Ip Address
134 [Documentation] Finds out MAC-ADDRESS of specified IP by pinging it from TOOLS_SYSTEM machine
135 ${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}
136 [Return] ${mac_address}
138 Ip Addres Should Not Be Routed To Follower
139 [Arguments] ${mac_addresses} ${ip_address} ${follower_index}
140 [Documentation] Verify that IP-ADDRESS is not routed to follower specified by ID
141 ${mac_address_assigned} Collections.Get From Dictionary ${mac_addresses} ${ODL_SYSTEM_${follower_index}_IP}
142 ${mac_address_resolved} Find Mac Address Of Ip Address ${ip_address}
143 BuiltIn.Should Not Be Equal As Strings ${mac_address_assigned} ${mac_address_resolved}
145 Ip Addres Should Be Routed To Follower
146 [Arguments] ${mac_addresses} ${ip_address} ${follower_index}
147 [Documentation] Verify that IP-ADDRESS is routed to follower specified by ID
148 ${mac_address_assigned} Collections.Get From Dictionary ${mac_addresses} ${ODL_SYSTEM_${follower_index}_IP}
149 ${mac_address_resolved} Find Mac Address Of Ip Address ${ip_address}
150 BuiltIn.Should Not Be Empty ${mac_address_resolved}
151 BuiltIn.Should Be Equal As Strings ${mac_address_assigned} ${mac_address_resolved}
154 [Arguments] ${ip_address}=${TOOLS_SYSTEM_2_IP} ${user}=${TOOLS_SYSTEM_USER} ${passwd}=${TOOLS_SYSTEM_PASSWORD}
155 [Documentation] Shutdown Tools node to avoid conflict in resolving virtual ip that is overlaping that node.
156 ${rc} OperatingSystem.Run And Return Rc ping -q -c 3 ${ip_address}
157 ${stdout} BuiltIn.Run Keyword And Return If ${rc} == 0 Utils.Run Command On Remote System ${ip_address} sudo shutdown -P 0 ${user}
159 BuiltIn.Log ${stdout}