From 45dcfa0dd9c50f92eee4253237798586a46a64bb Mon Sep 17 00:00:00 2001 From: Jamo Luhrsen Date: Tue, 18 Feb 2020 17:28:52 -0800 Subject: [PATCH] Add Library/Keywords to dynamically generate URI 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 --- csit/libraries/NetconfKeywords.robot | 9 ++++--- csit/libraries/Restconf.robot | 35 ++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 csit/libraries/Restconf.robot diff --git a/csit/libraries/NetconfKeywords.robot b/csit/libraries/NetconfKeywords.robot index 3a4abd0c9b..e2c292c7ab 100644 --- a/csit/libraries/NetconfKeywords.robot +++ b/csit/libraries/NetconfKeywords.robot @@ -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 index 0000000000..baed160b99 --- /dev/null +++ b/csit/libraries/Restconf.robot @@ -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} -- 2.36.6