02314f37bca74a3cb422f085e9b638f4f57fd1cd
[integration/test.git] / csit / libraries / SxpLib.robot
1 *** Settings ***
2 Documentation     Library containing Keywords used for SXP testing
3 Library           Collections
4 Library           RequestsLibrary
5 Library           SSHLibrary
6 Library           String
7 Library           ./Sxp.py
8 Resource          KarafKeywords.robot
9 Resource          Utils.robot
10 Resource          CompareStream.robot
11 Variables         ../variables/Variables.py
12
13 *** Variables ***
14 ${REST_CONTEXT}    /restconf/operations/sxp-controller
15
16 *** Keywords ***
17 Post To Controller
18     [Arguments]    ${session}    ${path}    ${DATA}
19     [Documentation]    Post request to Controller and checks response
20     ${resp}    Post Request    ${session}    ${REST_CONTEXT}:${path}    data=${DATA}    headers=${HEADERS_XML}
21     Log    ${resp.content}
22     Log    ${session}
23     Log    ${path}
24     Log    ${DATA}
25     Should be Equal As Strings    ${resp.status_code}    200
26     ${content}    Evaluate    json.loads('''${resp.content}''')    json
27     ${content}    Get From Dictionary    ${content}    output
28     ${content}    Get From Dictionary    ${content}    result
29     Should Be True    ${content}
30
31 Add Node
32     [Arguments]    ${node}    ${password}=${EMPTY}    ${version}=version4    ${port}=64999    ${session}=session    ${ip}=${EMPTY}
33     [Documentation]    Add node via RPC to ODL
34     ${DATA}    Add Node Xml    ${node}    ${port}    ${password}    ${version}    ${ip}
35     Post To Controller    ${session}    add-node    ${DATA}
36
37 Delete Node
38     [Arguments]    ${node}    ${session}=session
39     [Documentation]    Delete connection via RPC from node
40     ${DATA}    Delete Node Xml    ${node}
41     Post To Controller    ${session}    delete-node    ${DATA}
42
43 Add Connection
44     [Arguments]    ${version}    ${mode}    ${ip}    ${port}    ${node}=127.0.0.1    ${password}=${EMPTY}
45     ...    ${session}=session    ${domain}=global
46     [Documentation]    Add connection via RPC to node
47     ${DATA}    Add Connection Xml    ${version}    ${mode}    ${ip}    ${port}    ${node}
48     ...    ${password}    ${domain}
49     Post To Controller    ${session}    add-connection    ${DATA}
50
51 Get Connections
52     [Arguments]    ${node}=127.0.0.1    ${session}=session    ${domain}=global
53     [Documentation]    Gets all connections via RPC from node
54     ${DATA}    Get Connections From Node Xml    ${node}    ${domain}
55     ${resp}    Post Request    ${session}    ${REST_CONTEXT}:get-connections    data=${DATA}    headers=${HEADERS_XML}
56     Should be Equal As Strings    ${resp.status_code}    200
57     [Return]    ${resp.content}
58
59 Delete Connections
60     [Arguments]    ${ip}    ${port}    ${node}=127.0.0.1    ${session}=session    ${domain}=global
61     [Documentation]    Delete connection via RPC from node
62     ${DATA}    Delete Connections Xml    ${ip}    ${port}    ${node}    ${domain}
63     Post To Controller    ${session}    delete-connection    ${DATA}
64
65 Clean Connections
66     [Arguments]    ${node}=127.0.0.1    ${session}=session    ${domain}=global
67     [Documentation]    Delete all connections via RPC from node
68     ${resp}    Get Connections    ${node}    ${session}    ${domain}
69     @{connections}    Parse Connections    ${resp}
70     : FOR    ${connection}    IN    @{connections}
71     \    Delete Connections    ${connection['peer-address']}    ${connection['tcp-port']}    ${node}    ${session}    ${domain}
72
73 Verify Connection
74     [Arguments]    ${version}    ${mode}    ${ip}    ${port}=64999    ${node}=127.0.0.1    ${state}=on
75     ...    ${session}=session    ${domain}=global
76     [Documentation]    Verify that connection is ON
77     ${resp}    Get Connections    ${node}    ${session}    ${domain}
78     Should Contain Connection    ${resp}    ${ip}    ${port}    ${mode}    ${version}    ${state}
79
80 Add Binding
81     [Arguments]    ${sgt}    ${prefix}    ${node}=127.0.0.1    ${domain}=global    ${session}=session
82     [Documentation]    Add binding via RPC to Master DB of node
83     ${DATA}    Add Entry Xml    ${sgt}    ${prefix}    ${node}    ${domain}
84     Post To Controller    ${session}    add-entry    ${DATA}
85
86 Get Bindings
87     [Arguments]    ${node}=127.0.0.1    ${session}=session    ${domain}=global    ${scope}=all
88     [Documentation]    Gets all binding via RPC from Master DB of node
89     ${DATA}    Get Bindings From Node Xml    ${node}    ${scope}    ${domain}
90     ${resp}    Run Keyword If    '${ODL_STREAM}' not in ['beryllium', 'stable-lithium']    Post Request    ${session}    ${REST_CONTEXT}:get-node-bindings    data=${DATA}
91     ...    headers=${HEADERS_XML}
92     ...    ELSE    Get Request    ${session}    /restconf/operational/network-topology:network-topology/topology/sxp/node/${node}/master-database/    headers=${HEADERS_XML}
93     Should be Equal As Strings    ${resp.status_code}    200
94     [Return]    ${resp.content}
95
96 Clean Bindings
97     [Arguments]    ${node}=127.0.0.1    ${session}=session    ${domain}=global
98     [Documentation]    Delete all bindings via RPC from Master DB of node
99     ${resp}    Get Bindings    ${node}    ${session}    ${domain}    local
100     @{bindings}    Run Keyword If    '${ODL_STREAM}' not in ['beryllium', 'stable-lithium']    Parse Bindings    ${resp}
101     ...    ELSE    Parse Prefix Groups    ${resp}    local
102     : FOR    ${binding}    IN    @{bindings}
103     \    Run Keyword If    '${ODL_STREAM}' not in ['beryllium', 'stable-lithium']    Clean Binding    ${binding['sgt']}    ${binding['ip-prefix']}    ${node}
104     \    ...    ${session}    ${domain}
105     \    ...    ELSE    Clean Binding    ${binding}    ${binding['binding']}    ${node}
106     \    ...    ${session}    ${domain}
107
108 Clean Binding
109     [Arguments]    ${sgt}    ${prefixes}    ${node}    ${session}    ${domain}=global
110     [Documentation]    Used for nester FOR loop
111     : FOR    ${prefix}    IN    @{prefixes}
112     \    Run Keyword If    '${ODL_STREAM}' not in ['beryllium', 'stable-lithium']    Delete Binding    ${sgt}    ${prefix}    ${node}
113     \    ...    ${domain}    ${session}
114     \    ...    ELSE    Delete Binding    ${sgt['sgt']}    ${prefix['ip-prefix']}    ${node}
115     \    ...    ${domain}    ${session}
116
117 Update Binding
118     [Arguments]    ${sgtOld}    ${prefixOld}    ${sgtNew}    ${prefixNew}    ${node}=127.0.0.1    ${session}=session
119     ...    ${domain}=global
120     [Documentation]    Updates value of binding via RPC in Master DB of node
121     ${DATA}    Update Binding Xml    ${sgtOld}    ${prefixOld}    ${sgtNew}    ${prefixNew}    ${node}
122     ...    ${domain}
123     Post To Controller    ${session}    update-entry    ${DATA}
124
125 Delete Binding
126     [Arguments]    ${sgt}    ${prefix}    ${node}=127.0.0.1    ${domain}=global    ${session}=session
127     [Documentation]    Delete binding via RPC from Master DB of node
128     ${DATA}    Delete Binding Xml    ${sgt}    ${prefix}    ${node}    ${domain}
129     Post To Controller    ${session}    delete-entry    ${DATA}
130
131 Add PeerGroup
132     [Arguments]    ${name}    ${peers}=    ${node}=127.0.0.1    ${session}=session
133     [Documentation]    Adds new PeerGroup via RPC to Node
134     ${DATA}    Add Peer Group Xml    ${name}    ${peers}    ${node}
135     Post To Controller    ${session}    add-peer-group    ${DATA}
136
137 Delete Peer Group
138     [Arguments]    ${name}    ${node}=127.0.0.1    ${session}=session
139     [Documentation]    Delete PeerGroup via RPC from Node
140     ${DATA}    Delete Peer Group Xml    ${name}    ${node}
141     Post To Controller    ${session}    delete-peer-group    ${DATA}
142
143 Get Peer Groups
144     [Arguments]    ${node}=127.0.0.1    ${session}=session
145     [Documentation]    Gets all PeerGroups via RPC from node
146     ${DATA}    Get Peer Groups From Node Xml    ${node}
147     ${resp}    Post Request    ${session}    ${REST_CONTEXT}:get-peer-groups    data=${DATA}    headers=${HEADERS_XML}
148     Should be Equal As Strings    ${resp.status_code}    200
149     [Return]    ${resp.content}
150
151 Clean Peer Groups
152     [Arguments]    ${node}=127.0.0.1    ${session}=session
153     [Documentation]    Delete all PeerGroups via RPC from node
154     ${resp}    Get Peer Groups    ${node}    ${session}
155     @{prefixes}    Parse Peer Groups    ${resp}
156     : FOR    ${group}    IN    @{prefixes}
157     \    Delete Peer Group    ${group['name']}    ${node}    ${session}
158
159 Add Filter
160     [Arguments]    ${name}    ${type}    ${entries}    ${node}=127.0.0.1    ${session}=session    ${policy}=auto-update
161     [Documentation]    Add Filter via RPC from Node
162     ${DATA}    Run_Keyword_If_At_Least_Else    carbon    Add Filter Xml    ${name}    ${type}    ${entries}
163     ...    ${node}    ${policy}
164     ...    ELSE    Add Filter Xml    ${name}    ${type}    ${entries}    ${node}
165     Post To Controller    ${session}    add-filter    ${DATA}
166
167 Add Domain Filter
168     [Arguments]    ${name}    ${domains}    ${entries}    ${node}=127.0.0.1    ${filter_name}=base-domain-filter    ${session}=session
169     [Documentation]    Add Domain Filter via RPC from Node
170     ${DATA}    Add Domain Filter Xml    ${name}    ${domains}    ${entries}    ${node}    ${filter_name}
171     Post To Controller    ${session}    add-domain-filter    ${DATA}
172
173 Delete Filter
174     [Arguments]    ${name}    ${type}    ${node}=127.0.0.1    ${session}=session
175     [Documentation]    Delete Filter via RPC from Node
176     ${DATA}    Delete Filter Xml    ${name}    ${type}    ${node}
177     Post To Controller    ${session}    delete-filter    ${DATA}
178
179 Delete Domain Filter
180     [Arguments]    ${name}    ${node}=127.0.0.1    ${filter_name}=base-domain-filter    ${session}=session
181     [Documentation]    Delete Filter via RPC from Node
182     ${DATA}    Delete Domain Filter Xml    ${name}    ${node}    ${filter_name}
183     Post To Controller    ${session}    delete-domain-filter    ${DATA}
184
185 Should Contain Binding
186     [Arguments]    ${resp}    ${sgt}    ${prefix}    ${db_source}=any
187     [Documentation]    Tests if data contains specified binding
188     ${out}    Run Keyword If    '${ODL_STREAM}' not in ['beryllium', 'stable-lithium']    Find Binding    ${resp}    ${sgt}    ${prefix}
189     ...    ELSE    Find Binding Legacy    ${resp}    ${sgt}    ${prefix}    ${db_source}
190     ...    add
191     Should Be True    ${out}    Doesn't have ${sgt} ${prefix}
192
193 Should Not Contain Binding
194     [Arguments]    ${resp}    ${sgt}    ${prefix}    ${db_source}=any
195     [Documentation]    Tests if data doesn't contains specified binding
196     ${out}    Run Keyword If    '${ODL_STREAM}' not in ['beryllium', 'stable-lithium']    Find Binding    ${resp}    ${sgt}    ${prefix}
197     ...    ELSE    Find Binding Legacy    ${resp}    ${sgt}    ${prefix}    ${db_source}
198     ...    add
199     Should Not Be True    ${out}    Should't have ${sgt} ${prefix}
200
201 Should Contain Connection
202     [Arguments]    ${resp}    ${ip}    ${port}    ${mode}    ${version}    ${state}=none
203     [Documentation]    Test if data contains specified connection
204     ${out}    Find Connection    ${resp}    ${version}    ${mode}    ${ip}    ${port}
205     ...    ${state}
206     Should Be True    ${out}    Doesn't have ${ip}:${port} ${mode} ${version}
207
208 Should Not Contain Connection
209     [Arguments]    ${resp}    ${ip}    ${port}    ${mode}    ${version}    ${state}=none
210     [Documentation]    Test if data doesn't contains specified connection
211     ${out}    Find Connection    ${resp}    ${version}    ${mode}    ${ip}    ${port}
212     ...    ${state}
213     Should Not Be True    ${out}    Shouldn't have ${ip}:${port} ${mode} ${version}
214
215 Setup Topology Complex
216     [Arguments]    ${version}=version4    ${PASSWORD}=none
217     : FOR    ${node}    IN RANGE    2    6
218     \    Add Connection    ${version}    both    127.0.0.1    64999    127.0.0.${node}
219     \    ...    ${PASSWORD}
220     \    Add Connection    ${version}    both    127.0.0.${node}    64999    127.0.0.1
221     \    ...    ${PASSWORD}
222     \    Wait Until Keyword Succeeds    15    1    Verify Connection    ${version}    both
223     \    ...    127.0.0.${node}
224     \    Add Binding    ${node}0    10.10.10.${node}0/32    127.0.0.${node}
225     \    Add Binding    ${node}0    10.10.${node}0.0/24    127.0.0.${node}
226     \    Add Binding    ${node}0    10.${node}0.0.0/16    127.0.0.${node}
227     \    Add Binding    ${node}0    ${node}0.0.0.0/8    127.0.0.${node}
228     Add Binding    10    10.10.10.10/32    127.0.0.1
229     Add Binding    10    10.10.10.0/24    127.0.0.1
230     Add Binding    10    10.10.0.0/16    127.0.0.1
231     Add Binding    10    10.0.0.0/8    127.0.0.1
232
233 Verify Snapshot Was Pushed
234     [Arguments]    ${snapshot_string}=22-sxp-controller-one-node.xml
235     [Documentation]    Will succeed if the ${snapshot_string} is found in the karaf logs
236     ${output}    Run Command On Controller    ${ODL_SYSTEM_IP}    cat ${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log* | grep -c 'Successfully pushed configuration snapshot.*${snapshot_string}'
237     Should Not Be Equal As Strings    ${output}    0
238
239 Setup SXP Session
240     [Arguments]    ${session}=session    ${controller}=${ODL_SYSTEM_IP}
241     [Documentation]    Create session to Controller
242     Verify Feature Is Installed    odl-sxp-controller    ${controller}
243     Create Session    ${session}    url=http://${controller}:${RESTCONFPORT}    auth=${AUTH}    headers=${HEADERS_XML}
244     ${resp}    RequestsLibrary.Get Request    ${session}    ${MODULES_API}
245     Should Be Equal As Strings    ${resp.status_code}    200
246     Should Contain    ${resp.content}    ietf-restconf
247
248 Clean SXP Session
249     [Documentation]    Destroy created sessions
250     Delete All Sessions
251
252 Add Domain
253     [Arguments]    ${domain_name}    ${node}=127.0.0.1    ${session}=session
254     [Documentation]    Add Domain via RPC
255     ${DATA}    Add Domain Xml    ${node}    ${domain_name}
256     Post To Controller    ${session}    add-domain    ${DATA}
257
258 Delete Domain
259     [Arguments]    ${domain_name}    ${node}=127.0.0.1    ${session}=session
260     [Documentation]    Delete Domain via RPC
261     ${DATA}    Delete Domain Xml    ${node}    ${domain_name}
262     Post To Controller    ${session}    delete-domain    ${DATA}
263
264 Add Bindings
265     [Arguments]    ${sgt}    ${prefixes}    ${node}=127.0.0.1    ${session}=session    ${domain}=global
266     [Documentation]    Add bindings via RPC to Master DB of node
267     ${DATA}    Add Bindings Xml    ${node}    ${domain}    ${sgt}    ${prefixes}
268     Post To Controller    ${session}    add-bindings    ${DATA}
269
270 Delete Bindings
271     [Arguments]    ${sgt}    ${prefixes}    ${node}=127.0.0.1    ${session}=session    ${domain}=global
272     [Documentation]    Delete bindings via RPC from Master DB of node
273     ${DATA}    Delete Bindings Xml    ${node}    ${domain}    ${sgt}    ${prefixes}
274     Post To Controller    ${session}    delete-bindings    ${DATA}
275
276 Add Bindings Range
277     [Arguments]    ${sgt}    ${start}    ${size}    ${node}=127.0.0.1
278     [Documentation]    Add Bindings to Node specified by range
279     ${prefixes}    Prefix Range    ${start}    ${size}
280     Add Bindings    ${sgt}    ${prefixes}    ${node}
281
282 Delete Bindings Range
283     [Arguments]    ${sgt}    ${start}    ${size}    ${node}=127.0.0.1
284     [Documentation]    Delete Bindings to Node specified by range
285     ${prefixes}    Prefix Range    ${start}    ${size}
286     Delete Bindings    ${sgt}    ${prefixes}    ${node}
287
288 Check Binding Range
289     [Arguments]    ${sgt}    ${start}    ${end}    ${node}=127.0.0.1
290     [Documentation]    Check if Node contains Bindings specified by range
291     ${resp}    Get Bindings    ${node}
292     : FOR    ${num}    IN RANGE    ${start}    ${end}
293     \    ${ip}    Get Ip From Number    ${num}
294     \    Should Contain Binding    ${resp}    ${sgt}    ${ip}/32
295
296 Check Binding Range Negative
297     [Arguments]    ${sgt}    ${start}    ${end}    ${node}=127.0.0.1
298     [Documentation]    Check if Node does not contains Bindings specified by range
299     ${resp}    Get Bindings    ${node}
300     : FOR    ${num}    IN RANGE    ${start}    ${end}
301     \    ${ip}    Get Ip From Number    ${num}
302     \    Should Not Contain Binding    ${resp}    ${sgt}    ${ip}/32
303
304 Setup SXP Environment
305     [Arguments]    ${node_range}=2
306     [Documentation]    Create session to Controller, node_range parameter specifies number of nodes to be created plus one
307     Setup SXP Session
308     : FOR    ${num}    IN RANGE    1    ${node_range}
309     \    ${ip}    Get Ip From Number    ${num}
310     \    Run Keyword If    '${ODL_STREAM}' not in ['beryllium', 'stable-lithium']    Add Node    ${ip}
311     \    Run Keyword If    '${ODL_STREAM}' not in ['beryllium', 'stable-lithium']    Wait Until Keyword Succeeds    20    1    Check Node Started
312     \    ...    ${ip}
313
314 Check Node Started
315     [Arguments]    ${node}    ${port}=64999    ${system}=${ODL_SYSTEM_IP}    ${session}=session    ${ip}=${node}
316     [Documentation]    Verify that SxpNode has data writed to Operational datastore
317     ${resp}    RequestsLibrary.Get Request    ${session}    /restconf/operational/network-topology:network-topology/topology/sxp/node/${node}/
318     Should Be Equal As Strings    ${resp.status_code}    200
319     ${rc}    Run Command On Remote System    ${system}    netstat -tln | grep -q ${ip}:${port} && echo 0 || echo 1    ${ODL_SYSTEM_USER}    ${ODL_SYSTEM_PASSWORD}    prompt=${ODL_SYSTEM_PROMPT}
320     Should Be Equal As Strings    ${rc}    0
321
322 Clean SXP Environment
323     [Arguments]    ${node_range}=2
324     [Documentation]    Destroy created sessions
325     : FOR    ${num}    IN RANGE    1    ${node_range}
326     \    ${ip}    Get Ip From Number    ${num}
327     \    Run Keyword If    '${ODL_STREAM}' not in ['beryllium', 'stable-lithium']    Delete Node    ${ip}
328     Clean SXP Session