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