Migrate SXP controller check to jolokia 64/48764/3
authorMartin Mihálek <mamihale@cisco.com>
Tue, 29 Nov 2016 08:47:27 +0000 (09:47 +0100)
committerMartin Mihálek <mamihale@cisco.com>
Tue, 29 Nov 2016 08:57:30 +0000 (08:57 +0000)
Update checking of active SXP sevice from SSH to request.

Change-Id: I1786caf944f5679b4c6ecb7766093d19868b1d88
Signed-off-by: Martin Mihálek <mamihale@cisco.com>
csit/libraries/Sxp.py
csit/libraries/SxpClusterLib.robot

index 3b9b0f50842150a79f4f7be80edd0d66f2bcea4f..720871e581c03abc635ff2814d873f9ae661c041 100644 (file)
@@ -3,6 +3,24 @@ from netaddr import IPAddress
 from string import Template
 
 
+def get_active_controller_from_json(resp, service):
+    """Gets index of active controller running specified service
+
+    :param resp: JSON formatted response from EOS
+    :type resp: string
+    :param service: EOS Service to look for
+    :type service: string
+    :return: Index of controller
+    """
+    entities = json.loads(resp)['entity-owners']['entity-type']
+    for entity in entities:
+        if entity['type'] == "org.opendaylight.mdsal.ServiceEntityType":
+            for instance in entity['entity']:
+                if service in instance['id']:
+                    return int(instance['owner'][-1:])
+    return 0
+
+
 def mod(num, base):
     """Gets modulo of number
 
index 967f4e543836722545cb8dc76b030e3df682d541..4e2c7815db3ce54cc6cb6576b6163798e61bacd2 100644 (file)
@@ -74,25 +74,18 @@ Check Device is Connected
     Should Be True    ${is_connected}
 
 Get Active Controller
-    [Arguments]    ${port}=64999    ${ip}=${EMPTY}
-    [Documentation]    Find cluster controller that is actively connected to SXP device
-    ${controller}    Set Variable    ${EMPTY}
+    [Documentation]    Find cluster controller that is marked as leader for SXP service in cluster
+    ${controller}    Set Variable    0
     : FOR    ${i}    IN RANGE    ${NUM_ODL_SYSTEM}
-    \    ${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}
-    \    ...    prompt=${ODL_SYSTEM_PROMPT}
-    \    ${controller}    Set Variable If    '${rc}' == '0'    ${i+1}    ${controller}
+    \    ${resp}    RequestsLibrary.Get Request    controller${i+1}    /restconf/operational/entity-owners:entity-owners
+    \    ${controller}    Get Active Controller From Json    ${resp.content}    SxpControllerInstance
+    \    Run Keyword If    '${controller}' != '0'    Exit For Loop
     [Return]    ${controller}
 
 Get Inactive Controller
-    [Arguments]    ${port}=64999    ${ip}=${EMPTY}
-    [Documentation]    Find cluster controller that is not actively connected to SXP device
-    @{controllers}    Create List
-    : FOR    ${i}    IN RANGE    ${NUM_ODL_SYSTEM}
-    \    ${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}
-    \    ...    prompt=${ODL_SYSTEM_PROMPT}
-    \    Run Keyword If    '${rc}' != '0'    Append To List    ${controllers}    ${i+1}
-    Log    ${controllers}
-    ${controller}    Evaluate    random.choice( ${controllers})    random
+    [Documentation]    Find cluster controller that is not marked as leader for SXP service in cluster
+    ${active_controller}    Get Active Controller
+    ${controller}    Evaluate    random.choice( filter( lambda i: i!=${active_controller}, range(1, ${NUM_ODL_SYSTEM} + 1)))    random
     [Return]    ${controller}
 
 Get Any Controller