From: Ivan Hrasko Date: Mon, 16 Jul 2018 13:41:50 +0000 (+0200) Subject: SXP: Add tests for binding origins checks X-Git-Tag: pre-potassium~633 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=7bb03d4fc68b79e1213544104fe51ca443fc61ab;hp=ff3688d31959c081dc25fd7a0db4176e50646072;p=integration%2Ftest.git SXP: Add tests for binding origins checks - verify that origin priority checks are evaluated when using RPCs - incoming higher priority binding must override lower priority binding - but lower priority binding cannot override higher priority binding Change-Id: Ie6ed021854e6f3791352a3af24c68134b9eac65f Signed-off-by: Ivan Hrasko --- diff --git a/csit/libraries/Sxp.py b/csit/libraries/Sxp.py index 59a8339d65..33b317fced 100644 --- a/csit/libraries/Sxp.py +++ b/csit/libraries/Sxp.py @@ -902,21 +902,44 @@ def delete_node_xml(node_id): return data -def add_domain_xml(node_id, name): +def add_domain_xml(node_id, name, sgt, prefixes, origin): """Generate xml for Add Domain request :param node_id: Id of node :type node_id: str :param name: Name of Domain :type name: str + :param sgt: Security group + :type sgt: int + :param prefixes: List of ip-prefixes + :type prefixes: str + :param origin: Origin of added bindings + :type origin: str :returns: String containing xml data for request """ - templ = Template(''' - $id - $name + bindings = '' + for prefix in prefixes.split(','): + bindings += '\n' + '' + prefix + '' + + master_database = '' + if bindings: + master_database += ''' + + $sgt + $bindings + + ''' + master_database = Template(master_database).substitute(({'sgt': sgt, 'bindings': bindings})) + + templ = Template(''' + $id + $name + $origin + $master_database ''') - data = templ.substitute({'name': name, 'id': node_id}) + + data = templ.substitute({'name': name, 'id': node_id, 'origin': origin, 'master_database': master_database}) return data @@ -947,7 +970,7 @@ def get_domain_name(domain_name): return '' + domain_name + '' -def add_bindings_xml(node_id, domain, sgt, prefixes): +def add_bindings_xml(node_id, domain, sgt, prefixes, origin): """Generate xml for Add Bindings request :param node_id: Id of node @@ -958,21 +981,26 @@ def add_bindings_xml(node_id, domain, sgt, prefixes): :type sgt: int :param prefixes: List of ip-prefixes :type prefixes: str + :param origin: Origin of added bindings + :type origin: str :returns: String containing xml data for request """ bindings = '' for prefix in prefixes.split(','): bindings += '\n' + '' + prefix + '' - templ = Template(''' - $id - $name - - $sgt - $bindings - + templ = Template(''' + $id + $name + $origin + + + $sgt + $bindings + + ''') - data = templ.substitute({'name': domain, 'id': node_id, 'sgt': sgt, 'bindings': bindings}) + data = templ.substitute({'name': domain, 'id': node_id, 'sgt': sgt, 'bindings': bindings, 'origin': origin}) return data @@ -990,7 +1018,19 @@ def delete_bindings_xml(node_id, domain, sgt, prefixes): :returns: String containing xml data for request """ - return add_bindings_xml(node_id, domain, sgt, prefixes) + bindings = '' + for prefix in prefixes.split(','): + bindings += '\n' + '' + prefix + '' + templ = Template(''' + $id + $name + + $sgt + $bindings + +''') + data = templ.substitute({'name': domain, 'id': node_id, 'sgt': sgt, 'bindings': bindings}) + return data def prefix_range(start, end): diff --git a/csit/libraries/SxpLib.robot b/csit/libraries/SxpLib.robot index 5d7dfeee4b..d74625150b 100644 --- a/csit/libraries/SxpLib.robot +++ b/csit/libraries/SxpLib.robot @@ -81,9 +81,9 @@ Verify Connection Should Contain Connection ${resp} ${ip} ${port} ${mode} ${version} ${state} Add Bindings - [Arguments] ${sgt} ${prefixes} ${node}=127.0.0.1 ${session}=session ${domain}=global + [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} Add Bindings Xml ${node} ${domain} ${sgt} ${prefixes} + ${DATA} Add Bindings Xml ${node} ${domain} ${sgt} ${prefixes} ${origin} Post To Controller ${session} add-bindings ${DATA} Get Bindings @@ -94,33 +94,17 @@ Get Bindings [Return] ${resp} Clean Bindings - [Arguments] ${node}=127.0.0.1 ${session}=session ${domain}=global + [Arguments] ${node}=127.0.0.1 ${session}=session ${domain}=global ${scope}=local [Documentation] Delete all bindings via RPC from Master DB of node - ${resp} Get Bindings ${node} ${session} ${domain} local + ${resp} Get Bindings ${node} ${session} ${domain} ${scope} @{bindings} Parse Bindings ${resp} : FOR ${binding} IN @{bindings} - \ Clean Binding Default ${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} - \ Delete Bindings ${sgt} ${prefix} ${node} ${domain} ${session} + \ Delete Bindings ${binding['sgt']} ${binding['ip-prefix']} ${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} Delete Bindings Xml ${node} ${domain} ${sgt} ${prefixes} + ${DATA} Delete Bindings Xml ${node} ${domain} ${sgt} @{prefixes} Post To Controller ${session} delete-bindings ${DATA} Add PeerGroup @@ -178,13 +162,13 @@ Delete Domain Filter Post To Controller ${session} delete-domain-filter ${DATA} Should Contain Binding - [Arguments] ${resp} ${sgt} ${prefix} ${db_source}=any + [Arguments] ${resp} ${sgt} ${prefix} [Documentation] Tests if data contains specified binding ${out} Find Binding ${resp} ${sgt} ${prefix} Should Be True ${out} Doesn't have ${sgt} ${prefix} Should Not Contain Binding - [Arguments] ${resp} ${sgt} ${prefix} ${db_source}=any + [Arguments] ${resp} ${sgt} ${prefix} [Documentation] Tests if data doesn't contains specified binding ${out} Find Binding ${resp} ${sgt} ${prefix} Should Not Be True ${out} Should't have ${sgt} ${prefix} @@ -204,16 +188,16 @@ Should Not Contain Connection Should Not Be True ${out} Shouldn't have ${ip}:${port} ${mode} ${version} Bindings Should Contain - [Arguments] ${sgt} ${prefix} ${db_source}=any + [Arguments] ${sgt} ${prefix} ${domain}=global ${scope}=all [Documentation] Retrieves bindings and verifies they contain given binding - ${resp} Get Bindings - Should Contain Binding ${resp} ${sgt} ${prefix} ${db_source} + ${resp} Get Bindings domain=${domain} scope=${scope} + Should Contain Binding ${resp} ${sgt} ${prefix} Bindings Should Not Contain - [Arguments] ${sgt} ${prefix} ${db_source}=any + [Arguments] ${sgt} ${prefix} ${domain}=global ${scope}=all [Documentation] Retrieves bindings and verifies they do not contain given binding - ${resp} Get Bindings - Should Not Contain Binding ${resp} ${sgt} ${prefix} ${db_source} + ${resp} Get Bindings domain=${domain} scope=${scope} + Should Not Contain Binding ${resp} ${sgt} ${prefix} Connections Should Contain [Arguments] ${ip} ${port} ${mode} ${version} ${state}=none @@ -272,9 +256,9 @@ Clean SXP Session Delete All Sessions Add Domain - [Arguments] ${domain_name} ${node}=127.0.0.1 ${session}=session - [Documentation] Add Domain via RPC - ${DATA} Add Domain Xml ${node} ${domain_name} + [Arguments] ${domain_name} ${sgt}=None ${prefixes}='' ${origin}=LOCAL ${node}=127.0.0.1 ${session}=session + [Documentation] Add Domain with bindings via RPC + ${DATA} Add Domain Xml ${node} ${domain_name} ${sgt} ${prefixes} ${origin} Post To Controller ${session} add-domain ${DATA} Delete Domain diff --git a/csit/suites/sxp/binding-origin/020_Binding_Origins_Checks.robot b/csit/suites/sxp/binding-origin/020_Binding_Origins_Checks.robot new file mode 100644 index 0000000000..d766c6015d --- /dev/null +++ b/csit/suites/sxp/binding-origin/020_Binding_Origins_Checks.robot @@ -0,0 +1,100 @@ +*** Settings *** +Documentation Test suite to verify binding origins checks are performed in master database +Suite Setup Create Session And Node +Suite Teardown Delete Node And Close Session +Test Setup Clean Bindings +Library RequestsLibrary +Resource ../../../libraries/SxpLib.robot + +*** Test Cases *** +Test Add Lower Priority Binding + [Documentation] Test that incoming binding with lower priority does not override already existing + ... higher priority binding in master database for the same IP prefix + [Tags] Binding Origins Checks SXP + BuiltIn.Comment Add binding + SxpLib.Add Bindings 10 1.1.1.1/32 LOCAL + BuiltIn.Comment Try to add binding with lower priority + BuiltIn.Run Keyword And Expect Error RPC result is False SxpLib.Add Bindings 20 1.1.1.1/32 NETWORK + BuiltIn.Comment Verify that new binding is not added and previous binding is preserved + Verify Bindings Content 10 20 1.1.1.1/32 + +Test Add Higher Priority Binding + [Documentation] Test that incoming binding with higher priority overrides already existing + ... lower priority binding in master database for the same IP prefix + [Tags] Binding Origins Checks SXP + BuiltIn.Comment Add binding + SxpLib.Add Bindings 10 1.1.1.1/32 NETWORK + BuiltIn.Comment Add binding with higher priority + SxpLib.Add Bindings 20 1.1.1.1/32 LOCAL + BuiltIn.Comment Verify that new binding replaced previous binding + Verify Bindings Content 20 10 1.1.1.1/32 + +Test Add Unknown Priority Binding + [Documentation] Test that incoming binding with unknown priority cannot be added to master database + [Tags] Binding Origins Checks SXP + BuiltIn.Comment Try to add binding with unknown origin priority + BuiltIn.Run Keyword And Expect Error 400 != 200 SxpLib.Add Bindings 10 1.1.1.1/32 CLUSTER + BuiltIn.Comment Verify that binding is not in master database + SxpLib.Bindings Should Not Contain 10 1.1.1.1/32 + +Test Add Lower Priority Binding To Domain + [Documentation] Test that incoming binding with lower priority does not override already existing + ... higher priority binding in master database for the same IP prefix + BuiltIn.Comment Create custom domain with binding + SxpLib.Add Domain guest 10 1.1.1.1/32 LOCAL + BuiltIn.Comment Try add binding to custom domain with lower priority + BuiltIn.Run Keyword And Expect Error RPC result is False SxpLib.Add Bindings 20 1.1.1.1/32 NETWORK domain=guest + BuiltIn.Comment Verify that new binding is not added and previous binding is preserved + Verify Bindings Content 10 20 1.1.1.1/32 guest + +Test Add Higher Priority Binding To Domain + [Documentation] Test that incoming binding with lower priority does not override already existing + ... higher priority binding in master database for the same IP prefix + BuiltIn.Comment Create custom domain with binding + SxpLib.Add Domain guest 10 1.1.1.1/32 NETWORK + BuiltIn.Comment Add binding to custom domain with higher priority + SxpLib.Add Bindings 20 1.1.1.1/32 LOCAL domain=guest + BuiltIn.Comment Verify that new binding replaced previous binding + Verify Bindings Content 20 10 1.1.1.1/32 guest + +Test Get Bindings + [Documentation] Test that when requesting for LOCAL bindings then only LOCAL bindings are returned + BuiltIn.Comment Add LOCAL binding + SxpLib.Add Bindings 10 1.1.1.1/32 LOCAL + BuiltIn.Comment Add NETWORK binding + SxpLib.Add Bindings 20 2.2.2.2/32 NETWORK + BuiltIn.Comment Verify request for LOCAL bindings + Verify Local Bindings Content 10 1.1.1.1/32 20 2.2.2.2/32 + BuiltIn.Comment Verify request for ALL bindings + Verify All Bindings Content 10 1.1.1.1/32 20 2.2.2.2/32 + +*** Keywords *** +Create Session And Node + RequestsLibrary.Create Session session http://${ODL_SYSTEM_IP}:${RESTCONFPORT} auth=${AUTH} headers=${HEADERS_XML} + SxpLib.Setup SXP Environment + +Delete Node And Close Session + SxpLib.Clean SXP Environment + RequestsLibrary.Delete All Sessions + +Clean Bindings + SxpLib.Clean Bindings scope=all + SxpLib.Clean Bindings domain=guest scope=all + +Verify Bindings Content + [Arguments] ${should_contains_sgt} ${should_not_contains_sgt} ${prefix} ${domain}=global + ${bindings} = SxpLib.Get Bindings domain=${domain} scope=all + SxpLib.Should Contain Binding ${bindings} ${should_contains_sgt} ${prefix} + SxpLib.Should Not Contain Binding ${bindings} ${should_not_contains_sgt} ${prefix} + +Verify Local Bindings Content + [Arguments] ${local_sgt} ${local_prefix} ${network_sgt} ${network_prefix} + ${bindings} = SxpLib.Get Bindings scope=local + SxpLib.Should Contain Binding ${bindings} ${local_sgt} ${local_prefix} + SxpLib.Should Not Contain Binding ${bindings} ${network_sgt} ${network_prefix} + +Verify All Bindings Content + [Arguments] ${local_sgt} ${local_prefix} ${network_sgt} ${network_prefix} + ${bindings} = SxpLib.Get Bindings + SxpLib.Should Contain Binding ${bindings} ${local_sgt} ${local_prefix} + SxpLib.Should Contain Binding ${bindings} ${network_sgt} ${network_prefix}