Remove ODL_STREAM variable from usage in SxpLib.robot 71/50571/18
authorPeter Gubka <pgubka@cisco.com>
Tue, 17 Jan 2017 18:16:01 +0000 (19:16 +0100)
committerJamo Luhrsen <jluhrsen@redhat.com>
Fri, 20 Jan 2017 20:13:43 +0000 (20:13 +0000)
Change-Id: I35d9794ca3db5a9a0c2ff3cbfd1af1a324b05159
Signed-off-by: Peter Gubka <pgubka@cisco.com>
csit/libraries/CompareStream.robot
csit/libraries/SxpLib.robot

index f9a6cb4c6d4bc8670c5b6aced06ede64be3975c9..df880c42021868ee5358e9d3cb7f28f7ebb17599 100644 (file)
@@ -5,6 +5,7 @@ Documentation     This Resource contains list of Keywords Set_Variable_If_At_Lea
 ...               for comparison ${ODL_STREAM} to the given ${lower_bound},
 ...               in order to replace ad-hoc conditional execution in suites.
 Library           Collections
+Library           String
 
 *** Variables ***
 &{Stream_dict}    hydrogen=${1}    stable-helium=${2}    stable-lithium=${3}    beryllium=${4}    boron=${5}    carbon=${6}    nitrogen=${7}
@@ -82,6 +83,26 @@ Set_Variable_If_At_Most_Carbon
     ...    return ${value_if_false} otherwise.
     BuiltIn.Run_Keyword_And_Return    Set_Variable_If_At_Most    carbon    ${value_if_true}    ${value_if_false}
 
+CompareStream__Convert_Input
+    [Arguments]    @{arguments}
+    [Documentation]    Splits arguments into args and kwargs is used in Run_Keyword_If_At_Least_Else and Run_Keyword_If_At_Most_Else.
+    ...    The problem is, when the string contains =, but it is not a named argument (name=value). There can be many values containing =, but
+    ...    for sure it is present in xmls. If the string starts with "<" it will be treated as it is xml and splitting for
+    ...    name and value will not be executed.
+    ...    If named argument is passed into this kw, only string data are supported e.g. name=string. Complex variables such as lists or dictionaries
+    ...    are not supported.
+    ${args}    BuiltIn.Create_List
+    ${kwargs}    BuiltIn.Create_Dictionary
+    : FOR    ${arg}    IN    @{arguments}
+    \    ${removed}    String.Remove_String    ${arg}    \n    ${Space}    \t
+    \    ...    \r
+    \    ${splitted}    BuiltIn.Run_Keyword_If    "${removed[0]}" == "<"    BuiltIn.Create List    ${arg}
+    \    ...    ELSE    String.Split_String    ${arg}    separator==    max_split=1
+    \    ${len}    BuiltIn.Get_Length    ${splitted}
+    \    Run Keyword If    ${len}==1    Collections.Append_To_List    ${args}    @{splitted}[0]
+    \    ...    ELSE    Collections.Set_To_Dictionary    ${kwargs}    @{splitted}
+    BuiltIn.Return_From_Keyword    ${args}    ${kwargs}
+
 Run_Keyword_If_At_Least
     [Arguments]    ${lower_bound}    ${kw_name}    @{varargs}    &{kwargs}
     [Documentation]    Compare ${lower_bound} to ${ODL_STREAM} and in case ${ODL_STREAM} is at least ${lower_bound},
@@ -96,8 +117,10 @@ Run_Keyword_If_At_Least_Else
     BuiltIn.Run_Keyword_If    "${position}" == "-1"    BuiltIn.Fail    Missing else statement in defined expresion
     ${varargs_if}    Collections.Get_Slice_From_List    ${varargs}    0    ${position}
     ${varargs_else}    Collections.Get_Slice_From_List    ${varargs}    ${position+1}
-    ${resp}    BuiltIn.Run_Keyword_If    &{Stream_dict}[${ODL_STREAM}] >= &{Stream_dict}[${lower_bound}]    @{varargs_if}
-    ...    ELSE    @{varargs_else}
+    ${args_if}    ${kwargs_if}    CompareStream__Convert_Input    @{varargs_if}
+    ${args_else}    ${kwargs_else}    CompareStream__Convert_Input    @{varargs_else}
+    ${resp}    BuiltIn.Run_Keyword_If    &{Stream_dict}[${ODL_STREAM}] >= &{Stream_dict}[${lower_bound}]    @{args_if}    &{kwargs_if}
+    ...    ELSE    @{args_else}    &{kwargs_else}
     [Return]    ${resp}
 
 Run_Keyword_If_At_Most
@@ -114,8 +137,10 @@ Run_Keyword_If_At_Most_Else
     BuiltIn.Run_Keyword_If    "${position}" == "-1"    BuiltIn.Fail    Missing else statement in defined expresion
     ${varargs_if}    Collections.Get_Slice_From_List    ${varargs}    0    ${position}
     ${varargs_else}    Collections.Get_Slice_From_List    ${varargs}    ${position+1}
-    ${resp}    BuiltIn.Run_Keyword_If    &{Stream_dict}[${ODL_STREAM}] <= &{Stream_dict}[${upper_bound}]    @{varargs_if}
-    ...    ELSE    @{varargs_else}
+    ${args_if}    ${kwargs_if}    CompareStream__Convert_Input    @{varargs_if}
+    ${args_else}    ${kwargs_else}    CompareStream__Convert_Input    @{varargs_else}
+    ${resp}    BuiltIn.Run_Keyword_If    &{Stream_dict}[${ODL_STREAM}] >= &{Stream_dict}[${lower_bound}]    @{args_if}    &{kwargs_if}
+    ...    ELSE    @{args_else}    &{kwargs_else}
     [Return]    ${resp}
 
 Run_Keyword_If_More_Than
index 02314f37bca74a3cb422f085e9b638f4f57fd1cd..3a9b22f19db276a8242f996a6f0ab240fe2ebd68 100644 (file)
@@ -5,9 +5,10 @@ Library           RequestsLibrary
 Library           SSHLibrary
 Library           String
 Library           ./Sxp.py
+Resource          CompareStream.robot
 Resource          KarafKeywords.robot
 Resource          Utils.robot
-Resource          CompareStream.robot
+Resource          TemplatedRequests.robot
 Variables         ../variables/Variables.py
 
 *** Variables ***
@@ -87,32 +88,40 @@ Get Bindings
     [Arguments]    ${node}=127.0.0.1    ${session}=session    ${domain}=global    ${scope}=all
     [Documentation]    Gets all binding via RPC from Master DB of node
     ${DATA}    Get Bindings From Node Xml    ${node}    ${scope}    ${domain}
-    ${resp}    Run Keyword If    '${ODL_STREAM}' not in ['beryllium', 'stable-lithium']    Post Request    ${session}    ${REST_CONTEXT}:get-node-bindings    data=${DATA}
-    ...    headers=${HEADERS_XML}
-    ...    ELSE    Get Request    ${session}    /restconf/operational/network-topology:network-topology/topology/sxp/node/${node}/master-database/    headers=${HEADERS_XML}
-    Should be Equal As Strings    ${resp.status_code}    200
-    [Return]    ${resp.content}
+    ${resp1}    CompareStream.Run_Keyword_If_At_Least_Boron    TemplatedRequests.Post_To_Uri    ${REST_CONTEXT}:get-node-bindings    data=${DATA}    accept=${ACCEPT_JSON}    content_type=${HEADERS_XML}
+    ...    session=${session}
+    ${resp2}    CompareStream.Run_Keyword_If_Less_Than_Boron    TemplatedRequests.Get_As_Json_From_Uri    /restconf/operational/network-topology:network-topology/topology/sxp/node/${node}/master-database/    session=${session}
+    ${resp}    CompareStream.Set_Variable_If_At_Least_Boron    ${resp1}    ${resp2}
+    [Return]    ${resp}
 
 Clean Bindings
     [Arguments]    ${node}=127.0.0.1    ${session}=session    ${domain}=global
     [Documentation]    Delete all bindings via RPC from Master DB of node
     ${resp}    Get Bindings    ${node}    ${session}    ${domain}    local
-    @{bindings}    Run Keyword If    '${ODL_STREAM}' not in ['beryllium', 'stable-lithium']    Parse Bindings    ${resp}
+    @{bindings}    CompareStream.Run_Keyword_If_At_Least_Else    boron    Parse Bindings    ${resp}
     ...    ELSE    Parse Prefix Groups    ${resp}    local
     : FOR    ${binding}    IN    @{bindings}
-    \    Run Keyword If    '${ODL_STREAM}' not in ['beryllium', 'stable-lithium']    Clean Binding    ${binding['sgt']}    ${binding['ip-prefix']}    ${node}
-    \    ...    ${session}    ${domain}
-    \    ...    ELSE    Clean Binding    ${binding}    ${binding['binding']}    ${node}
-    \    ...    ${session}    ${domain}
+    \    CompareStream.Run_Keyword_If_At_Least_Boron    Clean Binding Default    ${binding}    ${node}    ${session}    ${domain}
+    \    CompareStream.Run_Keyword_If_At_Most_Beryllium    Clean Binding At Most Be    ${binding}    ${node}    ${session}    ${domain}
+
+Clean Binding Default
+    [Arguments]    ${binding}    ${node}    ${session}    ${domain}
+    [Documentation]    Clean binding
+    Clean Binding    ${binding['sgt']}    ${binding['ip-prefix']}    ${node}    ${session}
+
+Clean Binding At Most Be
+    [Arguments]    ${binding}    ${node}    ${session}    ${domain}
+    [Documentation]    Clean binding
+    Clean Binding    ${binding}    ${binding['binding']}    ${node}    ${session}
 
 Clean Binding
     [Arguments]    ${sgt}    ${prefixes}    ${node}    ${session}    ${domain}=global
     [Documentation]    Used for nester FOR loop
     : FOR    ${prefix}    IN    @{prefixes}
-    \    Run Keyword If    '${ODL_STREAM}' not in ['beryllium', 'stable-lithium']    Delete Binding    ${sgt}    ${prefix}    ${node}
-    \    ...    ${domain}    ${session}
-    \    ...    ELSE    Delete Binding    ${sgt['sgt']}    ${prefix['ip-prefix']}    ${node}
-    \    ...    ${domain}    ${session}
+    \    CompareStream.Run_Keyword_If_At_Least_Boron    Delete Binding Default    ${sgt}    ${prefix}    ${node}    ${domain}
+    \    ...    ${session}
+    \    CompareStream.Run_Keyword_If_At_Most_Beryllium    Delete Binding Be    ${sgt}    ${prefix}    ${node}    ${domain}
+    \    ...    ${session}
 
 Update Binding
     [Arguments]    ${sgtOld}    ${prefixOld}    ${sgtNew}    ${prefixNew}    ${node}=127.0.0.1    ${session}=session
@@ -122,6 +131,16 @@ Update Binding
     ...    ${domain}
     Post To Controller    ${session}    update-entry    ${DATA}
 
+Delete Binding Default
+    [Arguments]    ${sgt}    ${prefix}    ${node}    ${domain}    ${session}
+    [Documentation]    Delete binding via RPC
+    Delete Binding    ${sgt}    ${prefix}    ${node}    ${domain}    ${session}
+
+Delete Binding Be
+    [Arguments]    ${sgt}    ${prefix}    ${node}    ${domain}    ${session}
+    [Documentation]    Delete binding via RPC
+    Delete Binding    ${sgt['sgt']}    ${prefix['ip-prefix']}    ${node}    ${domain}    ${session}
+
 Delete Binding
     [Arguments]    ${sgt}    ${prefix}    ${node}=127.0.0.1    ${domain}=global    ${session}=session
     [Documentation]    Delete binding via RPC from Master DB of node
@@ -185,7 +204,7 @@ Delete Domain Filter
 Should Contain Binding
     [Arguments]    ${resp}    ${sgt}    ${prefix}    ${db_source}=any
     [Documentation]    Tests if data contains specified binding
-    ${out}    Run Keyword If    '${ODL_STREAM}' not in ['beryllium', 'stable-lithium']    Find Binding    ${resp}    ${sgt}    ${prefix}
+    ${out}    CompareStream.Run_Keyword_If_At_Least_Else    boron    Find Binding    ${resp}    ${sgt}    ${prefix}
     ...    ELSE    Find Binding Legacy    ${resp}    ${sgt}    ${prefix}    ${db_source}
     ...    add
     Should Be True    ${out}    Doesn't have ${sgt} ${prefix}
@@ -193,7 +212,7 @@ Should Contain Binding
 Should Not Contain Binding
     [Arguments]    ${resp}    ${sgt}    ${prefix}    ${db_source}=any
     [Documentation]    Tests if data doesn't contains specified binding
-    ${out}    Run Keyword If    '${ODL_STREAM}' not in ['beryllium', 'stable-lithium']    Find Binding    ${resp}    ${sgt}    ${prefix}
+    ${out}    CompareStream.Run_Keyword_If_At_Least_Else    boron    Find Binding    ${resp}    ${sgt}    ${prefix}
     ...    ELSE    Find Binding Legacy    ${resp}    ${sgt}    ${prefix}    ${db_source}
     ...    add
     Should Not Be True    ${out}    Should't have ${sgt} ${prefix}
@@ -307,9 +326,8 @@ Setup SXP Environment
     Setup SXP Session
     : FOR    ${num}    IN RANGE    1    ${node_range}
     \    ${ip}    Get Ip From Number    ${num}
-    \    Run Keyword If    '${ODL_STREAM}' not in ['beryllium', 'stable-lithium']    Add Node    ${ip}
-    \    Run Keyword If    '${ODL_STREAM}' not in ['beryllium', 'stable-lithium']    Wait Until Keyword Succeeds    20    1    Check Node Started
-    \    ...    ${ip}
+    \    CompareStream.Run_Keyword_If_At_Least_Boron    Add Node    ${ip}
+    \    CompareStream.Run_Keyword_If_At_Least_Boron    Wait Until Keyword Succeeds    20    1    Check Node Started    ${ip}
 
 Check Node Started
     [Arguments]    ${node}    ${port}=64999    ${system}=${ODL_SYSTEM_IP}    ${session}=session    ${ip}=${node}
@@ -324,5 +342,5 @@ Clean SXP Environment
     [Documentation]    Destroy created sessions
     : FOR    ${num}    IN RANGE    1    ${node_range}
     \    ${ip}    Get Ip From Number    ${num}
-    \    Run Keyword If    '${ODL_STREAM}' not in ['beryllium', 'stable-lithium']    Delete Node    ${ip}
+    \    CompareStream.Run_Keyword_If_At_Least_Boron    Delete Node    ${ip}
     Clean SXP Session