From 0fb5ff3cd81cc5810c49ea2aeafb05a1e8cc1c8c Mon Sep 17 00:00:00 2001 From: Ivan Hrasko Date: Wed, 24 Oct 2018 16:27:30 +0200 Subject: [PATCH] SXP: Add RPC redirecting tests Change-Id: Iad37cee3c72b4add1c477c3fe7149e8781fa6e2d Signed-off-by: Ivan Hrasko --- csit/libraries/Sxp.py | 8 +- csit/libraries/SxpBindingOriginsLib.robot | 15 +-- csit/libraries/SxpClusterLib.robot | 10 ++ csit/libraries/SxpLib.robot | 14 ++- .../sxp/clustering/040_RPC_Redirecting.robot | 98 +++++++++++++++++++ 5 files changed, 136 insertions(+), 9 deletions(-) create mode 100644 csit/suites/sxp/clustering/040_RPC_Redirecting.robot diff --git a/csit/libraries/Sxp.py b/csit/libraries/Sxp.py index 644eae7387..4aaf3b094f 100644 --- a/csit/libraries/Sxp.py +++ b/csit/libraries/Sxp.py @@ -996,7 +996,13 @@ def delete_domain_xml(node_id, name): :returns: String containing xml data for request """ - return add_domain_xml(node_id, name) + templ = Template(''' + $node_id + $name +''') + + data = templ.substitute({'node_id': node_id, 'name': name}) + return data def get_domain_name(domain_name): diff --git a/csit/libraries/SxpBindingOriginsLib.robot b/csit/libraries/SxpBindingOriginsLib.robot index 558d3bf90b..ba299f06fc 100644 --- a/csit/libraries/SxpBindingOriginsLib.robot +++ b/csit/libraries/SxpBindingOriginsLib.robot @@ -4,14 +4,15 @@ Library ./Sxp.py Resource ./SxpLib.robot *** Variables *** -${REST_CONTEXT} /restconf/operations/sxp-config-controller +${CONFIG_REST_CONTEXT} /restconf/operations/sxp-config-controller *** Keywords *** Revert To Default Binding Origins Configuration + [Arguments] ${session}=session [Documentation] Remove CLUSTER binding origin and set default priorities to default origins - BuiltIn.Run Keyword And Ignore Error SxpBindingOriginsLib.Delete Binding Origin CLUSTER - BuiltIn.Run Keyword And Ignore Error SxpBindingOriginsLib.Update Binding Origin LOCAL 1 - BuiltIn.Run Keyword And Ignore Error SxpBindingOriginsLib.Update Binding Origin NETWORK 2 + BuiltIn.Run Keyword And Ignore Error SxpBindingOriginsLib.Delete Binding Origin CLUSTER session=${session} + BuiltIn.Run Keyword And Ignore Error SxpBindingOriginsLib.Update Binding Origin LOCAL 1 session=${session} + BuiltIn.Run Keyword And Ignore Error SxpBindingOriginsLib.Update Binding Origin NETWORK 2 session=${session} Get Binding Origins [Arguments] ${session}=session @@ -24,19 +25,19 @@ Add Binding Origin [Arguments] ${origin} ${priority} ${session}=session [Documentation] Add custom binding origin to configuration ${data} = Sxp.Add Binding Origin Xml ${origin} ${priority} - SxpLib.Post To Controller ${session} add-binding-origin ${data} ${REST_CONTEXT} + SxpLib.Post To Controller ${session} path=add-binding-origin data=${data} rest_context=${CONFIG_REST_CONTEXT} Update Binding Origin [Arguments] ${origin} ${priority} ${session}=session [Documentation] Update binding origin in configuration ${data} = Sxp.Update Binding Origin Xml ${origin} ${priority} - SxpLib.Post To Controller ${session} update-binding-origin ${data} ${REST_CONTEXT} + SxpLib.Post To Controller ${session} path=update-binding-origin data=${data} rest_context=${CONFIG_REST_CONTEXT} Delete Binding Origin [Arguments] ${origin} ${session}=session [Documentation] Delete custom binding origin from configuration ${data} = Sxp.Delete Binding Origin Xml ${origin} - SxpLib.Post To Controller ${session} delete-binding-origin ${data} ${REST_CONTEXT} + SxpLib.Post To Controller ${session} path=delete-binding-origin data=${data} rest_context=${CONFIG_REST_CONTEXT} Should Contain Binding Origins [Arguments] @{origins} diff --git a/csit/libraries/SxpClusterLib.robot b/csit/libraries/SxpClusterLib.robot index 6a3562a4e0..36a069f8e8 100644 --- a/csit/libraries/SxpClusterLib.robot +++ b/csit/libraries/SxpClusterLib.robot @@ -77,6 +77,16 @@ Check Cluster Node started \ ${started} = BuiltIn.Set Variable If '${rc}' == '0' ${True} ${started} BuiltIn.Should Be True ${started} +Check Cluster Node stopped + [Arguments] ${node} ${port}=64999 ${ip}=${node} + [Documentation] Verify that SxpNode has data removed from Operational datastore and Node is stopped + ${stopped} = BuiltIn.Set Variable ${False} + : FOR ${i} IN RANGE ${NUM_ODL_SYSTEM} + \ ${rc} = Utils.Run Command On Remote System ${ODL_SYSTEM_${i+1}_IP} netstat -tln | grep -q ${ip}:${port} && echo 0 || echo 1 ${ODL_SYSTEM_USER} ${ODL_SYSTEM_PASSWORD} + \ ... prompt=${ODL_SYSTEM_PROMPT} + \ ${stopped} = BuiltIn.Set Variable If '${rc}' == '1' ${True} ${stopped} + BuiltIn.Should Be True ${stopped} + Check Device is Connected [Arguments] ${node} ${version}=version4 ${port}=64999 ${session}=session [Documentation] Checks if SXP device is connected to the cluster. It means it has connection in state "on" with one of the cluster members. diff --git a/csit/libraries/SxpLib.robot b/csit/libraries/SxpLib.robot index da4e5d4bb1..b3a29a1d13 100644 --- a/csit/libraries/SxpLib.robot +++ b/csit/libraries/SxpLib.robot @@ -151,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} = 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 diff --git a/csit/suites/sxp/clustering/040_RPC_Redirecting.robot b/csit/suites/sxp/clustering/040_RPC_Redirecting.robot new file mode 100644 index 0000000000..9ac8048413 --- /dev/null +++ b/csit/suites/sxp/clustering/040_RPC_Redirecting.robot @@ -0,0 +1,98 @@ +*** Settings *** +Documentation SXP holds active SXP nodes only on the cluster owner node. Active SXP node holds its master database and datastore access. This implies that all RPC operation logic must be executed only on cluster owner node. In case RPC is send to another cluster node it must be redirected to owner to be properly executed. This suite contains tests for SxpControllerService and SxpConfigControllerService RPCs. +Suite Setup SxpClusterLib.Setup SXP Cluster Session +Suite Teardown SxpClusterLib.Clean SXP Cluster Session +Library ../../../libraries/Common.py +Resource ../../../libraries/SxpBindingOriginsLib.robot +Resource ../../../libraries/SxpClusterLib.robot +Resource ../../../libraries/SxpLib.robot + +*** Test Cases *** +Test Add/Delete Node + [Documentation] Adding and then deleting SXP node is sucessfull only if all operations are done on cluster owner node. To verify that all RPCs are redirected to cluster owner send add-node RPC to the first cluster node and delete-node RPC to the second cluster node (requires datastore access). + [Tags] SXP Clustering Redirecting + SxpLib.Add Node ${INADDR_ANY} session=ClusterManagement__session_1 + BuiltIn.Wait Until Keyword Succeeds 1m 1x SxpClusterLib.Check Cluster Node started ${INADDR_ANY} ip=${EMPTY} + SxpLib.Delete Node ${INADDR_ANY} session=ClusterManagement__session_2 + BuiltIn.Wait Until Keyword Succeeds 1m 1x SxpClusterLib.Check Cluster Node stopped ${INADDR_ANY} ip=${EMPTY} + +Test Add/Delete Binding + [Documentation] Adding and then deleting binding from a SXP node is sucessfull only if all operations are done on cluster owner node. To verify that all RPCs are redirected to cluster owner send add-node RPC to the first cluster node, add-bindings RPC to the second cluster node (requires master database) and delete-bindings RPC to the third cluster node (requires master database). + [Tags] SXP Clustering Redirecting + Add Node And Check It Is Started + SxpLib.Add Bindings 1100 1.1.1.1/32 node=${INADDR_ANY} session=ClusterManagement__session_2 + SxpLib.Delete Bindings 1100 1.1.1.1/32 node=${INADDR_ANY} session=ClusterManagement__session_3 + [Teardown] Delete Node And Check It Is Stopped + +Test Add/Delete Domain + [Documentation] Adding and then deleting domain from a SXP node is sucessfull only if all operations are done on cluster owner node. To verify that all RPCs are redirected to cluster owner send add-node RPC to the first cluster node, add-domain RPC to the second cluster node (requires datastore access and master database) and delete-domain RPC to the third cluster node (requires datastore access). + [Tags] SXP Clustering Redirecting + Add Node And Check It Is Started + SxpLib.Add Domain cluster node=${INADDR_ANY} session=ClusterManagement__session_2 + SxpLib.Delete Domain cluster node=${INADDR_ANY} session=ClusterManagement__session_3 + [Teardown] Delete Node And Check It Is Stopped + +Test Add/Delete Connection + [Documentation] Adding and then deleting connection from a SXP node is sucessfull only if all operations are done on cluster owner node. To verify that all RPCs are redirected to cluster owner send add-node RPC to the first cluster node, add-connection RPC to the second cluster node (requires datastore access) and delete-connection RPC to the third cluster node (requires datastore access). + [Tags] SXP Clustering Redirecting + Add Node And Check It Is Started + SxpLib.Add Connection version4 listener ${INADDR_ANY} 64999 node=${INADDR_ANY} session=ClusterManagement__session_1 + SxpLib.Delete Connections ${INADDR_ANY} 64999 node=${INADDR_ANY} session=ClusterManagement__session_2 + [Teardown] Delete Node And Check It Is Stopped + +Test Add/Delete Peer Group + [Documentation] Adding and then deleting peer group from a SXP node is sucessfull only if all operations are done on cluster owner node. To verify that all RPCs are redirected to cluster owner send add-peer-group RPC to the first cluster node, get-peer-groups RPC to the second cluster node (requires datastore access) and delete-peer-group RPC to the third cluster node (requires datastore access). + [Tags] SXP Clustering Redirecting + [Setup] Add Node And Check It Is Started + SxpLib.Add PeerGroup GROUP peers=${EMPTY} node=${INADDR_ANY} session=ClusterManagement__session_1 + ${resp} = SxpLib.Get Peer Groups ${INADDR_ANY} session=ClusterManagement__session_2 + @{groups} = Sxp.Parse Peer Groups ${resp} + : FOR ${group} IN @{groups} + \ SxpLib.Delete Peer Group ${group['name']} node=${INADDR_ANY} session=ClusterManagement__session_3 + [Teardown] Delete Node And Check It Is Stopped + +Test Add/Delete Domain Filter + [Documentation] Adding and then deleting domain filter from a SXP node is sucessfull only if all operations are done on cluster owner node. To verify that all RPCs are redirected to cluster owner send add-domain-filter RPC to the first cluster node and delete-domain-filter RPC to the second cluster node (requires datastore access). + [Tags] SXP Clustering Redirecting + [Setup] Add Node And Check It Is Started + ${domain_1_xml} = Sxp.Add Domains domain-1 + ${domain_2_xml} = Sxp.Add Domains domain-2 + ${domains} = Common.Combine Strings ${domain_1_xml} ${domain_2_xml} + ${entry} = Sxp.Get Filter Entry 10 permit pl=20.0.0.0/8 + ${entries} = Common.Combine Strings ${entry} + SxpLib.Add Domain Filter global ${domains} ${entries} node=${INADDR_ANY} session=ClusterManagement__session_1 + SxpLib.Delete Domain Filter global node=${INADDR_ANY} session=ClusterManagement__session_2 + [Teardown] Delete Node And Check It Is Stopped + +Test Add/Delete Filter + [Documentation] Adding, updating and then deleting filter from a SXP node is sucessfull only if all operations are done on cluster owner node. To verify that all RPCs are redirected to cluster owner send add-filter RPC to the first cluster node, update-filter RPC to the second cluster node (requires datastore access) and delete-filter RPC to the third cluster node (requires datastore access). + [Tags] SXP Clustering Redirecting + [Setup] Add Node And Check It Is Started + ${entry1} = Sxp.Get Filter Entry 10 deny pl=10.10.20.0/24 + ${entry2} = Sxp.Get Filter Entry 20 permit epl=10.10.0.0/16,le,24 + ${entry3} = Sxp.Get Filter Entry 30 permit sgt=30 pl=10.10.10.0/24 + ${entries} = Common.Combine Strings ${entry1} ${entry2} ${entry3} + SxpLib.Add PeerGroup GROUP peers=${EMPTY} node=${INADDR_ANY} session=${CONTROLLER_SESSION} + SxpLib.Add Filter GROUP outbound ${entries} node=${INADDR_ANY} policy=manual-update session=ClusterManagement__session_1 + SxpLib.Update Filter GROUP outbound ${entries} node=${INADDR_ANY} policy=manual-update session=ClusterManagement__session_2 + SxpLib.Delete Filter GROUP outbound node=${INADDR_ANY} session=ClusterManagement__session_3 + [Teardown] Delete Node And Check It Is Stopped + +Test Add/Update/Delete Binding Origin + [Documentation] Binding origin operations need to be executed on cluster owner because they rely on static map which is present solely on cluster owner. To test that binding origin RPCs are redirected to cluster owner first add binding origin to the first node then update it on the second node (requires up-to date binding origin map) and update it on the third node (requires up-to date binding origin map). + [Tags] SXP Clustering Redirecting + SxpBindingOriginsLib.Add Binding Origin CLUSTER 0 session=ClusterManagement__session_1 + SxpBindingOriginsLib.Update Binding Origin CLUSTER 3 session=ClusterManagement__session_2 + SxpBindingOriginsLib.Delete Binding Origin CLUSTER session=ClusterManagement__session_3 + [Teardown] SxpBindingOriginsLib.Revert To Default Binding Origins Configuration session=${CONTROLLER_SESSION} + +*** Keywords *** +Add Node And Check It Is Started + [Documentation] Send add-node RPC to the first cluster member and check if node has been started. + SxpLib.Add Node ${INADDR_ANY} session=ClusterManagement__session_1 + BuiltIn.Wait Until Keyword Succeeds 1m 1x SxpClusterLib.Check Cluster Node started ${INADDR_ANY} ip=${EMPTY} + +Delete Node And Check It Is Stopped + [Documentation] Send delete-node RPC to the first cluster member and check if node has been stopped. + SxpLib.Delete Node ${INADDR_ANY} session=ClusterManagement__session_1 + BuiltIn.Wait Until Keyword Succeeds 1m 1x SxpClusterLib.Check Cluster Node stopped ${INADDR_ANY} ip=${EMPTY} -- 2.36.6