Remove entity-ownership from shard list for Phosphorus or later
[integration/test.git] / csit / libraries / SxpLib.robot
index ccf5c2011fbd84ba311c070215cdc9d9b07a6296..55d7166529f9db2bea2550fd7f41f5e46a24024f 100644 (file)
@@ -17,18 +17,18 @@ Post To Controller
     [Arguments]    ${session}    ${path}    ${data}    ${rest_context}=${REST_CONTEXT}
     [Documentation]    Post request to Controller and checks response
     ${resp} =    RequestsLibrary.Post Request    ${session}    ${rest_context}:${path}    data=${data}    headers=${HEADERS_XML}
-    Log    ${resp.content}
+    Log    ${resp.text}
     Log    ${session}
     Log    ${path}
     Log    ${data}
     BuiltIn.Should be Equal As Strings    ${resp.status_code}    200
-    ${content} =    BuiltIn.Evaluate    json.loads('''${resp.content}''')    json
+    ${content} =    BuiltIn.Evaluate    json.loads('''${resp.text}''')    json
     ${output} =    collections.Get From Dictionary    ${content}    output
     ${result} =    collections.Get From Dictionary    ${output}    result
     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}
@@ -55,7 +55,7 @@ Get Connections
     ${data} =    Sxp.Get Connections From Node Xml    ${node}    ${domain}
     ${resp} =    RequestsLibrary.Post Request    ${session}    ${REST_CONTEXT}:get-connections    data=${data}    headers=${HEADERS_XML}
     BuiltIn.Should be Equal As Strings    ${resp.status_code}    200
-    [Return]    ${resp.content}
+    [Return]    ${resp.text}
 
 Delete Connections
     [Arguments]    ${ip}    ${port}    ${node}=127.0.0.1    ${session}=session    ${domain}=global
@@ -68,8 +68,9 @@ Clean Connections
     [Documentation]    Delete all connections via RPC from node
     ${resp} =    Get Connections    ${node}    ${session}    ${domain}
     @{connections} =    Sxp.Parse Connections    ${resp}
-    : FOR    ${connection}    IN    @{connections}
-    \    Delete Connections    ${connection['peer-address']}    ${connection['tcp-port']}    ${node}    ${session}    ${domain}
+    FOR    ${connection}    IN    @{connections}
+        Delete Connections    ${connection['peer-address']}    ${connection['tcp-port']}    ${node}    ${session}    ${domain}
+    END
 
 Verify Connection
     [Arguments]    ${version}    ${mode}    ${ip}    ${port}=64999    ${node}=127.0.0.1    ${state}=on
@@ -109,10 +110,11 @@ Clean Bindings
     [Documentation]    Delete all bindings via RPC from Master DB of node
     ${resp} =    Get Bindings    ${node}    ${session}    ${domain}    ${scope}
     @{bindings} =    Sxp.Parse Bindings    ${resp}
-    : FOR    ${binding}    IN    @{bindings}
-    \    @{prefixes_list} =    collections.Get From Dictionary    ${binding}    ip-prefix
-    \    ${prefixes} =    BuiltIn.Catenate    SEPARATOR=,    @{prefixes_list}
-    \    Delete Bindings    ${binding['sgt']}    ${prefixes}    ${node}    ${domain}    ${session}
+    FOR    ${binding}    IN    @{bindings}
+        @{prefixes_list} =    collections.Get From Dictionary    ${binding}    ip-prefix
+        ${prefixes} =    BuiltIn.Catenate    SEPARATOR=,    @{prefixes_list}
+        Delete Bindings    ${binding['sgt']}    ${prefixes}    ${node}    ${domain}    ${session}
+    END
 
 Delete Bindings
     [Arguments]    ${sgt}    ${prefixes}    ${node}=127.0.0.1    ${domain}=global    ${session}=session
@@ -138,23 +140,36 @@ Get Peer Groups
     ${data} =    Sxp.Get Peer Groups From Node Xml    ${node}
     ${resp} =    RequestsLibrary.Post Request    ${session}    ${REST_CONTEXT}:get-peer-groups    data=${data}    headers=${HEADERS_XML}
     BuiltIn.Should be Equal As Strings    ${resp.status_code}    200
-    [Return]    ${resp.content}
+    [Return]    ${resp.text}
 
 Clean Peer Groups
     [Arguments]    ${node}=127.0.0.1    ${session}=session
     [Documentation]    Delete all PeerGroups via RPC from node
     ${resp} =    Get Peer Groups    ${node}    ${session}
     @{prefixes} =    Sxp.Parse Peer Groups    ${resp}
-    : FOR    ${group}    IN    @{prefixes}
-    \    Delete Peer Group    ${group['name']}    ${node}    ${session}
+    FOR    ${group}    IN    @{prefixes}
+        Delete Peer Group    ${group['name']}    ${node}    ${session}
+    END
 
 Add Filter
     [Arguments]    ${name}    ${type}    ${entries}    ${node}=127.0.0.1    ${session}=session    ${policy}=auto-update
     [Documentation]    Add Filter via RPC from Node
+    ${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
@@ -191,7 +206,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
@@ -226,17 +241,18 @@ Connections Should Not Contain
 
 Setup Topology Complex
     [Arguments]    ${version}=version4    ${password}=none
-    : FOR    ${node}    IN RANGE    2    6
-    \    Add Connection    ${version}    both    127.0.0.1    64999    127.0.0.${node}
-    \    ...    ${password}
-    \    Add Connection    ${version}    both    127.0.0.${node}    64999    127.0.0.1
-    \    ...    ${password}
-    \    BuiltIn.Wait Until Keyword Succeeds    15    1    Verify Connection    ${version}    both
-    \    ...    127.0.0.${node}
-    \    Add Bindings    ${node}0    10.10.10.${node}0/32    127.0.0.${node}
-    \    Add Bindings    ${node}0    10.10.${node}0.0/24    127.0.0.${node}
-    \    Add Bindings    ${node}0    10.${node}0.0.0/16    127.0.0.${node}
-    \    Add Bindings    ${node}0    ${node}0.0.0.0/8    127.0.0.${node}
+    FOR    ${node}    IN RANGE    2    6
+        Add Connection    ${version}    both    127.0.0.1    64999    127.0.0.${node}
+        ...    ${password}
+        Add Connection    ${version}    both    127.0.0.${node}    64999    127.0.0.1
+        ...    ${password}
+        BuiltIn.Wait Until Keyword Succeeds    15    1    Verify Connection    ${version}    both
+        ...    127.0.0.${node}
+        Add Bindings    ${node}0    10.10.10.${node}0/32    127.0.0.${node}
+        Add Bindings    ${node}0    10.10.${node}0.0/24    127.0.0.${node}
+        Add Bindings    ${node}0    10.${node}0.0.0/16    127.0.0.${node}
+        Add Bindings    ${node}0    ${node}0.0.0.0/8    127.0.0.${node}
+    END
     Add Bindings    10    10.10.10.10/32    127.0.0.1
     Add Bindings    10    10.10.10.0/24    127.0.0.1
     Add Bindings    10    10.10.0.0/16    127.0.0.1
@@ -248,10 +264,6 @@ 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
 
-Clean SXP Session
-    [Documentation]    Destroy created sessions
-    RequestsLibrary.Delete All Sessions
-
 Add Domain
     [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)
@@ -293,55 +305,74 @@ Check Binding Range
     [Arguments]    ${sgt}    ${start}    ${end}    ${node}=127.0.0.1
     [Documentation]    Check if Node contains Bindings specified by range
     ${resp} =    Get Bindings    ${node}
-    : FOR    ${num}    IN RANGE    ${start}    ${end}
-    \    ${ip} =    Sxp.Get Ip From Number    ${num}
-    \    Should Contain Binding    ${resp}    ${sgt}    ${ip}/32
+    FOR    ${num}    IN RANGE    ${start}    ${end}
+        ${ip} =    Sxp.Get Ip From Number    ${num}
+        Should Contain Binding    ${resp}    ${sgt}    ${ip}/32
+    END
 
 Check Binding Range Negative
     [Arguments]    ${sgt}    ${start}    ${end}    ${node}=127.0.0.1
     [Documentation]    Check if Node does not contains Bindings specified by range
     ${resp} =    Get Bindings    ${node}
-    : FOR    ${num}    IN RANGE    ${start}    ${end}
-    \    ${ip} =    Sxp.Get Ip From Number    ${num}
-    \    Should Not Contain Binding    ${resp}    ${sgt}    ${ip}/32
+    FOR    ${num}    IN RANGE    ${start}    ${end}
+        ${ip} =    Sxp.Get Ip From Number    ${num}
+        Should Not Contain Binding    ${resp}    ${sgt}    ${ip}/32
+    END
 
 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}
-    \    ${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}
+    [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}
+        Add Node    ${node}    retry_open_timer=${num}
+        BuiltIn.Wait Until Keyword Succeeds    20    1    Check Node Started    ${node}    system=${ODL_SYSTEM_IP}
+    END
 
 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}
-    \    ${ip} =    Sxp.Get Ip From Number    ${num}
-    \    Delete Node    ${ip}
-    Clean SXP Session
+    FOR    ${num}    IN RANGE    1    ${node_range}+1
+        ${ip} =    Sxp.Get Ip From Number    ${num}
+        Delete Node    ${ip}
+        BuiltIn.Wait Until Keyword Succeeds    12x    10s    Check Node Stopped    ${ip}    system=${ODL_SYSTEM_IP}
+    END
+    RequestsLibrary.Delete All Sessions
 
 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} =    BuiltIn.Set Variable If    "${resp.status_code}" == "200"    ${resp.content}    ${EMPTY}
+    ${data} =    BuiltIn.Set Variable If    "${resp.status_code}" == "200"    ${resp.text}    ${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}
+    BuiltIn.Log    ${resp}
     BuiltIn.Should Match    "${resp.status_code}"    "20?"
 
 Clean Routing Configuration To Controller