Topoprocessing - workaroud for EOFError
[integration/test.git] / csit / libraries / TopoprocessingKeywords.robot
1 *** Settings ***
2 Variables         ../variables/Variables.py
3 Variables         ../variables/topoprocessing/Topologies.py
4 Variables         ../variables/topoprocessing/TopologyRequests.py
5 Library           RequestsLibrary
6 Library           SSHLibrary
7 Library           XML
8 Resource          KarafKeywords.robot
9 Resource          Utils.robot
10
11 *** Variables ***
12 ${CONFIGURATION_XML}    ${CURDIR}/../suites/topoprocessing/configuration.xml
13 ${OPERATIONAL_XML}    ${CURDIR}/../suites/topoprocessing/operational.xml
14 ${REMOTE_FILE}    ${WORKSPACE}/${BUNDLEFOLDER}/etc/opendaylight/karaf/80-topoprocessing-config.xml
15 ${OUTPUT_TOPO_NAME}    topo:1
16 ${OVERLAY_TOPO_URL}    ${TOPOLOGY_URL}/${OUTPUT_TOPO_NAME}
17
18 *** Keywords ***
19 Basic Request Put
20     [Arguments]    ${request}    ${overlay_topology_url}
21     [Documentation]    Send a simple HTTP PUT request to Configurational datastore
22     ${resp}    Put Request    session    ${CONFIG_API}/${overlay_topology_url}    data=${request}
23     Log    ${CONFIG_API}/${overlay_topology_url}
24     Should Match    "${resp.status_code}"    "20?"
25     Wait For Karaf Log    Correlation configuration successfully read
26     Wait For Karaf Log    Transaction successfully written
27
28 Basic Request Get
29     [Arguments]    ${overlay_topology_url}
30     [Documentation]    Send a simple HTTP GET request to a given URL
31     ${resp}    Get Request    session    ${OPERATIONAL_API}/${overlay_topology_url}
32     Should Be Equal As Strings    ${resp.status_code}    200
33     [Return]    ${resp}
34
35 Send Basic Delete Request
36     [Arguments]    ${url}
37     [Documentation]    Sends a HTTP/DELETE request to a given URL
38     ${resp}    Delete Request    session    ${CONFIG_API}/${url}
39     Log    Deleting ${CONFIG_API}/${url}
40     [Return]    ${resp}
41
42 Delete Underlay Node
43     [Arguments]    ${topology-id}    ${node-id}
44     [Documentation]    Deletes a node from an underlay topology
45     ${resp}    Send Basic Delete Request    ${TOPOLOGY_URL}/${topology-id}/node/${node-id}
46     [Return]    ${resp}
47
48 Delete Underlay Termination Point
49     [Arguments]    ${topology-id}    ${node-id}    ${tp-id}
50     [Documentation]    Deletes a termination point from an underlay topology
51     ${resp}    Send Basic Delete Request    ${TOPOLOGY_URL}/${topology-id}/node/${node-id}/termination-point/${tp-id}
52     [Return]    ${resp}
53
54 Delete Underlay Link
55     [Arguments]    ${topology-id}    ${link-id}
56     [Documentation]    Deletes a link from an underlay topology
57     ${resp}    Send Basic Delete Request    ${TOPOLOGY_URL}/${topology-id}/link/${link-id}
58     [Return]    ${resp}
59
60 Setup Environment
61     [Documentation]    Setup karaf enviroment for following tests
62     Log    ---- Setup Environment ----
63     Open Connection    ${ODL_SYSTEM_IP}
64     Flexible Controller Login
65     Put File    ${CONFIGURATION_XML}    ${REMOTE_FILE}
66     Close Connection
67     Wait Until Keyword Succeeds    2x    2s    Issue Command On Karaf Console    log:set DEBUG org.opendaylight.topoprocessing
68     Install a Feature    odl-restconf-noauth    timeout=30
69     Create Session    session    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}    headers=${SEND_ACCEPT_XML_HEADERS}
70     Install Features    odl-openflowplugin-nsf-model odl-topoprocessing-framework odl-topoprocessing-network-topology odl-topoprocessing-inventory odl-mdsal-models odl-ovsdb-southbound-impl
71     Prepare New Feature Installation
72     Insert Underlay topologies
73
74 Install Features
75     [Arguments]    ${features}    ${timeout}=180
76     [Documentation]    Install features according to tested distribution
77     Run Keyword If    '${ODL_STREAM}' == 'beryllium'    Install Features for Beryllium Distribution    ${features}    ${timeout}
78     ...    ELSE    Install Features for Other Distributions    ${features}    ${timeout}
79
80 Install Features for Beryllium Distribution
81     [Arguments]    ${features}    ${timeout}
82     [Documentation]    Will wait for features to install only once per run
83     Install a Feature    ${features}    timeout=${timeout}
84     Set Global Variable If It Does Not Exist    \${WAIT_FOR_FEATURES_TO_INSTALL}    ${TRUE}
85     Run Keyword If    ${WAIT_FOR_FEATURES_TO_INSTALL}    Run Keywords    Wait For Karaf Log    Registering Topology Request Listener    ${timeout}
86     ...    AND    Set Global Variable    \${WAIT_FOR_FEATURES_TO_INSTALL}    ${FALSE}
87
88 Install Features for Other Distributions
89     [Arguments]    ${features}    ${timeout}
90     [Documentation]    Will wait for features to install only if no topoprocessing feature was installed
91     ${installed_features}    Issue Command On Karaf Console    feature:list -i
92     ${lines}    Get Lines Containing String    ${installed_features}    odl-topoprocessing-framework
93     ${length}    Get Length    ${lines}
94     Install a Feature    ${features}    timeout=${timeout}
95     Run Keyword If    ${length} == 0    Wait For Karaf Log    Registering Topology Request Listener    ${timeout}
96
97 Clean Environment
98     [Documentation]    Revert startup changes
99     Log    ---- Clean Environment ----
100     Open Connection    ${ODL_SYSTEM_IP}
101     Flexible Controller Login
102     Put File    ${OPERATIONAL_XML}    ${REMOTE_FILE}
103     Close Connection
104     Delete All Sessions
105
106 Delete Overlay Topology
107     [Documentation]    Delete overlay topologies from datastore
108     Run Keyword If Test Failed    Print Output Topo
109     Log    ---- Test Teardown ----
110     Log    Deleting overlay topology from ${CONFIG_API}/${OVERLAY_TOPO_URL}
111     ${resp}    Delete Request    session    ${CONFIG_API}/${OVERLAY_TOPO_URL}
112     Should Be Equal As Strings    ${resp.status_code}    200
113
114 Print Output Topo
115     [Documentation]    Waits a while to allow any hanging transactions to finnish and then logs the output topology
116     Log    ---- Output Topo Dump After Cooldown----
117     Sleep    2s
118     ${resp}    Wait Until Keyword Succeeds    5x    250ms    Basic Request Get    ${OVERLAY_TOPO_URL}
119     Log    ${resp.content}
120
121 Refresh Underlay Topologies And Delete Overlay Topology
122     [Documentation]    Deletes given overlay topology from datastore and overwrites the underlaying ones with initial topologies
123     Delete Overlay Topology
124     Insert Underlay Topologies
125
126 Prepare New Feature Installation
127     [Documentation]    Clears karaf logs and CONFIGURATION datastore
128     ${resp}    Delete Request    session    ${CONFIG_API}/network-topology:network-topology
129     ${resp}    Delete Request    session    ${CONFIG_API}/opendaylight-inventory:nodes
130     Issue Command On Karaf Console    log:clear
131
132 Insert Underlay Topologies
133     [Documentation]    Insert underlay topologies used by following tests
134     Log    Inserting underlay topologies
135     # Network underlay topologies
136     : FOR    ${index}    IN RANGE    1    7
137     \    ${resp}    Put Request    session    ${CONFIG_API}/${TOPOLOGY_URL}/network-topo:${index}    data=${NETWORK_UNDERLAY_TOPOLOGY_${index}}
138     \    Log    ${resp.content}
139     \    Should Match    "${resp.status_code}"    "20?"
140     # Openflow underlay nodes
141     ${resp}    Put Request    session    ${CONFIG_API}/opendaylight-inventory:nodes    data=${OPENFLOW_UNDERLAY_NODES}
142     Log    ${resp.content}
143     Should Match    "${resp.status_code}"    "20?"
144     # Openflow underlay topologies
145     : FOR    ${index}    IN RANGE    1    7
146     \    ${resp}    Put Request    session    ${CONFIG_API}/${TOPOLOGY_URL}/openflow-topo:${index}    data=${OPENFLOW_UNDERLAY_TOPOLOGY_${index}}
147     \    Log    ${resp.content}
148     \    Should Match    "${resp.status_code}"    "20?"
149     Issue Command On Karaf Console    log:clear
150     Log    ${resp.content}
151
152 Prepare Unification Inside Topology Request
153     [Arguments]    ${request_template}    ${model}    ${correlation_item}    ${underlay_topo1}
154     [Documentation]    Prepare topology request for unification inside from template
155     ${request_template}    Set Element Text    ${request_template}    ${model}    xpath=.//correlations/output-model
156     ${request_template}    Set Element Text    ${request_template}    aggregation-only    xpath=.//correlations/correlation/type
157     ${request_template}    Set Element Text    ${request_template}    ${correlation_item}    xpath=.//correlation/correlation-item
158     ${request_template}    Set Element Text    ${request_template}    unification    xpath=.//correlation/aggregation/aggregation-type
159     ${request_template}    Set Element Text    ${request_template}    ${model}    xpath=.//correlation/aggregation/mapping[1]/input-model
160     ${request_template}    Set Element Text    ${request_template}    ${underlay_topo1}    xpath=.//correlation/aggregation/mapping[1]/underlay-topology
161     ${request_template}    Element to String    ${request_template}
162     [Return]    ${request_template}
163
164 Prepare Unification Topology Request
165     [Arguments]    ${request_template}    ${model}    ${correlation_item}    ${underlay_topo1}    ${underlay_topo2}
166     [Documentation]    Prepare topology request for unification on two topologies from template
167     ${request_template}    Prepare Unification Inside Topology Request    ${request_template}    ${model}    ${correlation_item}    ${underlay_topo1}
168     ${request_template}    Set Element Text    ${request_template}    ${underlay_topo2}    xpath=.//correlation/aggregation/mapping[2]/underlay-topology
169     ${request_template}    Set Element Text    ${request_template}    ${model}    xpath=.//correlation/aggregation/mapping[2]/input-model
170     ${request_template}    Element to String    ${request_template}
171     [Return]    ${request_template}
172
173 Prepare Unification Filtration Topology Request
174     [Arguments]    ${request_template}    ${model}    ${correlation_item}    ${target_field1}    ${underlay_topo1}    ${target_field2}
175     ...    ${underlay_topo2}
176     [Documentation]    Prepare topology request for unification on two topologies from template
177     ${request_template}    Prepare Unification Filtration Inside Topology Request    ${request_template}    ${model}    ${correlation_item}    ${target_field1}    ${underlay_topo1}
178     ${request_template}    Set Element Text    ${request_template}    ${underlay_topo2}    xpath=.//correlation/aggregation/mapping[2]/underlay-topology
179     Insert Target Field    ${request_template}    2    ${target_field2}    1
180     ${request_template}    Set Element Text    ${request_template}    ${model}    xpath=.//correlation/aggregation/mapping[2]/input-model
181     ${request_template}    Element to String    ${request_template}
182     [Return]    ${request_template}
183
184 Prepare Unification Filtration Inside Topology Request
185     [Arguments]    ${request_template}    ${model}    ${correlation_item}    ${target-field}    ${underlay_topo}
186     [Documentation]    Prepare topology request for unification filtration inside from template
187     ${request_template}    Set Element Text    ${request_template}    ${model}    xpath=.//correlations/output-model
188     ${request_template}    Set Element Text    ${request_template}    filtration-aggregation    xpath=.//correlations/correlation/type
189     ${request_template}    Set Element Text    ${request_template}    ${correlation_item}    xpath=.//correlation/correlation-item
190     ${request_template}    Set Element Text    ${request_template}    unification    xpath=.//correlation/aggregation/aggregation-type
191     ${request_template}    Set Element Text    ${request_template}    ${model}    xpath=.//correlation/aggregation/mapping[1]/input-model
192     ${request_template}    Set Element Text    ${request_template}    ${underlay_topo}    xpath=.//correlation/aggregation/mapping[1]/underlay-topology
193     Insert Target Field    ${request_template}    1    ${target-field}    1
194     ${request_template}    Set Element Text    ${request_template}    ${underlay_topo}    xpath=.//correlation/filtration/underlay-topology
195     ${request_template}    Element to String    ${request_template}
196     [Return]    ${request_template}
197
198 Insert Apply Filters
199     [Arguments]    ${request_template}    ${mapping}    ${filter_id}
200     ${request_template}    Add Element    ${request_template}    ${APPLY_FILTERS}    xpath=.//correlation/aggregation/mapping[${mapping}]
201     ${request_template}    Set Element Text    ${request_template}    ${filter_id}    xpath=.//correlation/aggregation/mapping[${mapping}]/apply-filters
202     [Return]    ${request_template}
203
204 Prepare Filtration Topology Request
205     [Arguments]    ${request_template}    ${model}    ${correlation_item}    ${underlay_topo}
206     [Documentation]    Prepare topology request for filtration from template
207     ${request_template}    Set Element Text    ${request_template}    ${model}    xpath=.//correlations/output-model
208     ${request_template}    Set Element Text    ${request_template}    ${correlation_item}    xpath=.//correlation/correlation-item
209     ${request_template}    Set Element Text    ${request_template}    ${underlay_topo}    xpath=.//correlation/filtration/underlay-topology
210     [Return]    ${request_template}
211
212 Insert Target Field
213     [Arguments]    ${request_template}    ${mapping_index}    ${target_field_path}    ${matching_key}
214     [Documentation]    Add target field to request
215     ${target_field_template}    Set Element Text    ${TARGET_FIELD}    ${target_field_path}    xpath=.//target-field-path
216     ${target_field_template}    Set Element Text    ${target_field_template}    ${matching_key}    xpath=.//matching-key
217     ${request_template}    Add Element    ${request_template}    ${target_field_template}    xpath=.//correlation/aggregation/mapping[${mapping_index}]
218     ${request_template}    Element to String    ${request_template}
219     [Return]    ${request_template}
220
221 Insert Filter
222     [Arguments]    ${request_template}    ${filter_template}    ${target_field}
223     [Documentation]    Add filter to filtration
224     ${request_template}    Add Element    ${request_template}    ${filter_template}    xpath=.//correlation/filtration
225     ${model}    Get Element Text    ${request_template}    xpath=.//correlations/output-model
226     ${request_template}    Set Element Text    ${request_template}    ${model}    xpath=.//correlation/filtration/filter/input-model
227     ${request_template}    Set Element Text    ${request_template}    ${target_field}    xpath=.//correlation/filtration/filter/target-field
228     [Return]    ${request_template}
229
230 Insert Filter With ID
231     [Arguments]    ${request_template}    ${filter_template}    ${target_field}    ${filter_id}
232     [Documentation]    Add filter to filtration with specified id
233     ${request_template}    Insert Filter    ${request_template}    ${filter_template}    ${target_field}
234     ${request_template}    Set Element Text    ${request_template}    ${filter_id}    xpath=.//correlation/filtration/filter/filter-id
235     [Return]    ${request_template}
236
237 Set IPV4 Filter
238     [Arguments]    ${request_template}    ${ip_address}
239     [Documentation]    Set filter ipv4 address
240     ${request_template}    Set Element Text    ${request_template}    ${ip_address}    xpath=.//correlation/filtration/filter/ipv4-address-filter/ipv4-address
241     ${request_template}    Element to String    ${request_template}
242     [Return]    ${request_template}
243
244 Set Range Number Filter
245     [Arguments]    ${request_template}    ${min_number}    ${max_number}
246     [Documentation]    Set filter minimum and maximum number values
247     ${request_template}    Set Element Text    ${request_template}    ${min_number}    xpath=.//correlation/filtration/filter/range-number-filter/min-number-value
248     ${request_template}    Set Element Text    ${request_template}    ${max_number}    xpath=.//correlation/filtration/filter/range-number-filter/max-number-value
249     ${request_template}    Element to String    ${request_template}
250     [Return]    ${request_template}
251
252 Set Range String Filter
253     [Arguments]    ${request_template}    ${min_value}    ${max_value}
254     [Documentation]    Set filter minimum and maximum string values
255     ${request_template}    Set Element Text    ${request_template}    ${min_value}    xpath=.//correlation/filtration/filter/range-string-filter/min-string-value
256     ${request_template}    Set Element Text    ${request_template}    ${max_value}    xpath=.//correlation/filtration/filter/range-string-filter/max-string-value
257     ${request_template}    Element to String    ${request_template}
258     [Return]    ${request_template}
259
260 Set Specific Number Filter
261     [Arguments]    ${request_template}    ${number}
262     [Documentation]    Set filter number value
263     ${request_template}    Set Element Text    ${request_template}    ${number}    xpath=.//correlation/filtration/filter/specific-number-filter/specific-number
264     ${request_template}    Element to String    ${request_template}
265     [Return]    ${request_template}
266
267 Set Specific String Filter
268     [Arguments]    ${request_template}    ${string_value}
269     [Documentation]    Set filter string value
270     ${request_template}    Set Element Text    ${request_template}    ${string_value}    xpath=.//correlation/filtration/filter/specific-string-filter/specific-string
271     ${request_template}    Element to String    ${request_template}
272     [Return]    ${request_template}
273
274 Set IPV6 Filter
275     [Arguments]    ${request_template}    ${ip_address}
276     [Documentation]    Set filter ipv6 address
277     ${request_template}    Set Element Text    ${request_template}    ${ip_address}    xpath=.//correlation/filtration/filter/ipv6-address-filter/ipv6-address
278     ${request_template}    Element to String    ${request_template}
279     [Return]    ${request_template}
280
281 Set Script Filter
282     [Arguments]    ${request_template}    ${script_language}    ${script}
283     [Documentation]    Set filter script
284     ${request_template}    Set Element Text    ${request_template}    ${script_language}    xpath=.//correlation/filtration/filter/script-filter/scripting/language
285     ${request_template}    Set Element Text    ${request_template}    ${script}    xpath=.//correlation/filtration/filter/script-filter/scripting/script
286     ${request_template}    Element to String    ${request_template}
287     [Return]    ${request_template}
288
289 Insert Link Computation Inside
290     [Arguments]    ${request_template}    ${link_computation_template}    ${input_model}    ${underlay_topology}
291     [Documentation]    Add link computation to request
292     ${request_template}    Add Element    ${request_template}    ${link_computation_template}    xpath=.
293     ${request_template}    Set Element Text    ${request_template}    ${input_model}    xpath=.//link-computation/node-info/input-model
294     ${request_template}    Set Element Text    ${request_template}    ${input_model}    xpath=.//link-computation/link-info/input-model
295     ${request_template}    Set Element Text    ${request_template}    ${input_model}    xpath=.//link-computation/output-model
296     ${request_template}    Set Element Text    ${request_template}    ${underlay_topology}    xpath=.//link-computation/link-info/link-topology
297     ${request_template}    Set Element Attribute    ${request_template}    xmlns:n    urn:opendaylight:topology:correlation    xpath=./link-computation
298     ${request_template}    Element to String    ${request_template}
299     [Return]    ${request_template}
300
301 Insert Link Computation
302     [Arguments]    ${request_template}    ${link_computation_template}    ${input_model}    ${underlay_topology_1}    ${underlay_topology_2}
303     [Documentation]    Add link computation to request
304     ${request_template}    Add Element    ${request_template}    ${link_computation_template}    xpath=.
305     ${request_template}    Set Element Text    ${request_template}    ${input_model}    xpath=.//link-computation/node-info/input-model
306     ${request_template}    Set Element Text    ${request_template}    ${input_model}    xpath=.//link-computation/link-info[1]/input-model
307     ${request_template}    Set Element Text    ${request_template}    ${input_model}    xpath=.//link-computation/link-info[2]/input-model
308     ${request_template}    Set Element Text    ${request_template}    ${input_model}    xpath=.//link-computation/output-model
309     ${request_template}    Set Element Text    ${request_template}    ${underlay_topology_1}    xpath=.//link-computation/link-info[1]/link-topology
310     ${request_template}    Set Element Text    ${request_template}    ${underlay_topology_2}    xpath=.//link-computation/link-info[2]/link-topology
311     ${request_template}    Set Element Attribute    ${request_template}    xmlns:n    urn:opendaylight:topology:correlation    xpath=./link-computation
312     ${request_template}    Element to String    ${request_template}
313     [Return]    ${request_template}
314
315 Insert Scripting into Request
316     [Arguments]    ${request}    ${language}    ${script}
317     [Documentation]    Insert Scripting into Request under aggregation node
318     ${request}    Add Element    ${request}    ${SCRIPTING}    xpath=.//correlation/aggregation
319     ${request}    Set Element Text    ${request}    ${script}    xpath=.//correlation/aggregation/scripting/script
320     ${request}    Set Element Text    ${request}    ${language}    xpath=.//correlation/aggregation/scripting/language
321     ${request}    Element to String    ${request}
322     [Return]    ${request}
323
324 Create Isis Node
325     [Arguments]    ${node-id}    ${ovs-version}=23    ${router-id-ipv4}=10.0.0.1
326     [Documentation]    Create an isis node element with id and ip
327     ${request}    Set Element Text    ${NODE_ISIS}    ${node-id}    xpath=.//node-id
328     ${request}    Set Element Text    ${request}    ${ovs-version}    xpath=.//ovs-version
329     ${request}    Set Element Text    ${request}    ${router-id-ipv4}    xpath=.//igp-node-attributes/isis-node-attributes/ted/te-router-id-ipv4
330     ${request}    Element to String    ${request}
331     [Return]    ${request}
332
333 Create Openflow Node
334     [Arguments]    ${node-id}    ${ip-address}=10.0.0.1    ${serial-number}=27
335     [Documentation]    Create an Openflow node element with id and ip
336     ${request}    Set Element Text    ${NODE_OPENFLOW}    ${node-id}    xpath=.//id
337     ${request}    Set Element Text    ${request}    ${ip-address}    xpath=.//ip-address
338     ${request}    Set Element Text    ${request}    ${serial-number}    xpath=.//serial-number
339     ${request}    Element to String    ${request}
340     [Return]    ${request}
341
342 Create OVSDB Termination Point
343     [Arguments]    ${tp-id}    ${ofport}
344     [Documentation]    Create an OVSDB termination point element with id and port
345     ${request}    Set Element Text    ${TERMINATION_POINT_OVSDB}    ${tp-id}    xpath=.//tp-id
346     ${request}    Set Element Text    ${request}    ${ofport}    xpath=.//ofport
347     ${request}    Element to String    ${request}
348     [Return]    ${request}
349
350 Create Openflow Node Connector
351     [Arguments]    ${nc-id}    ${port-number}
352     [Documentation]    Create an Openflow node connector element with id and port number
353     ${request}    Set Element Text    ${NODE_CONNECTOR_OPENFLOW}    ${nc-id}    xpath=.//id
354     ${request}    Set Element Text    ${request}    ${port-number}    xpath=.//port-number
355     ${request}    Element to String    ${request}
356     [Return]    ${request}
357
358 Create Link
359     [Arguments]    ${link-id}    ${source-node}    ${dest-node}    ${name}    ${metric}
360     ${request}    Set Element Text    ${LINK}    ${link-id}    xpath=.//link-id
361     ${request}    Set Element Text    ${request}    ${source-node}    xpath=.//source/source-node
362     ${request}    Set Element Text    ${request}    ${dest-node}    xpath=.//destination/dest-node
363     ${request}    Set Element Text    ${request}    ${name}    xpath=.//igp-link-attributes/name
364     ${request}    Set Element Text    ${request}    ${metric}    xpath=.//igp-link-attributes/metric
365     ${request}    Element to String    ${request}
366     [Return]    ${request}
367
368 Extract Node from Topology
369     [Arguments]    ${topology}    ${supp_node_id}
370     [Documentation]    Returns node that contains supporting node with ID specified in argument supp_node_id
371     ${xpath}    Set Variable    .//node/supporting-node[node-ref='${supp_node_id}']/..
372     ${node}    Get Element    ${topology}    xpath=${xpath}
373     ${node}    Element to String    ${node}
374     [Return]    ${node}
375
376 Extract Termination Point from Topology
377     [Arguments]    ${model}    ${topology}    ${topo_id}    ${node_id}    ${tp_id}
378     [Documentation]    Returns termination point that contains supporting termination point from specified topology, node and with specified id
379     Check Supported Model    ${model}
380     ${xpath}    Set Variable If    '${model}' == 'network-topology-model' or '${model}' == 'opendaylight-inventory-model'    .//termination-point[tp-ref='/network-topology:network-topology/topology/${topo_id}/node/${node_id}/termination-point/${tp_id}']    .//termination-point/supporting-termination-point[tp-ref='${tp_id}']/..
381     ${tp}    Get Element    ${topology}    xpath=${xpath}
382     ${tp}    Element to String    ${tp}
383     [Return]    ${tp}
384
385 Extract Link from Topology
386     [Arguments]    ${model}    ${topology}    ${topo_id}    ${link_id}
387     [Documentation]    Returns link that contains supporting link
388     Check Supported Model    ${model}
389     ${xpath}    Set Variable If    '${model}' == 'network-topology-model' or '${model}' == 'opendaylight-inventory-model'    .//link/supporting-link[link-ref='/network-topology/topology/${topo_id}/link/${link_id}']/..    .//link/supporting-link[tp-ref='${tp_id}']/..
390     ${link}    Get Element    ${topology}    xpath=${xpath}
391     ${link}    Element to String    ${link}
392     [Return]    ${link}
393
394 Check Supported Model
395     [Arguments]    ${model}
396     [Documentation]    Checks if model is supported.
397     Run Keyword If    '${model}' != 'network-topology-model' and '${model}' != 'i2rs-model' and '${model}' != 'opendaylight-inventory-model'    Fail    Not supported model
398
399 Check Aggregated Node in Topology
400     [Arguments]    ${model}    ${topology}    ${tp_count}    @{supp_node_ids}
401     [Documentation]    Checks number of termination points and concrete supporting nodes in aggregated node and returns overlay node id. Model should be 'network-topology-model', 'opendaylight-inventory-model' or 'i2rs-model'.
402     Check Supported Model    ${model}
403     ${node_id}    Get From List    ${supp_node_ids}    0
404     ${aggregated_node}    Extract Node from Topology    ${topology}    ${node_id}
405     ${supp_node_count}    Get Length    ${supp_node_ids}
406     Should Contain X Times    ${aggregated_node}    <supporting-node>    ${supp_node_count}
407     Should Contain X Times    ${aggregated_node}    <termination-point>    ${tp_count}
408     Should Contain X Times    ${aggregated_node}    <tp-ref>    ${tp_count}
409     : FOR    ${supp_node_id}    IN    @{supp_node_ids}
410     \    Element Text Should Be    ${aggregated_node}    ${supp_node_id}    xpath=.//supporting-node[node-ref='${supp_node_id}']/node-ref
411     ${overlay_node_id}    Get Element Text    ${aggregated_node}    xpath=./node-id
412     [Return]    ${overlay_node_id}
413
414 Check Aggregated Termination Point in Node
415     [Arguments]    ${model}    ${topology}    ${topology_id}    ${node_id}    ${tp_id}    @{supp_tp_ids}
416     [Documentation]    Checks supporting termination points in aggregated termination point. Model should be 'network-topology-model', 'opendaylight-inventory-model' or 'i2rs-model'.
417     Check Supported Model    ${model}
418     ${tp}    Extract Termination Point from Topology    ${model}    ${topology}    ${topology_id}    ${node_id}    ${tp_id}
419     ${supp_tp_count}    Get Length    ${supp_tp_ids}
420     Should Contain X Times    ${tp}    <tp-ref>    ${supp_tp_count}
421     : FOR    ${supp_tp_id}    IN    @{supp_tp_ids}
422     \    Should Contain X Times    ${tp}    ${supp_tp_id}</tp-ref>    1
423
424 Check Filtered Nodes in Topology
425     [Arguments]    ${topology}    ${tp_count}    @{node_ids}
426     [Documentation]    Checks nodes in filtered topology
427     : FOR    ${node_id}    IN    @{node_ids}
428     \    Element Text Should Be    ${topology}    ${node_id}    xpath=.//node/supporting-node[node-ref='${node_id}']/node-ref
429
430 Check Filtered Termination Points in Node
431     [Arguments]    ${topology}    ${supp_node_id}    @{supp_tp_ids}
432     [Documentation]    Checks termination points in filtered topology
433     ${node}    Extract Node from Topology    ${topology}    ${supp_node_id}
434     ${supp_tp_count}    Get Length    ${supp_tp_ids}
435     Should Contain X Times    ${node}    <supporting-node>    1
436     Should Contain X Times    ${node}    <termination-point>    ${supp_tp_count}
437     Should Contain X Times    ${node}    <tp-ref>    ${supp_tp_count}
438     : FOR    ${supp_tp_id}    IN    @{supp_tp_ids}
439     \    Should Contain X Times    ${node}    ${supp_tp_id}    1
440
441 Check Filtered Links In Topology
442     [Arguments]    ${topology}    @{supp_link_ids}
443     [Documentation]    Checks links in filtered topology
444     : FOR    ${supp_link_id}    IN    @{supp_link_ids}
445     \    Should Contain X Times    ${topology}    ${supp_link_id}</link-ref>    1
446
447 Check Overlay Link Source And Destination
448     [Arguments]    ${model}    ${topology}    ${topo_id}    ${link_id}    ${expected_source}    ${expected_destination}
449     [Documentation]    Checks if the overlay link's source and destination specified by a supporting link ref matches given source and destination
450     ${link}    Extract Link from Topology    ${model}    ${topology}    ${topo_id}    ${link_id}
451     ${link_source}    Get Element Text    ${link}    xpath=.//source-node
452     ${link_destination}    Get Element Text    ${link}    xpath=.//dest-node
453     Should Be Equal As Strings    ${link_source}    ${expected_source}
454     Should Be Equal As Strings    ${link_destination}    ${expected_destination}
455
456 Output Topo Should Be Complete
457     [Arguments]    ${node_count}=-1    ${supporting-node_count}=-1    ${node-ref_count}=-1    ${tp_count}=-1    ${tp-ref_count}=-1    ${link_count}=-1
458     ...    ${link-ref_count}=-1
459     [Documentation]    Verifies that the output topology contains the expected amount of essential elements
460     ${resp}    Wait Until Keyword Succeeds    5x    250ms    Basic Request Get    ${OVERLAY_TOPO_URL}
461     Should Contain    ${resp.content}    <topology-id>${OUTPUT_TOPO_NAME}</topology-id>
462     Run Keyword If    ${node_count}>-1    Should Contain X Times    ${resp.content}    <node>    ${node_count}
463     Run Keyword If    ${supporting-node_count}>-1    Should Contain X Times    ${resp.content}    <supporting-node>    ${supporting-node_count}
464     Run Keyword If    ${node-ref_count}>-1    Should Contain X Times    ${resp.content}    <node-ref>    ${node-ref_count}
465     Run Keyword If    ${link_count}>-1    Should Contain X Times    ${resp.content}    <link>    ${link_count}
466     Run Keyword If    ${link-ref_count}>-1    Should Contain X Times    ${resp.content}    <link-ref>    ${link-ref_count}
467     Run Keyword If    ${tp_count}>-1    Should Contain X Times    ${resp.content}    <termination-point>    ${tp_count}
468     Run Keyword If    ${tp-ref_count}>-1    Should Contain X Times    ${resp.content}    <tp-ref>    ${tp-ref_count}
469     Log    ---- Output Topo ----
470     Log    ${resp.content}
471     [Return]    ${resp}
472
473 Set Global Variable If It Does Not Exist
474     [Arguments]    ${name}    ${value}
475     ${status}    ${message} =    Run Keyword And Ignore Error    Variable Should Exist    ${name}
476     Run Keyword If    "${status}" == "FAIL"    Set Global Variable    ${name}    ${value}