Add Library/Keywords to dynamically generate URI 97/87897/7
authorJamo Luhrsen <jluhrsen@gmail.com>
Wed, 19 Feb 2020 01:28:52 +0000 (17:28 -0800)
committerJamo Luhrsen <jluhrsen@gmail.com>
Fri, 21 Feb 2020 17:23:56 +0000 (09:23 -0800)
The intention is to have a flag for USE_RFC8040 that can
be set to True or False and the final REST endpoint will
be gererated automatically

Change-Id: Ic6514154f59fb2a73b0cc2dab9bec94f8f353ea6
Signed-off-by: Jamo Luhrsen <jluhrsen@gmail.com>
csit/libraries/NetconfKeywords.robot
csit/libraries/Restconf.robot [new file with mode: 0644]

index 3a4abd0c9b7543d345b2fe21174be85f1a84aa50..e2c292c7aba619c277b3fd8250ee9aee2ee7311c 100644 (file)
@@ -18,6 +18,7 @@ Library           DateTime
 Library           RequestsLibrary
 Library           SSHLibrary
 Resource          NexusKeywords.robot
+Resource          Restconf.robot
 Resource          SSHKeywords.robot
 Resource          TemplatedRequests.robot
 Resource          Utils.robot
@@ -60,7 +61,8 @@ Count_Netconf_Connectors_For_Device
     # This keyword should be renamed but without an automatic keyword naming standards checker this is
     # potentially destabilizing change so right now it is as FIXME. Proposed new name:
     # Count_Device_Instances_In_Netconf_Topology
-    ${mounts}=    TemplatedRequests.Get_As_Json_From_Uri    ${OPERATIONAL_API}/network-topology:network-topology/topology/topology-netconf    session=${session}
+    ${uri} =    Restconf.Generate URI    network-topology:network-topology    operational
+    ${mounts}=    TemplatedRequests.Get_As_Json_From_Uri    ${uri}    session=${session}
     Builtin.Log    ${mounts}
     ${actual_count}=    Builtin.Evaluate    len('''${mounts}'''.split('"node-id": "${device_name}"'))-1
     Builtin.Return_From_Keyword    ${actual_count}
@@ -78,7 +80,7 @@ Check_Device_Completely_Gone
     [Arguments]    ${device_name}    ${session}=default
     [Documentation]    Check that the specified device has no Netconf connectors nor associated data.
     Check_Device_Has_No_Netconf_Connector    ${device_name}    session=${session}
-    ${uri}=    Builtin.Set_Variable    ${CONFIG_API}/network-topology:network-topology/topology/topology-netconf/node/${device_name}
+    ${uri} =    Restconf.Generate URI    network-topology:network-topology    config    topology=topology-netconf    node=${device_name}
     ${status}    ${response}=    BuiltIn.Run_Keyword_And_Ignore_Error    TemplatedRequests.Get_As_Xml_From_Uri    ${uri}    session=${session}
     BuiltIn.Should_Be_Equal_As_Strings    ${status}    FAIL
     BuiltIn.Should_Contain    ${response}    404
@@ -86,7 +88,8 @@ Check_Device_Completely_Gone
 Check_Device_Connected
     [Arguments]    ${device_name}    ${session}=default
     [Documentation]    Check that the specified device is accessible from Netconf.
-    ${device_status}=    TemplatedRequests.Get_As_Json_From_Uri    ${OPERATIONAL_API}/network-topology:network-topology/topology/topology-netconf/node/${device_name}    session=${session}
+    ${uri} =    Restconf.Generate URI    network-topology:network-topology    operational    topology=topology-netconf    node=${device_name}
+    ${device_status}=    TemplatedRequests.Get_As_Json_From_Uri    ${uri}    session=${session}
     Builtin.Should_Contain    ${device_status}    "netconf-node-topology:connection-status": "connected"
 
 Wait_Device_Connected
diff --git a/csit/libraries/Restconf.robot b/csit/libraries/Restconf.robot
new file mode 100644 (file)
index 0000000..baed160
--- /dev/null
@@ -0,0 +1,35 @@
+*** Settings ***
+
+*** Variables ***
+${USE_RFC8040} =    False
+
+*** Keywords ***
+
+Generate URI
+    [Arguments]    ${identifier}    ${datastore}=config    @{node_value_list}
+    [Documentation]    Returns the proper URI to use depending on if RFC8040 is to be used or not. Variable input
+    ...    error checking is done to ensure the ${USE_RFC8040} Flag is one of True or False and the ${datastore} variable
+    ...    must be config or operational. @{node_value_list} is expected to be in the format of node=value. RFC8040 can
+    ...    use that as is with '=' delimiter, but older restconf URI will convert the '=' to a '/'
+    ${uri} =    Run Keyword If    "${USE_RFC8040}" == "True"    Generate RFC8040 URI    ${identifier}    ${datastore}    @{node_value_list}
+    Return From Keyword If    "${USE_RFC8040}" == "True"    ${uri}
+    Run Keyword If    "${USE_RFC8040}" != "False"    Fail    Invalid Value for RFC8040 Flag: ${USE_RFC8040}
+    Run Keyword If    "${datastore}"!="config" and "${datastore}"!="operational"    Fail    Invalid value for datastore: ${datastore}
+    ${uri} =    Run Keyword If    "${datastore}"=="config"    Set Variable    ${CONFIG_API}/${identifier}
+    ...    ELSE    Set Variable    ${OPERATIONAL_API}/${identifier}
+    ${node_value_path} =    Set Variable    ${EMPTY}
+    FOR    ${nv}    IN    @{node_value_list}
+        ${nv} =    String.Replace String    ${nv}    =    /
+        ${node_value_path} =    Set Variable    ${node_value_path}/${nv}
+    END
+    [Return]    ${uri}${node_value_path}
+
+Generate RFC8040 URI
+    [Arguments]    ${identifier}    ${datastore}=config    @{node_value_list}
+    ${node_value_path} =    Set Variable    ${EMPTY}
+    FOR    ${nv}    IN    @{node_value_list}
+        ${node_value_path} =    Set Variable    ${node_value_path}/${nv}
+    END
+    ${uri} =    Run Keyword If    "${datastore}" == "config"    Set Variable    rests/data/${identifier}${node_value_path}?content=config
+    ...    ELSE    Set Variable    rests/data/${identifier}${node_value_path}?content=nonconfig
+    [Return]    ${uri}