''')
data = templ.substitute({'routes': routes})
return data
+
+
+def add_binding_origin_xml(origin, priority):
+ """Generate xml for Add Binding Origin request
+
+ :param origin: Origin type
+ :type origin: str
+ :param priority: Origin priority
+ :type priority: str
+ :returns: String containing xml data for request
+
+ """
+ templ = Template('''<input xmlns="urn:opendaylight:sxp:config:controller">
+ <origin>$origin</origin>
+ <priority>$priority</priority>
+</input>''')
+ data = templ.substitute({'origin': origin, 'priority': priority})
+ return data
+
+
+def update_binding_origin_xml(origin, priority):
+ """Generate xml for Update Binding Origin request
+
+ :param origin: Origin type
+ :type origin: str
+ :param priority: Origin priority
+ :type priority: str
+ :returns: String containing xml data for request
+
+ """
+ templ = Template('''<input xmlns="urn:opendaylight:sxp:config:controller">
+ <origin>$origin</origin>
+ <priority>$priority</priority>
+</input>''')
+ data = templ.substitute({'origin': origin, 'priority': priority})
+ return data
+
+
+def delete_binding_origin_xml(origin):
+ """Generate xml for Delete Binding Origin request
+
+ :param origin: Origin type
+ :type origin: str
+ :returns: String containing xml data for request
+
+ """
+ templ = Template('''<input xmlns="urn:opendaylight:sxp:config:controller">
+ <origin>$origin</origin>
+</input>''')
+ data = templ.substitute({'origin': origin})
+ return data
+
+
+def find_binding_origin(origins_json, origin):
+ """Test if Binding origin of specified value is contained in JSON
+
+ :param origins_json: JSON containing Binding origins
+ :type origins_json: str
+ :param origin: Origin to be found
+ :type origin: str
+ :returns: True if Binding origin of specified origin type was found, otherwise False.
+
+ """
+ for json_origin in parse_binding_origins(origins_json):
+ if json_origin['origin'] == origin:
+ return True
+ return False
+
+
+def find_binding_origin_with_priority(origins_json, origin, priority):
+ """Test if Binding origin of specified value and priority is contained in JSON
+
+ :param origins_json: JSON containing Binding origins
+ :type origins_json: str
+ :param origin: Origin to be found
+ :type origin: str
+ :param priority: desired priority of origin
+ :type priority: str
+ :returns: True if Binding origin of specified origin type with desired priority was found, otherwise False.
+
+ """
+ for json_origin in parse_binding_origins(origins_json):
+ if json_origin['origin'] == origin:
+ if json_origin['priority'] == int(priority):
+ return True
+ return False
+
+
+def parse_binding_origins(origins_json):
+ """Parse JSON string into Array of Binding origins
+
+ :param origins_json: JSON containing Binding origins
+ :type origins_json: str
+ :returns: Array containing Binding origins.
+
+ """
+ output = []
+ for origins in origins_json['binding-origins'].values():
+ for origin in origins:
+ output.append(origin)
+ return output
--- /dev/null
+*** Settings ***
+Documentation Library containing Keywords used for SXP binding origins testing
+Library ./Sxp.py
+Resource ./SxpLib.robot
+
+*** Variables ***
+${REST_CONTEXT} /restconf/operations/sxp-config-controller
+
+*** Keywords ***
+Revert To Default Binding Origins Configuration
+ [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
+
+Get Binding Origins
+ [Arguments] ${session}=session
+ [Documentation] Gets all binding origins via RPC from configuration
+ ${resp} = RequestsLibrary.Get Request ${session} /restconf/config/sxp-config:binding-origins
+ BuiltIn.Should Be Equal As Strings ${resp.status_code} 200
+ [Return] ${resp}
+
+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}
+
+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}
+
+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}
+
+Should Contain Binding Origins
+ [Arguments] @{origins}
+ [Documentation] Test if data contain specified binding origins
+ ${resp} = SxpBindingOriginsLib.Get Binding Origins
+ : FOR ${origin} IN @{origins}
+ \ ${out} = Sxp.Find Binding Origin ${resp.json()} ${origin}
+ \ BuiltIn.Should Be True ${out} Missing origin: ${origin} in ${resp}
+
+Should Not Contain Binding Origins
+ [Arguments] @{origins}
+ [Documentation] Test if data DONT contain specified binding origins
+ ${resp} = SxpBindingOriginsLib.Get Binding Origins
+ : FOR ${origin} IN @{origins}
+ \ ${out} = Sxp.Find Binding Origin ${resp.json()} ${origin}
+ \ BuiltIn.Should Be Equal As Strings False ${out} Not expected origin: ${origin} in ${resp}
+
+Should Contain Binding Origin With Priority
+ [Arguments] ${origin} ${priority}
+ [Documentation] Test if data contain specified binding origin with desired priority
+ ${resp} = SxpBindingOriginsLib.Get Binding Origins
+ ${out} = Sxp.Find Binding Origin With Priority ${resp.json()} ${origin} ${priority}
+ BuiltIn.Should Be True ${out} Missing origin: ${origin} with priority: ${priority} in ${resp}
*** Keywords ***
Post To Controller
- [Arguments] ${session} ${path} ${DATA}
+ [Arguments] ${session} ${path} ${DATA} ${rest_context}=${REST_CONTEXT}
[Documentation] Post request to Controller and checks response
- ${resp} Post Request ${session} ${REST_CONTEXT}:${path} data=${DATA} headers=${HEADERS_XML}
+ ${resp} Post Request ${session} ${rest_context}:${path} data=${DATA} headers=${HEADERS_XML}
Log ${resp.content}
Log ${session}
Log ${path}
Log ${DATA}
Should be Equal As Strings ${resp.status_code} 200
${content} Evaluate json.loads('''${resp.content}''') json
- ${content} Get From Dictionary ${content} output
- ${content} Get From Dictionary ${content} result
- Should Be True ${content}
+ ${output} Get From Dictionary ${content} output
+ ${result} Get From Dictionary ${output} result
+ Should Be True ${result} RPC result is False
Add Node
[Arguments] ${node} ${password}=${EMPTY} ${version}=version4 ${port}=64999 ${session}=session ${ip}=${EMPTY}
--- /dev/null
+*** Settings ***
+Documentation Test suite to verify binding origins configuration possibilities (CRUD)
+Suite Setup RequestsLibrary.Create Session session http://${ODL_SYSTEM_IP}:${RESTCONFPORT} auth=${AUTH} headers=${HEADERS_XML}
+Suite Teardown RequestsLibrary.Delete All Sessions
+Test Setup SxpBindingOriginsLib.Revert To Default Binding Origins Configuration
+Library RequestsLibrary
+Resource ../../../libraries/SxpBindingOriginsLib.robot
+
+*** Variables ***
+@{DEFAULT_ORIGINS} LOCAL NETWORK
+@{CLUSTER} CLUSTER
+@{DEFAULT_AND_CLUSTER} LOCAL NETWORK CLUSTER
+
+*** Test Cases ***
+Test Add Binding Origin
+ [Documentation] Test if binding origin is added to configuration
+ [Tags] Binding Origins CRUD SXP
+ SxpBindingOriginsLib.Add Binding Origin CLUSTER 0
+ SxpBindingOriginsLib.Should Contain Binding Origins @{DEFAULT_AND_CLUSTER}
+
+Test Add Binding Origin With Already Used Origin Type
+ [Documentation] Test if binding origin with already used origin type cannot be added to configuration
+ [Tags] Binding Origins CRUD SXP
+ BuiltIn.Run Keyword And Expect Error RPC result is False SxpBindingOriginsLib.Add Binding Origin LOCAL 0
+
+Test Add Binding Origin With Already Used Priority
+ [Documentation] Test if binding origin with already used priotity cannot be added to configuration
+ [Tags] Binding Origins CRUD SXP
+ BuiltIn.Run Keyword And Expect Error RPC result is False SxpBindingOriginsLib.Add Binding Origin CLUSTER 1
+
+Test Update Binding Origin
+ [Documentation] Test if binding origin is updated in configuration
+ [Tags] Binding Origins CRUD SXP
+ BuiltIn.Comment Update default origin
+ SxpBindingOriginsLib.Update Binding Origin LOCAL 0
+ BuiltIn.Comment Verify that LOCAL origin priority is updated
+ SxpBindingOriginsLib.Should Contain Binding Origin With Priority LOCAL 0
+
+Test Update Binding Origin Of Unknown Origin Type
+ [Documentation] Test if unknown origin cannot be updated
+ [Tags] Binding Origins CRUD SXP
+ BuiltIn.Run Keyword And Expect Error RPC result is False SxpBindingOriginsLib.Update Binding Origin CLUSTER 0
+
+Test Update Binding Origin With Already Used Priority
+ [Documentation] Test if binding origin cannot be updated to use priority of another binding origin
+ [Tags] Binding Origins CRUD SXP
+ BuiltIn.Run Keyword And Expect Error RPC result is False SxpBindingOriginsLib.Update Binding Origin LOCAL 2
+
+Test Delete Binding Origin
+ [Documentation] Test if binding origin is deleted from configuration
+ [Tags] Binding Origins CRUD SXP
+ BuiltIn.Comment Add CLUSTER origin and verify it is added
+ SxpBindingOriginsLib.Add Binding Origin CLUSTER 0
+ SxpBindingOriginsLib.Should Contain Binding Origins @{DEFAULT_AND_CLUSTER}
+ BuiltIn.Comment Delete CLUSTER origin
+ SxpBindingOriginsLib.Delete Binding Origin CLUSTER
+ BuiltIn.Comment Verify that CLUSTER origin is no more present
+ SxpBindingOriginsLib.Should Not Contain Binding Origins CLUSTER
+
+Test Delete Default Binding Origin
+ [Documentation] Test that default binding origin cannot be deleted from configuration
+ [Tags] Binding Origins CRUD SXP
+ BuiltIn.Comment Try to delete default origin
+ BuiltIn.Run Keyword And Expect Error RPC result is False SxpBindingOriginsLib.Delete Binding Origin LOCAL
+ BuiltIn.Comment Verify all default origins are preserved
+ SxpBindingOriginsLib.Should Contain Binding Origins @{DEFAULT_ORIGINS}