Replace entity-owners API call 64/98664/3
authorSangwook Ha <sangwook.ha@verizon.com>
Tue, 23 Nov 2021 22:18:22 +0000 (14:18 -0800)
committerSangwook Ha <sangwook.ha@verizon.com>
Tue, 23 Nov 2021 23:09:19 +0000 (15:09 -0800)
An entity ownership test for OpenFlow Plugin makes a direct REST
API call to get the entity ownership information from operational
data store, which is only valid up to Silicon.

Update the 'get_entities' function in the ClusterEntities library
to fall back on the entity-owners API call for Silicon, and replace
the API call to the operational data currently used in the test case
with the function/keyword so that Silicon/Phosphorus/Sulfur are
all supported.

Signed-off-by: Sangwook Ha <sangwook.ha@verizon.com>
Change-Id: Idf7d41d1abc509f5f344e7d6d40d93a4dee8f960

csit/libraries/ClusterEntities.py
csit/libraries/ClusterManagement.robot
csit/suites/openflowplugin/EntityOwnership/030_Cluster_Sync_Problems.robot

index 507966c9d6c21537bb72dcd3b9f30c03373ce8fc..9f51f09e4ce5652f5f8594c3f92775511e7aff8a 100644 (file)
@@ -18,14 +18,28 @@ def get_entities(restconf_url):
             "User-Agent": "csit agent",
         },
         auth=("admin", "admin"),
+        timeout=5.0,
     )
 
     info(
-        "Response %s ",
+        "Response %s",
         resp,
     )
+    info(
+        "Response JSON %s",
+        resp.json(),
+    )
 
-    return resp.json()
+    if resp.status_code == status_codes["bad_request"]:
+        info(
+            "Status code is '%s' - trying operational data instead.",
+            resp.status_code,
+        )
+        result = get_entities_data(restconf_url)
+    else:
+        result = resp.json()
+
+    return result
 
 
 def get_entity_name(e_type, e_name):
@@ -76,10 +90,15 @@ def get_entity(restconf_url, e_type, e_name):
         },
         data=data,
         auth=("admin", "admin"),
+        timeout=5.0,
     )
 
     info(
-        "Entity json %s",
+        "Response %s",
+        resp,
+    )
+    info(
+        "Response JSON %s",
         resp.json(),
     )
 
@@ -122,12 +141,17 @@ def get_entity_owner(restconf_url, e_type, e_name):
         },
         data=data,
         auth=("admin", "admin"),
+        timeout=5.0,
     )
 
     info(
-        "Response %s ",
+        "Response %s",
         resp,
     )
+    info(
+        "Response JSON %s",
+        resp.json(),
+    )
 
     if resp.status_code == status_codes["bad_request"]:
         info(
@@ -141,6 +165,34 @@ def get_entity_owner(restconf_url, e_type, e_name):
     return result
 
 
+def get_entities_data(restconf_url):
+    """
+    Get the entity information from the datastore for Silicon
+    or earlier versions.
+    :param restconf_url: RESTCONF URL up to the RESTCONF root
+    """
+    resp = get(
+        url=restconf_url + "/data/entity-owners:entity-owners",
+        headers={
+            "Accept": "application/yang-data+json",
+            "User-Agent": "csit agent",
+        },
+        auth=("admin", "admin"),
+        timeout=5.0,
+    )
+
+    info(
+        "Response %s",
+        resp,
+    )
+    info(
+        "Response JSON %s",
+        resp.json(),
+    )
+
+    return resp.json()
+
+
 def get_entity_type_data(restconf_url, e_type):
     """
     Get the entity information for the given entity type from the datastore
@@ -158,14 +210,15 @@ def get_entity_type_data(restconf_url, e_type):
             "User-Agent": "csit agent",
         },
         auth=("admin", "admin"),
+        timeout=5.0,
     )
 
     info(
-        "Response %s ",
+        "Response %s",
         resp,
     )
     info(
-        "Entity json %s",
+        "Response JSON %s",
         resp.json(),
     )
 
index 77da92ab61c5add50d5621e63a0b443b2b06fcbf..c58fb4c80c08522b35aedf6f22d555cc4a0e7fc5 100644 (file)
@@ -233,7 +233,7 @@ Get_Owner_And_Candidates_For_Device_Rpc
     ${ip} =    Resolve_IP_Address_For_Member    member_index=${index}
     ${entity_type} =    BuiltIn.Set_Variable_If    '${device_type}' == 'netconf'    netconf-node/${device_name}    ${device_type}
     ${url} =    BuiltIn.Catenate    SEPARATOR=    http://    ${ip}    :8181/    ${RESTCONF_URI}
-    ${entity_result} =    ClusterEntities.get entity    ${url}    ${entity_type}    ${device_name}
+    ${entity_result} =    ClusterEntities.Get_Entity    ${url}    ${entity_type}    ${device_name}
     ${entity_candidates} =    Collections.Get_From_Dictionary    ${entity_result}    candidates
     ${entity_owner} =    Collections.Get_From_Dictionary    ${entity_result}    owner
     BuiltIn.Should_Not_Be_Empty    ${entity_owner}    No owner found for ${device_name}
index 4214ddcde42a47cb6848cf498ea857cde8a64d03..6247cfcb263ae00d9a50776c025711b1db95a72c 100644 (file)
@@ -7,20 +7,21 @@ Test Template     Isolating Node Scenario
 Library           SSHLibrary
 Library           RequestsLibrary
 Library           XML
+Library           Collections
+Library           ${CURDIR}/../../../libraries/ClusterEntities.py
 Resource          ${CURDIR}/../../../libraries/SetupUtils.robot
 Resource          ${CURDIR}/../../../libraries/Utils.robot
 Resource          ${CURDIR}/../../../libraries/FlowLib.robot
 Resource          ${CURDIR}/../../../libraries/OvsManager.robot
 Resource          ${CURDIR}/../../../libraries/ClusterManagement.robot
 Resource          ${CURDIR}/../../../libraries/ClusterOpenFlow.robot
-Library           Collections
+Resource          ${CURDIR}/../../../variables/openflowplugin/Variables.robot
 
 *** Variables ***
 ${SWITCHES}       1
 ${START_CMD}      sudo mn --topo linear,${SWITCHES}
 @{CONTROLLER_NODES}    ${ODL_SYSTEM_1_IP}    ${ODL_SYSTEM_2_IP}    ${ODL_SYSTEM_3_IP}
 @{cntls_idx_list}    ${1}    ${2}    ${3}
-${ENTITY_OWNER_URI}    rests/data/entity-owners:entity-owners
 
 *** Test Cases ***
 Start Mininet To All Nodes
@@ -158,9 +159,10 @@ Isolate Controller From The Cluster
 
 Check No Device Owners In Controller
     [Documentation]    Check there is no owners in controllers
-    ${session} =    Resolve_Http_Session_For_Member    member_index=${active_member}
-    # FIXME: The URI only works for Silicon & earlier versions. This should be replaced with new RPC calls for Phosphorus.
-    ${data} =    TemplatedRequests.Get_As_Json_From_Uri    uri=${ENTITY_OWNER_URI}    session=${session}
+    ${ip} =    Resolve_IP_Address_For_Member    member_index=${active_member}
+    ${url} =    BuiltIn.Catenate    SEPARATOR=    http://    ${ip}    :8181    ${RFC8040_RESTCONF_ROOT}
+    ${data} =    ClusterEntities.Get_Entities    ${url}
+    ${data} =    BuiltIn.Convert_To_String    ${data}
     #ofp-topology-manager entity is introduced in the OPNFLWPLUG-1022 bug fix, and this entity will
     #always be present in the EOS output. All 3 controller nodes will be candidate, so EOS output will
     #contain 6 members (members show 2 times).