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