2 Documentation Library containing Keywords used for SXP cluster testing
3 Library RequestsLibrary
5 Resource ./SxpLib.robot
6 Resource ./ClusterManagement.robot
7 Variables ../variables/Variables.py
10 ${DEVICE_SESSION} device_1
11 ${DEVICE_NODE_ID} 1.1.1.1
12 ${CLUSTER_NODE_ID} 2.2.2.2
15 Setup SXP Cluster Session
16 [Documentation] Create sessions asociated with SXP cluster setup
17 Setup SXP Session ${DEVICE_SESSION} ${TOOLS_SYSTEM_IP}
18 : FOR ${i} IN RANGE ${NUM_ODL_SYSTEM}
19 \ Setup SXP Session controller${i+1} ${ODL_SYSTEM_${i+1}_IP}
20 ClusterManagement_Setup
22 Clean SXP Cluster Session
23 [Documentation] Clean sessions asociated with SXP cluster setup
24 Flush_Iptables_From_List_Or_All
25 : FOR ${i} IN RANGE ${NUM_ODL_SYSTEM}
26 \ Wait Until Keyword Succeeds 240 1 Sync_Status_Should_Be_True ${i+1}
30 [Arguments] ${peer_mode}=listener
31 [Documentation] Setup and connect SXP cluster topology
32 Add Node ${DEVICE_NODE_ID} ip=0.0.0.0 session=${DEVICE_SESSION}
33 Wait Until Keyword Succeeds 20 1 Check Node Started ${DEVICE_NODE_ID} session=${DEVICE_SESSION} system=${TOOLS_SYSTEM_IP}
35 ${cluster_mode} Get Opposing Mode ${peer_mode}
36 : FOR ${i} IN RANGE ${NUM_ODL_SYSTEM}
37 \ Add Connection version4 ${peer_mode} ${ODL_SYSTEM_${i+1}_IP} 64999 ${DEVICE_NODE_ID}
38 \ ... session=${DEVICE_SESSION}
39 ${controller_id} Get Any Controller
40 Add Node ${CLUSTER_NODE_ID} ip=0.0.0.0 session=controller${controller_id}
41 Wait Until Keyword Succeeds 20 1 Check Cluster Node started ${CLUSTER_NODE_ID}
42 Add Connection version4 ${cluster_mode} ${TOOLS_SYSTEM_IP} 64999 ${CLUSTER_NODE_ID} session=controller${controller_id}
43 Wait Until Keyword Succeeds 120 1 Check Device is Connected ${DEVICE_NODE_ID} session=${DEVICE_SESSION}
46 [Documentation] Disconnect SXP cluster topology
47 Flush_Iptables_From_List_Or_All
48 : FOR ${i} IN RANGE ${NUM_ODL_SYSTEM}
49 \ Wait Until Keyword Succeeds 240 1 Sync_Status_Should_Be_True ${i+1}
50 ${controller_index} Get Active Controller
51 Delete Node ${DEVICE_NODE_ID} session=${DEVICE_SESSION}
52 Delete Node ${CLUSTER_NODE_ID} session=controller${controller_index}
54 Check Cluster Node started
55 [Arguments] ${node} ${port}=64999 ${ip}=${EMPTY}
56 [Documentation] Verify that SxpNode has data written to Operational datastore and Node is running on one of cluster nodes
57 ${started} Set Variable ${False}
58 : FOR ${i} IN RANGE ${NUM_ODL_SYSTEM}
59 \ ${rc} 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}
60 \ ... prompt=${ODL_SYSTEM_PROMPT}
61 \ ${started} Set Variable If '${rc}' == '0' ${True} ${started}
62 Should Be True ${started}
64 Check Device is Connected
65 [Arguments] ${node} ${version}=version4 ${port}=64999 ${session}=session
66 [Documentation] Checks if SXP device is connected to at least one cluster node
67 ${is_connected} Set Variable ${False}
68 ${resp} Get Connections node=${node} session=${session}
69 : FOR ${i} IN RANGE ${NUM_ODL_SYSTEM}
70 \ ${follower} Find Connection ${resp} ${version} any ${ODL_SYSTEM_${i+1}_IP}
72 \ ${is_connected} Run Keyword If ${follower} Set Variable ${True}
73 \ ... ELSE Set Variable ${is_connected}
74 Should Be True ${is_connected}
77 [Arguments] ${port}=64999 ${ip}=${EMPTY}
78 [Documentation] Find cluster controller that is actively connected to SXP device
79 ${controller} Set Variable ${EMPTY}
80 : FOR ${i} IN RANGE ${NUM_ODL_SYSTEM}
81 \ ${rc} 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}
82 \ ... prompt=${ODL_SYSTEM_PROMPT}
83 \ ${controller} Set Variable If '${rc}' == '0' ${i+1} ${controller}
84 [Return] ${controller}
86 Get Inactive Controller
87 [Arguments] ${port}=64999 ${ip}=${EMPTY}
88 [Documentation] Find cluster controller that is not actively connected to SXP device
89 @{controllers} Create List
90 : FOR ${i} IN RANGE ${NUM_ODL_SYSTEM}
91 \ ${rc} 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}
92 \ ... prompt=${ODL_SYSTEM_PROMPT}
93 \ Run Keyword If '${rc}' != '0' Append To List ${controllers} ${i+1}
95 ${controller} Evaluate random.choice( ${controllers}) random
96 [Return] ${controller}
99 [Documentation] Get any controller from cluster range
100 ${follower} Evaluate random.choice( range(1, ${NUM_ODL_SYSTEM} + 1)) random