87926f467c8b8f0bef71b4e27e62a55650cdee30
[integration/test.git] / csit / suites / netconf / MDSAL / northbound.robot
1 *** Settings ***
2 Documentation     Metconf MDSAL Northbound test suite.
3 ...
4 ...               Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
5 ...
6 ...               This program and the accompanying materials are made available under the
7 ...               terms of the Eclipse Public License v1.0 which accompanies this distribution,
8 ...               and is available at http://www.eclipse.org/legal/epl-v10.html
9 ...
10 ...
11 ...               The request produced by test cases "Get Config Running", "Get Config Running
12 ...               To Confirm No_Edit Before Commit", "Get Config Running To Confirm Delete
13 ...               After Commit" and "Get Config Candidate To Confirm Discard" all use the same
14 ...               message id ("empty") for their requests. This is possible because the
15 ...               requests produced by this suite are strictly serialized. The RFC 6241 does
16 ...               not state that these IDs are unique, it only requires that each ID used is
17 ...               "XML attribute normalized" if the client wants it to be returned unmodified.
18 ...               The RFC specifically says that "the content of this attribute is not
19 ...               interpreted in any way, it only is stored to be returned with the reply to
20 ...               the request. The reuse of the "empty" string for the 4 test cases was chosen
21 ...               for simplicity.
22 ...
23 ...               TODO: Change the 4 testcases to use unique message IDs.
24 Suite Setup       Setup_Everything
25 Suite Teardown    Teardown_Everything
26 Test Setup        SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
27 Library           RequestsLibrary
28 Library           SSHLibrary
29 Resource          ${CURDIR}/../../../libraries/FailFast.robot
30 Resource          ${CURDIR}/../../../libraries/SetupUtils.robot
31 Resource          ${CURDIR}/../../../libraries/SSHKeywords.robot
32 Resource          ${CURDIR}/../../../libraries/Utils.robot
33 Variables         ${CURDIR}/../../../variables/Variables.py
34
35 *** Variables ***
36 ${datadir}        ${CURDIR}/../../../variables/netconf/MDSAL
37 ${dataext}        msg
38 ${ssh_netconf_pid}    -1
39
40 *** Test Cases ***
41 Connect_To_ODL_Netconf
42     [Documentation]    Connect to ODL Netconf and fail if that is not possible.
43     Create_ODL_Netconf_Connection
44     Open_ODL_Netconf_Connection
45
46 Get_Config_Running
47     [Documentation]    Make sure the configuration has only the default elements in it.
48     Check_Test_Objects_Not_Present_In_Config    get-config
49
50 Missing_Message_ID_Attribute
51     [Documentation]    Check that messages with missing "message-ID" attribute are rejected with the correct error (RFC 6241, section 4.1).
52     Perform_Test    missing-attr
53
54 Additional_Attributes_In_Message
55     [Documentation]    Check that additional attributes in messages are returned properly (RFC 6241, sections 4.1 and 4.2).
56     ${reply}=    Load_And_Send_Message    additional-attr
57     BuiltIn.Should_Contain    ${reply}    xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"
58     BuiltIn.Should_Contain    ${reply}    message-id="1"
59     BuiltIn.Should_Contain    ${reply}    attribute="something"
60     BuiltIn.Should_Contain    ${reply}    additional="otherthing"
61     BuiltIn.Should_Contain    ${reply}    xmlns:prefix="http://www.example.com/my-schema-example.html"
62
63 Edit_Config_Modules_Merge
64     [Documentation]    Request a "merge" operation adding an element in candidate configuration and check the reply.
65     Perform_Test    config-modules-merge-1
66
67 Get_Config_Running_To_Confirm_No_Edit_Before_Commit
68     [Documentation]    Make sure the running configuration is still unchanged as the change was not commited yet.
69     Check_Test_Objects_Not_Present_In_Config    get-config-no-edit-before-commit
70
71 Commit_Edit
72     [Documentation]    Commit the change and check the reply.
73     Perform_Test    commit-edit
74
75 name0_In_Config_Running_To_Confirm_Edit_After_Commit
76     [Documentation]    Check that the change is now in the configuration.
77     ${reply}=    Load_And_Send_Message    get-config-edit-after-commit
78     BuiltIn.Should_Contain    ${reply}    <name>name0</name>
79
80 name0_In_Config_Modules_Via_Restconf
81     [Documentation]    Check that the change is also visible through Restconf.
82     ${data}=    Utils.Get_Data_From_URI    config    config:modules    headers=${ACCEPT_XML}
83     BuiltIn.Should_Contain    ${data}    <name>name0</name>
84
85 Terminate_Connection_Gracefully
86     [Documentation]    Close the session and disconnect.
87     Close_ODL_Netconf_Connection_Gracefully
88
89 name0_In_Config_Modules_Via_Restconf_After_Disconnect
90     [Documentation]    Check that the change is still visible through Restconf after Netconf disconnect.
91     ${data}=    Utils.Get_Data_From_URI    config    config:modules    headers=${ACCEPT_XML}
92     BuiltIn.Should_Contain    ${data}    <name>name0</name>
93
94 Reconnect_To_ODL_Netconf_After_Graceful_Session_End
95     [Documentation]    Reconnect to ODL Netconf and fail if that is not possible.
96     Open_ODL_Netconf_Connection
97
98 name0_In_Config_Running_After_Reconnect
99     [Documentation]    Check that the change is now in the configuration.
100     ${reply}=    Load_And_Send_Message    get-config-edit-after-commit
101     BuiltIn.Should_Contain    ${reply}    <name>name0</name>
102
103 name0_In_Config_Modules_Via_Restconf_After_Reconnect
104     [Documentation]    Check that the change is still visible through Restconf after Netconf reconnect.
105     ${data}=    Utils.Get_Data_From_URI    config    config:modules    headers=${ACCEPT_XML}
106     BuiltIn.Should_Contain    ${data}    <name>name0</name>
107
108 Edit_Config_Modules_Create_Shall_Fail_Now
109     [Documentation]    Request a "create" operation of an element that already exists and check that it fails with the correct error (RFC 6241, section 7.2, operation "create").
110     Perform_Test    config-modules-create
111
112 Delete_Modules
113     [Documentation]    Delete the created element from the candidate configuration and check the reply.
114     Perform_Test    config-modules-delete
115
116 Get_Config_Running_To_Confirm_No_Delete_Before_Commit
117     [Documentation]    Make sure the element is still present in the running configuration as the delete command was not committed yet.
118     ${reply}=    Load_And_Send_Message    get-config-no-delete-before-commit
119     BuiltIn.Should_Contain    ${reply}    <name>name0</name>
120
121 Commit_Delete
122     [Documentation]    Commit the deletion of the element and check the reply.
123     Perform_Test    commit-delete
124
125 Get_Config_Running_To_Confirm_Delete_After_Commit
126     [Documentation]    Check that the element is gone.
127     Check_Test_Objects_Not_Present_In_Config    get-config-delete-after-commit
128
129 Restconf_Get_Modules_Shall_Return_404
130     [Documentation]    Check that "Not Found" is returned when Restconf is asked for the deleted element.
131     ${response}=    RequestsLibrary.Get    config    config:modules    ${ACCEPT_XML}
132     BuiltIn.Should_Be_Equal_As_Strings    404    ${response.status_code}
133
134 Commit_No_Transaction
135     [Documentation]    Attempt to perform "commit" when there are no changes in the candidate configuration and check that it fails with the correct error.
136     Test_Commit_With_No_Transactions
137
138 Edit_Config_Another_Modules_Merge_For_Discard
139     [Documentation]    Create an element to be discarded and check the reply.
140     Perform_Test    config-modules-merge-2
141
142 Get_And_Check_Config_Candidate_For_Discard
143     [Documentation]    Check that the element to be discarded is present in the candidate configuration.
144     ${reply}=    Load_And_Send_Message    get-config-candidate
145     BuiltIn.Should_Contain    ${reply}    <name>name1</name>
146     BuiltIn.Should_Not_Contain    ${reply}    name0
147
148 Discard_Changes_Using_Discard_Request
149     [Documentation]    Ask the server to discard the candidate and check the reply.
150     Perform_Test    commit-discard
151
152 Get_And_Check_Config_Candidate_To_Confirm_Discard
153     [Documentation]    Check that the element was really discarded.
154     Check_Test_Objects_Not_Present_In_Config    get-config-candidate-discard
155
156 Edit_Config_Modules_Multiple_Modules_Merge_1
157     [Documentation]    Create the element with "name2" subelement again and check the reply.
158     Perform_Test    merge-multiple-1
159
160 Edit_Config_Modules_Multiple_Modules_Merge_2
161     [Documentation]    Add a "name3" subelement to the element and check the reply.
162     Perform_Test    merge-multiple-2
163
164 Edit_Config_Modules_Multiple_Modules_Merge_3
165     [Documentation]    Add a "name4" subelement to the element and check the reply.
166     Perform_Test    merge-multiple-3
167
168 Commit_Multiple_Modules_Merge
169     [Documentation]    Commit the changes and check the reply.
170     Perform_Test    merge-multiple-commit
171
172 name2_name3_name4_In_Running_Config
173     [Documentation]    Check that the 3 subelements are now present in the running configuration.
174     ${reply}=    Load_And_Send_Message    merge-multiple-check
175     BuiltIn.Should_Contain    ${reply}    <name>name2</name>
176     BuiltIn.Should_Contain    ${reply}    <name>name3</name>
177     BuiltIn.Should_Contain    ${reply}    <name>name4</name>
178
179 name2_name3_name4_In_Config_Modules_Via_Restconf
180     [Documentation]    Check that the 3 subelements are visible via Restconf.
181     ${data}=    Utils.Get_Data_From_URI    config    config:modules    headers=${ACCEPT_XML}
182     BuiltIn.Should_Contain    ${data}    <name>name2</name>
183     BuiltIn.Should_Contain    ${data}    <name>name3</name>
184     BuiltIn.Should_Contain    ${data}    <name>name4</name>
185
186 Abort_Connection_To_Simulate_Session_Failure
187     [Documentation]    Simulate session failure by disconnecting without terminating the session.
188     Abort_ODL_Netconf_Connection
189
190 name2_name3_name4_In_Config_Modules_Via_Restconf_After_Session_Fail
191     [Documentation]    Check that the 3 subelements are visible via Restconf.
192     ${data}=    Utils.Get_Data_From_URI    config    config:modules    headers=${ACCEPT_XML}
193     BuiltIn.Should_Contain    ${data}    <name>name2</name>
194     BuiltIn.Should_Contain    ${data}    <name>name3</name>
195     BuiltIn.Should_Contain    ${data}    <name>name4</name>
196
197 Reconnect_To_ODL_Netconf_After_Session_Failure
198     [Documentation]    Reconnect to ODL Netconf and fail if that is not possible.
199     Open_ODL_Netconf_Connection
200
201 name2_name3_name4_In_Running_Config_After_Session_Failure
202     [Documentation]    Check that the 3 subelements are now present in the running configuration.
203     ${reply}=    Load_And_Send_Message    merge-multiple-check
204     BuiltIn.Should_Contain    ${reply}    <name>name2</name>
205     BuiltIn.Should_Contain    ${reply}    <name>name3</name>
206     BuiltIn.Should_Contain    ${reply}    <name>name4</name>
207
208 Edit_Multiple_Modules_Merge
209     [Documentation]    Add another subelement named "test" to the element and check the reply.
210     Perform_Test    merge-multiple-edit
211
212 Commit_Multiple_Modules_Merge_Edit
213     [Documentation]    Commit the addition of the "test" subelement and check the reply.
214     Perform_Test    merge-multiple-edit-commit
215
216 Check_Multiple_Modules_Merge_Edit
217     [Documentation]    Check that the "test" subelement exists and has correct value for "port" subelement.
218     ${reply}=    Load_And_Send_Message    merge-multiple-edit-check
219     BuiltIn.Should_Contain    ${reply}    <port xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">2022</port>
220
221 Update_Multiple_Modules_Merge
222     [Documentation]    Update the value of the "port" subelement of the "test" subelement and check the reply.
223     Perform_Test    merge-multiple-update
224
225 Commit_Multiple_Modules_Merge_Update
226     [Documentation]    Commit the update and check the reply.
227     Perform_Test    merge-multiple-update-commit
228
229 Check_Multiple_Modules_Merge_Update
230     [Documentation]    Check that the value of the "port" was really updated.
231     ${reply}=    Load_And_Send_Message    merge-multiple-update-check
232     BuiltIn.Should_Contain    ${reply}    <port xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">3000</port>
233
234 Replace_Multiple_Modules_Merge
235     [Documentation]    Replace the content of the "test" with another completely different and check the reply.
236     Perform_Test    merge-multiple-replace
237
238 Commit_Multiple_Modules_Merge_Replace
239     [Documentation]    Commit the replace and check the reply.
240     Perform_Test    merge-multiple-replace-commit
241
242 Check_Multiple_Modules_Merge_Replace
243     [Documentation]    Check that the new content is there and the old content is gone.
244     ${reply}=    Load_And_Send_Message    merge-multiple-replace-check
245     BuiltIn.Should_Contain    ${reply}    <name>test</name>
246     BuiltIn.Should_Contain    ${reply}    <address xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">10.194.132.42</address>
247     BuiltIn.Should_Contain    ${reply}    <tcp-only xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">false</tcp-only>
248     BuiltIn.Should_Contain    ${reply}    <port xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">4000</port>
249     BuiltIn.Should_Contain    ${reply}    <password xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">admin</password>
250     BuiltIn.Should_Contain    ${reply}    <username xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">admin</username>
251     BuiltIn.Should_Not_Contain    ${reply}    <name>global-event-executor</name>
252     BuiltIn.Should_Not_Contain    ${reply}    <name>binding-osgi-broker</name>
253     BuiltIn.Should_Not_Contain    ${reply}    <name>dom-broker</name>
254     BuiltIn.Should_Not_Contain    ${reply}    <name>global-netconf-dispatcher</name>
255     BuiltIn.Should_Not_Contain    ${reply}    <name>global-netconf-processing-executor</name>
256
257 Remove_Multiple_Modules
258     [Documentation]    Remove the testing "module" element and all its subelements and check the reply.
259     Perform_Test    merge-multiple-remove
260
261 Commit_Multiple_Modules_Removal
262     [Documentation]    Commit the removal and check the reply.
263     Perform_Test    merge-multiple-remove-commit
264
265 Delete_Not_Existing_Module
266     [Documentation]    Attempt to delete the "module" element again and check that it fails with the correct error.
267     Perform_Test    delete-not-existing
268
269 Commit_Delete_Not_Existing_Module
270     [Documentation]    Attempt to commit and check the reply.
271     Test_Commit_With_No_Transactions
272     [Teardown]    Utils.Report_Failure_Due_To_Bug    4455
273
274 Remove_Not_Existing_Module
275     [Documentation]    Attempt to remove the "module" element again and check that the operation is "silently ignored".
276     Perform_Test    remove-not-existing
277
278 Commit_Remove_Not_Existing_Module
279     [Documentation]    Attempt to commit and check the reply.
280     Perform_Test    remove-not-existing-commit
281
282 Close_Session
283     [Documentation]    Close the session and check that it was closed properly.
284     Perform_Test    close-session
285
286 *** Keywords ***
287 Get_Data
288     [Arguments]    ${name}
289     [Documentation]    Load the specified data from the data directory and return it.
290     ${data}=    OperatingSystem.Get_File    ${datadir}${/}${name}.${dataext}
291     [Return]    ${data}
292
293 Create_ODL_Netconf_Connection
294     [Arguments]    ${host}=${CONTROLLER}    ${port}=${ODL_NETCONF_PORT}    ${user}=${ODL_NETCONF_USER}    ${password}=${ODL_NETCONF_PASSWORD}
295     [Documentation]    Open a netconf connecion to the given machine.
296     # The "-s netconf" flag (see the "SSHLibrary.Write" line below)    is not
297     # supported by SSHLibrary, therefore we need to use this elaborate and
298     # pretty tricky way to connect to the ODL Netconf port.
299     # TODO: Extract into NetconfKeywords as there are other tests that are
300     #    going to need to use this operation (Netconf Performance and Scaling
301     #    comes to my mind now as one of the things tested is the performance
302     #    of the direct netconf connection.
303     # TODO: Make this keyword return a dictionary object with all the
304     #    data about the prepared connection neatly packaged. Make all
305     #    the other keywords handling the connection accept such an
306     #    object and pull the data out of it rather than relying on
307     #    global variables. This will allow for tracking more Netconf
308     #    connections, increasing utility.
309     ${control}=    SSHLibrary.Open_Connection    ${host}    prompt=${ODL_SYSTEM_PROMPT}    timeout=10s
310     Utils.Flexible_Controller_Login
311     BuiltIn.Set_Suite_Variable    ${ssh_control}    ${control}
312     ${netconf}=    SSHLibrary.Open_Connection    ${host}    prompt=${ODL_SYSTEM_PROMPT}    timeout=10s
313     Utils.Flexible_Controller_Login
314     BuiltIn.Set_Suite_Variable    ${ssh_netconf}    ${netconf}
315     BuiltIn.Set_Suite_Variable    ${ssh_port}    ${port}
316     BuiltIn.Set_Suite_Variable    ${ssh_user}    ${user}
317     BuiltIn.Set_Suite_Variable    ${ssh_password}    ${password}
318
319 Reopen_ODL_Netconf_Connection
320     [Documentation]    Reopen a closed netconf connection.
321     SSHLibrary.Write    sshpass -p ${ssh_password} ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ${ssh_user}\@127.0.0.1 -p ${ssh_port} -s netconf
322     ${hello}=    SSHLibrary.Read_Until    ${ODL_NETCONF_PROMPT}
323     SSHLibrary.Switch_Connection    ${ssh_control}
324     ${pid}=    SSHLibrary.Execute_Command    ps -A | grep sshpass | cut -b 1-6
325     BuiltIn.Set_Suite_Variable    ${ssh_netconf_pid}    ${pid}
326     SSHLibrary.Switch_Connection    ${ssh_netconf}
327     [Return]    ${hello}
328
329 Open_ODL_Netconf_Connection
330     [Documentation]    Open a prepared netconf connecion.
331     ${hello}=    Reopen_ODL_Netconf_Connection
332     ${hello_message}=    Get_Data    hello
333     Transmit_Message    ${hello_message}
334     [Return]    ${hello}
335
336 Transmit_Message
337     [Arguments]    ${message}
338     [Documentation]    Transmit message to Netconf connection and discard the echo of the message.
339     SSHLibrary.Write    ${message}
340     SSHLibrary.Write    ${ODL_NETCONF_PROMPT}
341     SSHLibrary.Read_Until    ${ODL_NETCONF_PROMPT}
342
343 Send_Message
344     [Arguments]    ${message}
345     [Documentation]    Send message to Netconf connection and get the reply.
346     Transmit_Message    ${message}
347     ${reply}=    SSHLibrary.Read_Until    ${ODL_NETCONF_PROMPT}
348     [Return]    ${reply}
349
350 Prepare_For_Search
351     [Arguments]    ${searched_string}
352     [Documentation]    Prepare the specified string for searching in Netconf connection replies.
353     ...    The string passed to this keyword is coming from a data
354     ...    file which has different end of line conventions than
355     ...    the actual Netconf reply. This keyword patches the string
356     ...    to match what Netconf actually returns.
357     ${result}=    BuiltIn.Evaluate    "\\r\\n".join("""${searched_string}""".split("\\n"))
358     [Return]    ${result}
359
360 Load_And_Send_Message
361     [Arguments]    ${name}
362     [Documentation]    Load a message from the data file set, send it to Netconf and return the reply.
363     ${request}=    Get_Data    ${name}-request
364     ${reply}=    Send_Message    ${request}
365     [Return]    ${reply}
366
367 Load_Expected_Reply
368     [Arguments]    ${name}
369     [Documentation]    Load the expected reply from the data file set and return it.
370     ${expected_reply}=    Get_Data    ${name}-reply
371     ${expected}=    Prepare_For_Search    ${expected_reply}
372     [Return]    ${expected}
373
374 Abort_ODL_Netconf_Connection
375     [Documentation]    Correctly close the Netconf connection and make sure it is really dead.
376     BuiltIn.Return_From_Keyword_If    ${ssh_netconf_pid} == -1
377     ${kill_command}=    BuiltIn.Set_Variable    kill ${ssh_netconf_pid}
378     BuiltIn.Set_Suite_Variable    ${ssh_netconf_pid}    -1
379     SSHLibrary.Switch_Connection    ${ssh_control}
380     SSHLibrary.Write    ${kill_command}
381     SSHLibrary.Read_Until_Prompt
382     SSHLibrary.Switch_Connection    ${ssh_netconf}
383     SSHLibrary.Read_Until_Prompt
384
385 Close_ODL_Netconf_Connection_Gracefully
386     Perform_Test    close-session
387     Abort_ODL_Netconf_Connection
388
389 Setup_Everything
390     [Documentation]    Setup resources and create session for Restconf checking.
391     SetupUtils.Setup_Utils_For_Setup_And_Teardown
392     RequestsLibrary.Create_Session    config    http://${CONTROLLER}:${RESTCONFPORT}${CONFIG_API}    auth=${AUTH}
393
394 Teardown_Everything
395     [Documentation]    Close the Netconf connection and destroy all sessions in the requests library.
396     Abort_ODL_Netconf_Connection
397     RequestsLibrary.Delete_All_Sessions
398
399 Check_Test_Objects_Not_Present_In_Config
400     [Arguments]    ${name}
401     [Documentation]    Use dataset with the specified name to get the configuration and check that none of our test objects are there.
402     ${reply}=    Load_And_Send_Message    ${name}
403     BuiltIn.Should_Not_Contain    ${reply}    <name>name0</name>
404     BuiltIn.Should_Not_Contain    ${reply}    <name>name1</name>
405     BuiltIn.Should_Not_Contain    ${reply}    <name>name2</name>
406     BuiltIn.Should_Not_Contain    ${reply}    <name>name3</name>
407     BuiltIn.Should_Not_Contain    ${reply}    <name>name4</name>
408
409 Perform_Test
410     [Arguments]    ${name}
411     [Documentation]    Load and send the request from the dataset and compare the returned reply to the one stored in the dataset.
412     ${actual}=    Load_And_Send_Message    ${name}
413     ${expected}=    Load_Expected_Reply    ${name}
414     ${newline}=    BuiltIn.Evaluate    "\\r\\n"
415     BuiltIn.Should_Be_Equal    ${newline}${expected}${ODL_NETCONF_PROMPT}    ${actual}
416     [Return]    ${actual}
417
418 Send_And_Check
419     [Arguments]    ${name}    ${expected}
420     ${actual}=    Load_And_Send_Message    ${name}
421     BuiltIn.Should_Be_Equal    ${expected}    ${actual}
422
423 Test_Commit_With_No_Transactions
424     [Documentation]    Issue a "commit" RPC request and check that it fails with "No current transactions" error.
425     ${reply}=    Load_And_Send_Message    commit-no-transaction
426     ${expected}=    Load_Expected_Reply    commit-no-transaction
427     BuiltIn.Should_Contain    ${reply}    ${expected}