Fix featuresBoot parameter in nitrogen tests
[integration/test.git] / csit / libraries / SxpLib.robot
index e5b99194b007c425a1962764ed3df7ae1e857258..6f4d5c977fa08c4ea61bddf7f1d9c56d05743387 100644 (file)
@@ -5,8 +5,10 @@ Library           RequestsLibrary
 Library           SSHLibrary
 Library           String
 Library           ./Sxp.py
+Resource          CompareStream.robot
 Resource          KarafKeywords.robot
 Resource          Utils.robot
+Resource          TemplatedRequests.robot
 Variables         ../variables/Variables.py
 
 *** Variables ***
@@ -29,8 +31,10 @@ Post To Controller
 
 Add Node
     [Arguments]    ${node}    ${password}=${EMPTY}    ${version}=version4    ${port}=64999    ${session}=session    ${ip}=${EMPTY}
+    ...    ${ssl_stores}=${EMPTY}
     [Documentation]    Add node via RPC to ODL
     ${DATA}    Add Node Xml    ${node}    ${port}    ${password}    ${version}    ${ip}
+    ...    keystores=${ssl_stores}
     Post To Controller    ${session}    add-node    ${DATA}
 
 Delete Node
@@ -41,10 +45,10 @@ Delete Node
 
 Add Connection
     [Arguments]    ${version}    ${mode}    ${ip}    ${port}    ${node}=127.0.0.1    ${password}=${EMPTY}
-    ...    ${session}=session    ${domain}=global
+    ...    ${session}=session    ${domain}=global    ${security_mode}=${EMPTY}
     [Documentation]    Add connection via RPC to node
     ${DATA}    Add Connection Xml    ${version}    ${mode}    ${ip}    ${port}    ${node}
-    ...    ${password}    ${domain}
+    ...    ${password}    ${domain}    security_mode=${security_mode}
     Post To Controller    ${session}    add-connection    ${DATA}
 
 Get Connections
@@ -86,32 +90,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
@@ -121,6 +133,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
@@ -156,9 +178,11 @@ Clean Peer Groups
     \    Delete Peer Group    ${group['name']}    ${node}    ${session}
 
 Add Filter
-    [Arguments]    ${name}    ${type}    ${entries}    ${node}=127.0.0.1    ${session}=session
+    [Arguments]    ${name}    ${type}    ${entries}    ${node}=127.0.0.1    ${session}=session    ${policy}=auto-update
     [Documentation]    Add Filter via RPC from Node
-    ${DATA}    Add Filter Xml    ${name}    ${type}    ${entries}    ${node}
+    ${DATA}    Run_Keyword_If_At_Least_Else    carbon    Add Filter Xml    ${name}    ${type}    ${entries}
+    ...    ${node}    ${policy}
+    ...    ELSE    Add Filter Xml    ${name}    ${type}    ${entries}    ${node}
     Post To Controller    ${session}    add-filter    ${DATA}
 
 Add Domain Filter
@@ -182,7 +206,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}
@@ -190,7 +214,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}
@@ -233,10 +257,16 @@ Verify Snapshot Was Pushed
     ${output}    Run Command On Controller    ${ODL_SYSTEM_IP}    cat ${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log* | grep -c 'Successfully pushed configuration snapshot.*${snapshot_string}'
     Should Not Be Equal As Strings    ${output}    0
 
+Prepare SSH Keys On Karaf
+    [Arguments]    ${system}=${ODL_SYSTEM_IP}    ${user}=${ODL_SYSTEM_USER}    ${passwd}=${ODL_SYSTEM_PASSWORD}    ${prompt}=${ODL_SYSTEM_PROMPT}    ${system_workspace}=${WORKSPACE}
+    [Documentation]    Executes client login on karaf VM in so that SSH keys will be generated by defualt karaf callback,
+    ...    expecting echo affter succesfull login. TODO: test on multiple runs if this aproach reduce SSHExceptions in robotframework
+    ${stdout}    Run Command On Remote System    ${system}    ${system_workspace}${/}${BUNDLEFOLDER}/bin/client echo READY    ${user}    ${passwd}    prompt=${prompt}
+    Should Match    "${stdout}"    "*READY"
+
 Setup SXP Session
     [Arguments]    ${session}=session    ${controller}=${ODL_SYSTEM_IP}
     [Documentation]    Create session to Controller
-    Install a Feature    odl-sxp-controller    ${controller}
     Verify Feature Is Installed    odl-sxp-controller    ${controller}
     Create Session    ${session}    url=http://${controller}:${RESTCONFPORT}    auth=${AUTH}    headers=${HEADERS_XML}
     ${resp}    RequestsLibrary.Get Request    ${session}    ${MODULES_API}
@@ -305,9 +335,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}
@@ -322,5 +351,24 @@ 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
+
+Get Routing Configuration From Controller
+    [Arguments]    ${session}
+    [Documentation]    Get Routing configuration from config DS
+    ${resp}    RequestsLibrary.Get Request    ${session}    /restconf/config/sxp-cluster-route:sxp-cluster-route/    headers=${ACCEPT_XML}
+    ${data}    Set Variable If    "${resp.status_code}" == "200"    ${resp.content}    ${EMPTY}
+    [Return]    ${data}
+
+Put Routing Configuration To Controller
+    [Arguments]    ${DATA}    ${session}
+    [Documentation]    Put Routing configuration to Config DS
+    ${resp}    RequestsLibrary.Put Request    ${session}    /restconf/config/sxp-cluster-route:sxp-cluster-route/    data=${DATA}    headers=${HEADERS_XML}
+    Should Match    "${resp.status_code}"    "20?"
+
+Clean Routing Configuration To Controller
+    [Arguments]    ${session}
+    [Documentation]    Delete Routing configuration from Config DS
+    ${resp}    RequestsLibrary.Get Request    ${session}    /restconf/config/sxp-cluster-route:sxp-cluster-route/    headers=${ACCEPT_XML}
+    Run Keyword If    "${resp.status_code}" == "200"    RequestsLibrary.Delete Request    ${session}    /restconf/config/sxp-cluster-route:sxp-cluster-route/