28b8ce653b15209dbd1022d121b265231a35ac0c
[integration/test.git] / csit / libraries / TopoprocessingKeywords.robot
1 *** Settings ***
2 Variables         ../variables/Variables.py
3 Variables         ../variables/topoprocessing/Topologies.py
4 Library           RequestsLibrary
5 Library           SSHLibrary
6 Library           XML
7 Resource          KarafKeywords.robot
8 Resource          Utils.robot
9
10 *** Variables ***
11 ${CONFIGURATION_XML}    ${CURDIR}/../suites/topoprocessing/configuration.xml
12 ${OPERATIONAL_XML}    ${CURDIR}/../suites/topoprocessing/operational.xml
13 ${REMOTE_FILE}    ${WORKSPACE}/${BUNDLEFOLDER}/etc/opendaylight/karaf/80-topoprocessing-config.xml
14
15 *** Keywords ***
16 Send Basic Request
17     [Arguments]    ${request}    ${overlay_topology_url}
18     [Documentation]    Test basic aggregation
19     ${resp}    Put Request    session    ${CONFIG_API}/${overlay_topology_url}    data=${request}
20     Log    ${CONFIG_API}/${overlay_topology_url}
21     Should Be Equal As Strings    ${resp.status_code}    200
22     Wait For Karaf Log    Correlation configuration successfully read
23     Wait For Karaf Log    Transaction successfully written
24     ${resp}    Get Request    session    ${OPERATIONAL_API}/${overlay_topology_url}
25     Should Be Equal As Strings    ${resp.status_code}    200
26     Log    ${resp.content}
27     [Return]    ${resp}
28
29 Setup Environment
30     [Documentation]    Setup karaf enviroment for following tests
31     Log    ---- Setup Environment ----
32     Open Connection    ${ODL_SYSTEM_IP}
33     Flexible Controller Login
34     Put File    ${CONFIGURATION_XML}    ${REMOTE_FILE}
35     Close Connection
36     Issue Command On Karaf Console    log:set DEBUG org.opendaylight.topoprocessing
37     Install a Feature    odl-restconf-noauth    timeout=30
38     Create Session    session    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}    headers=${SEND_ACCEPT_XML_HEADERS}
39     ${features}    Get Installed Features
40     ${lines}    Get Lines Containing String    ${features}    odl-topoprocessing-framework
41     ${length}    Get Length    ${lines}
42     Install a Feature    odl-openflowplugin-nsf-model-li odl-topoprocessing-framework odl-topoprocessing-network-topology odl-topoprocessing-inventory odl-mdsal-models odl-ovsdb-southbound-impl    timeout=120
43     Run Keyword If    ${length} == 0    Wait For Karaf Log    Registering Topology Request Listener    60
44     Prepare New Feature Installation
45     Insert Underlay topologies
46
47 Clean Environment
48     [Documentation]    Revert startup changes
49     Log    ---- Clean Environment ----
50     Open Connection    ${ODL_SYSTEM_IP}
51     Flexible Controller Login
52     Put File    ${OPERATIONAL_XML}    ${REMOTE_FILE}
53     Close Connection
54     Delete All Sessions
55
56 Test Teardown
57     [Arguments]    ${overlay_topology}
58     [Documentation]    Delete overlay topologies from datastore
59     Log    ---- Test Teardown ----
60     Log    Deleting overlay topology from ${CONFIG_API}/${overlay_topology}
61     ${resp}    Delete Request    session    ${CONFIG_API}/${overlay_topology}
62     Should Be Equal As Strings    ${resp.status_code}    200
63
64 Prepare New Feature Installation
65     [Documentation]    Clears karaf logs and CONFIGURATION datastore
66     ${resp}    Delete Request    session    ${CONFIG_API}/network-topology:network-topology
67     ${resp}    Delete Request    session    ${CONFIG_API}/opendaylight-inventory:nodes
68     Issue Command On Karaf Console    log:clear
69
70 Insert Underlay Topologies
71     [Documentation]    Insert underlay topologies used by following tests
72     Log    Inserting underlay topologies
73     # Network underlay topology 1
74     ${resp}    Put Request    session    ${CONFIG_API}/${TOPOLOGY_URL}/network-topo:1    data=${NETWORK_UNDERLAY_TOPOLOGY_1}
75     Log    ${resp.content}
76     Should Be Equal As Strings    ${resp.status_code}    200
77     # Network underlay topology 2
78     ${resp}    Put Request    session    ${CONFIG_API}/${TOPOLOGY_URL}/network-topo:2    data=${NETWORK_UNDERLAY_TOPOLOGY_2}
79     Log    ${resp.content}
80     Should Be Equal As Strings    ${resp.status_code}    200
81     # Openflow underlay nodes
82     ${resp}    Put Request    session    ${CONFIG_API}/opendaylight-inventory:nodes    data=${OPENFLOW_UNDERLAY_NODES}
83     Log    ${resp.content}
84     Should Be Equal As Strings    ${resp.status_code}    200
85     # Openflow underlay topology 1
86     ${resp}    Put Request    session    ${CONFIG_API}/${TOPOLOGY_URL}/openflow-topo:1    data=${OPENFLOW_UNDERLAY_TOPOLOGY_1}
87     Log    ${resp.content}
88     Should Be Equal As Strings    ${resp.status_code}    200
89     # Openflow underlay topology 2
90     ${resp}    Put Request    session    ${CONFIG_API}/${TOPOLOGY_URL}/openflow-topo:2    data=${OPENFLOW_UNDERLAY_TOPOLOGY_2}
91     Log    ${resp.content}
92     Should Be Equal As Strings    ${resp.status_code}    200
93     Issue Command On Karaf Console    log:clear
94     Log    ${resp.content}
95
96 Prepare Unification Inside Topology Request
97     [Arguments]    ${request_template}    ${model}    ${correlation_item}    ${target-field}    ${underlay_topo1}
98     [Documentation]    Prepare topology request for unification inside from template
99     ${request_template}    Set Element Text    ${request_template}    ${model}    xpath=.//correlations/output-model
100     ${request_template}    Set Element Text    ${request_template}    aggregation-only    xpath=.//correlations/correlation/type
101     ${request_template}    Set Element Text    ${request_template}    ${correlation_item}    xpath=.//correlation/correlation-item
102     ${request_template}    Set Element Text    ${request_template}    unification    xpath=.//correlation/aggregation/aggregation-type
103     ${request_template}    Set Element Text    ${request_template}    ${model}    xpath=.//correlation/aggregation/mapping[1]/input-model
104     ${request_template}    Set Element Text    ${request_template}    ${underlay_topo1}    xpath=.//correlation/aggregation/mapping[1]/underlay-topology
105     ${request_template}    Set Element Text    ${request_template}    ${target-field}    xpath=.//correlation/aggregation/mapping[1]/target-field
106     ${request_template}    Element to String    ${request_template}
107     [Return]    ${request_template}
108
109 Prepare Unification Topology Request
110     [Arguments]    ${request_template}    ${model}    ${correlation_item}    ${target-field}    ${underlay_topo1}    ${underlay_topo2}
111     [Documentation]    Prepare topology request for unification on two topologies from template
112     ${request_template}    Prepare Unification Inside Topology Request    ${request_template}    ${model}    ${correlation_item}    ${target-field}    ${underlay_topo1}
113     ${request_template}    Set Element Text    ${request_template}    ${underlay_topo2}    xpath=.//correlation/aggregation/mapping[2]/underlay-topology
114     ${request_template}    Set Element Text    ${request_template}    ${target-field}    xpath=.//correlation/aggregation/mapping[2]/target-field
115     ${request_template}    Set Element Text    ${request_template}    ${model}    xpath=.//correlation/aggregation/mapping[2]/input-model
116     ${request_template}    Element to String    ${request_template}
117     [Return]    ${request_template}
118
119 Get Installed Features
120     [Documentation]    Returns list of installed features as String
121     Open Connection    ${ODL_SYSTEM_IP}    port=${KARAF_SHELL_PORT}    prompt=${KARAF_PROMPT}    timeout=5
122     Flexible SSH Login    ${KARAF_USER}    ${KARAF_PASSWORD}
123     Write    feature:list -i
124     ${features}    Read until prompt
125     Close Connection
126     Log    Installed features:
127     Log    ${features}
128     [Return]    ${features}
129
130 Insert Scripting into Request
131     [Arguments]    ${request}    ${language}    ${script}
132     [Documentation]    Insert Scripting into Request under aggregation node
133     ${request}    Add Element    ${request}    ${SCRIPTING}    xpath=.//correlation/aggregation
134     ${request}    Set Element Text    ${request}    ${script}    xpath=.//correlation/aggregation/scripting/script
135     ${request}    Set Element Text    ${request}    ${language}    xpath=.//correlation/aggregation/scripting/language
136     ${request}    Element to String    ${request}
137     [Return]    ${request}