SXP: wait for node start/stop
[integration/test.git] / csit / libraries / SxpLib.robot
index 8d25a248f517338c07baf579525eae546c439f74..bb5f14cd11c2c9c96c8464560ce910ad4ea58229 100644 (file)
@@ -3,6 +3,7 @@ Documentation     Library containing Keywords used for SXP testing
 Library           Collections
 Library           RequestsLibrary
 Library           ./Sxp.py
+Resource          CompareStream.robot
 Resource          KarafKeywords.robot
 Resource          TemplatedRequests.robot
 Resource          Utils.robot
@@ -27,7 +28,7 @@ Post To Controller
     BuiltIn.Should Be True    ${result}    RPC result is False
 
 Add Node
-    [Arguments]    ${node}    ${password}=${EMPTY}    ${version}=version4    ${port}=64999    ${session}=session    ${ip}=${EMPTY}
+    [Arguments]    ${node}    ${password}=${EMPTY}    ${version}=version4    ${port}=64999    ${session}=session    ${ip}=${node}
     ...    ${ssl_stores}=${EMPTY}    ${retry_open_timer}=1
     [Documentation]    Add node via RPC to ODL
     ${data} =    Sxp.Add Node Xml    ${node}    ${port}    ${password}    ${version}    ${ip}
@@ -78,9 +79,22 @@ Verify Connection
     Should Contain Connection    ${resp}    ${ip}    ${port}    ${mode}    ${version}    ${state}
 
 Add Bindings
-    [Arguments]    ${sgt}    ${prefixes}    ${origin}=LOCAL    ${node}=127.0.0.1    ${session}=session    ${domain}=global
-    [Documentation]    Add/Update one or more bindings via RPC to Master DB of the node
-    ${data} =    Sxp.Add Bindings Xml    ${node}    ${domain}    ${sgt}    ${prefixes}    ${origin}
+    [Arguments]    ${sgt}    ${prefixes}    ${node}=127.0.0.1    ${session}=session    ${domain}=global    ${origin}=LOCAL
+    [Documentation]    Based on ODL version decide if bindings will be added with or without origin type (introduced in Fluorine)
+    CompareStream.Run_Keyword_If_At_Least_Fluorine    Add Bindings Fluorine    ${sgt}    ${prefixes}    ${node}    ${session}    ${domain}
+    ...    ${origin}
+    CompareStream.Run_Keyword_If_At_Most_Oxygen    Add Bindings Oxygen    ${sgt}    ${prefixes}    ${node}    ${session}    ${domain}
+
+Add Bindings Fluorine
+    [Arguments]    ${sgt}    ${prefixes}    ${node}    ${session}    ${domain}    ${origin}
+    [Documentation]    Add/Update one or more bindings with origin type via RPC to Master DB of the node
+    ${data} =    Sxp.Add Bindings Xml Fluorine    ${node}    ${domain}    ${sgt}    ${prefixes}    ${origin}
+    Post To Controller    ${session}    add-bindings    ${data}
+
+Add Bindings Oxygen
+    [Arguments]    ${sgt}    ${prefixes}    ${node}    ${session}    ${domain}
+    [Documentation]    Add/Update one or more bindings without origin type via RPC to Master DB of the node
+    ${data} =    Sxp.Add Bindings Xml Oxygen    ${node}    ${domain}    ${sgt}    ${prefixes}
     Post To Controller    ${session}    add-bindings    ${data}
 
 Get Bindings
@@ -96,12 +110,14 @@ Clean Bindings
     ${resp} =    Get Bindings    ${node}    ${session}    ${domain}    ${scope}
     @{bindings} =    Sxp.Parse Bindings    ${resp}
     : FOR    ${binding}    IN    @{bindings}
-    \    Delete Bindings    ${binding['sgt']}    ${binding['ip-prefix']}    ${node}    ${domain}    ${session}
+    \    @{prefixes_list} =    collections.Get From Dictionary    ${binding}    ip-prefix
+    \    ${prefixes} =    BuiltIn.Catenate    SEPARATOR=,    @{prefixes_list}
+    \    Delete Bindings    ${binding['sgt']}    ${prefixes}    ${node}    ${domain}    ${session}
 
 Delete Bindings
     [Arguments]    ${sgt}    ${prefixes}    ${node}=127.0.0.1    ${domain}=global    ${session}=session
     [Documentation]    Delete one or more bindings via RPC from Master DB of node
-    ${data} =    Sxp.Delete Bindings Xml    ${node}    ${domain}    ${sgt}    @{prefixes}
+    ${data} =    Sxp.Delete Bindings Xml    ${node}    ${domain}    ${sgt}    ${prefixes}
     Post To Controller    ${session}    delete-bindings    ${data}
 
 Add PeerGroup
@@ -135,10 +151,22 @@ Clean Peer Groups
 Add Filter
     [Arguments]    ${name}    ${type}    ${entries}    ${node}=127.0.0.1    ${session}=session    ${policy}=auto-update
     [Documentation]    Add Filter via RPC from Node
-    ${data} =    BuiltIn.Run_Keyword_If_At_Least_Else    carbon    Add Filter Xml    ${name}    ${type}    ${entries}
+    ${data} =    Prepare Add/Update Filter Data    ${name}    ${type}    ${entries}    ${node}    ${policy}
+    Post To Controller    ${session}    add-filter    ${data}
+
+Update Filter
+    [Arguments]    ${name}    ${type}    ${entries}    ${node}=127.0.0.1    ${session}=session    ${policy}=auto-update
+    [Documentation]    Update Filter via RPC
+    ${data} =    Prepare Add/Update Filter Data    ${name}    ${type}    ${entries}    ${node}    ${policy}
+    Post To Controller    ${session}    update-filter    ${data}
+
+Prepare Add/Update Filter Data
+    [Arguments]    ${name}    ${type}    ${entries}    ${node}=127.0.0.1    ${policy}=auto-update
+    [Documentation]    Prepare XML payload for add-filter and update-filter RPCs. Payloads for both RPCs are the same.
+    ${data} =    CompareStream.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}
+    [Return]    ${data}
 
 Add Domain Filter
     [Arguments]    ${name}    ${domains}    ${entries}    ${node}=127.0.0.1    ${filter_name}=base-domain-filter    ${session}=session
@@ -175,7 +203,7 @@ Should Contain Connection
     [Documentation]    Test if data contains specified connection
     ${out} =    Sxp.Find Connection    ${resp}    ${version}    ${mode}    ${ip}    ${port}
     ...    ${state}
-    BuiltIn.Should Be True    ${out}    Doesn't have ${ip}:${port} ${mode} ${version}
+    BuiltIn.Should Be True    ${out}    Doesn't have ${ip}:${port} ${mode} ${version} in state ${state}
 
 Should Not Contain Connection
     [Arguments]    ${resp}    ${ip}    ${port}    ${mode}    ${version}    ${state}=none
@@ -232,30 +260,23 @@ Verify Snapshot Was Pushed
     ${output} =    Utils.Run Command On Controller    ${ODL_SYSTEM_IP}    cat ${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log* | grep -c 'Successfully pushed configuration snapshot.*${snapshot_string}'
     BuiltIn.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} =    Utils.Run Command On Remote System    ${system}    ${system_workspace}${/}${BUNDLEFOLDER}/bin/client echo READY    ${user}    ${passwd}    prompt=${prompt}
-    BuiltIn.Should Match    "${stdout}"    "*READY"
-
-Setup SXP Session
-    [Arguments]    ${session}=session    ${controller}=${ODL_SYSTEM_IP}
-    [Documentation]    Create session to Controller
-    KarafKeywords.Verify Feature Is Installed    odl-sxp-controller    ${controller}
-    RequestsLibrary.Create Session    ${session}    url=http://${controller}:${RESTCONFPORT}    auth=${AUTH}    headers=${HEADERS_XML}
-    ${resp} =    RequestsLibrary.Get Request    ${session}    ${MODULES_API}
-    BuiltIn.Should Be Equal As Strings    ${resp.status_code}    200
-    BuiltIn.Should Contain    ${resp.content}    ietf-restconf
-
-Clean SXP Session
-    [Documentation]    Destroy created sessions
-    RequestsLibrary.Delete All Sessions
-
 Add Domain
-    [Arguments]    ${domain_name}    ${sgt}=None    ${prefixes}=''    ${origin}=LOCAL    ${node}=127.0.0.1    ${session}=session
-    [Documentation]    Add Domain with bindings via RPC
-    ${data} =    Sxp.Add Domain Xml    ${node}    ${domain_name}    ${sgt}    ${prefixes}    ${origin}
+    [Arguments]    ${domain_name}    ${sgt}=None    ${prefixes}=None    ${origin}=LOCAL    ${node}=127.0.0.1    ${session}=session
+    [Documentation]    Based on ODL version decide if domain's bindings will be added with or without origin type (introduced in Fluorine)
+    CompareStream.Run_Keyword_If_At_Least_Fluorine    Add Domain Fluorine    ${domain_name}    ${sgt}    ${prefixes}    ${origin}    ${node}
+    ...    ${session}
+    CompareStream.Run_Keyword_If_At_Most_Oxygen    Add Domain Oxygen    ${domain_name}    ${sgt}    ${prefixes}    ${node}    ${session}
+
+Add Domain Fluorine
+    [Arguments]    ${domain_name}    ${sgt}    ${prefixes}    ${origin}    ${node}    ${session}
+    [Documentation]    Add Domain with bindings (with origin) via RPC
+    ${data} =    Sxp.Add Domain Xml Fluorine    ${node}    ${domain_name}    ${sgt}    ${prefixes}    ${origin}
+    Post To Controller    ${session}    add-domain    ${data}
+
+Add Domain Oxygen
+    [Arguments]    ${domain_name}    ${sgt}    ${prefixes}    ${node}    ${session}
+    [Documentation]    Add Domain with bindings (without origin) via RPC
+    ${data} =    Sxp.Add Domain Xml Oxygen    ${node}    ${domain_name}    ${sgt}    ${prefixes}
     Post To Controller    ${session}    add-domain    ${data}
 
 Delete Domain
@@ -267,13 +288,13 @@ Delete Domain
 Add Bindings Range
     [Arguments]    ${sgt}    ${start}    ${size}    ${node}=127.0.0.1
     [Documentation]    Add Bindings to Node specified by range
-    ${prefixes} =    BuiltIn.Prefix Range    ${start}    ${size}
+    ${prefixes} =    Sxp.Prefix Range    ${start}    ${size}
     Add Bindings    ${sgt}    ${prefixes}    ${node}
 
 Delete Bindings Range
     [Arguments]    ${sgt}    ${start}    ${size}    ${node}=127.0.0.1
     [Documentation]    Delete Bindings to Node specified by range
-    ${prefixes} =    BuiltIn.Prefix Range    ${start}    ${size}
+    ${prefixes} =    Sxp.Prefix Range    ${start}    ${size}
     Delete Bindings    ${sgt}    ${prefixes}    ${node}
 
 Check Binding Range
@@ -293,30 +314,44 @@ Check Binding Range Negative
     \    Should Not Contain Binding    ${resp}    ${sgt}    ${ip}/32
 
 Setup SXP Environment
-    [Arguments]    ${node_range}=2
-    [Documentation]    Create session to Controller, node_range parameter specifies number of nodes to be created plus one
-    Setup SXP Session
-    : FOR    ${num}    IN RANGE    1    ${node_range}
-    \    ${ip} =    Sxp.Get Ip From Number    ${num}
+    [Arguments]    ${node_range}=1
+    [Documentation]    Create session to Controller, ${node_range} parameter specifies number of localhost nodes to be created on ${ODL_SYSTEM_IP}.
+    RequestsLibrary.Create Session    session    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}    timeout=${DEFAULT_TIMEOUT_HTTP}    max_retries=0
+    : FOR    ${num}    IN RANGE    1    ${node_range}+1
+    \    ${node} =    Sxp.Get Ip From Number    ${num}
     \    ${rnd_retry_time} =    BuiltIn.Evaluate    random.randint(1, 10)    modules=random
-    \    Add Node    ${ip}    retry_open_timer=${rnd_retry_time}
-    \    BuiltIn.Wait Until Keyword Succeeds    20    1    Check Node Started    ${ip}
+    \    Add Node    ${node}    retry_open_timer=${rnd_retry_time}
+    \    BuiltIn.Wait Until Keyword Succeeds    20    1    Check Node Started    ${node}    system=${ODL_SYSTEM_IP}
 
 Check Node Started
-    [Arguments]    ${node}    ${port}=64999    ${system}=${ODL_SYSTEM_IP}    ${session}=session    ${ip}=${node}
-    [Documentation]    Verify that SxpNode has data writed to Operational datastore
+    [Arguments]    ${node}    ${port}=64999    ${system}=${node}    ${session}=session    ${ip}=${node}
+    [Documentation]    Verify that SxpNode has data writen to Operational datastore and is running
     ${resp} =    RequestsLibrary.Get Request    ${session}    /restconf/operational/network-topology:network-topology/topology/sxp/node/${node}/
     BuiltIn.Should Be Equal As Strings    ${resp.status_code}    200
-    ${rc} =    Utils.Run Command On Remote System    ${system}    netstat -tln | grep -q ${ip}:${port} && echo 0 || echo 1    ${ODL_SYSTEM_USER}    ${ODL_SYSTEM_PASSWORD}    prompt=${ODL_SYSTEM_PROMPT}
+    ${rc} =    Get Node Running Status    ${node}    ${port}    ${system}    ${session}    ${ip}
     BuiltIn.Should Be Equal As Strings    ${rc}    0
 
+Check Node Stopped
+    [Arguments]    ${node}    ${port}=64999    ${system}=${node}    ${session}=session    ${ip}=${node}
+    [Documentation]    Verify that SxpNode has data removed from Operational datastore and is not running
+    ${resp} =    RequestsLibrary.Get Request    ${session}    /restconf/operational/network-topology:network-topology/topology/sxp/node/${node}/
+    BuiltIn.Should Be Equal As Strings    ${resp.status_code}    404
+    ${rc} =    Get Node Running Status    ${node}    ${port}    ${system}    ${session}    ${ip}
+    BuiltIn.Should Be Equal As Strings    ${rc}    1
+
+Get Node Running Status
+    [Arguments]    ${node}    ${port}    ${system}    ${session}    ${ip}
+    [Documentation]    Get status if node is running by checking that netty server is running
+    ${rc} =    Utils.Run Command On Remote System    ${system}    netstat -tln | grep -q ${ip}:${port} && echo 0 || echo 1    ${ODL_SYSTEM_USER}    ${ODL_SYSTEM_PASSWORD}    prompt=${ODL_SYSTEM_PROMPT}
+    [Return]    ${rc}
+
 Clean SXP Environment
-    [Arguments]    ${node_range}=2
+    [Arguments]    ${node_range}=1
     [Documentation]    Destroy created sessions
-    : FOR    ${num}    IN RANGE    1    ${node_range}
+    : FOR    ${num}    IN RANGE    1    ${node_range}+1
     \    ${ip} =    Sxp.Get Ip From Number    ${num}
     \    Delete Node    ${ip}
-    Clean SXP Session
+    RequestsLibrary.Delete All Sessions
 
 Get Routing Configuration From Controller
     [Arguments]    ${session}
@@ -329,6 +364,7 @@ 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}
+    BuiltIn.Log    ${resp}
     BuiltIn.Should Match    "${resp.status_code}"    "20?"
 
 Clean Routing Configuration To Controller