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