df92fb9d33d2cc8ea39c8f67d7ef7b75e0594362
[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_Fast_Failing
27 Test Teardown     FailFast.Start_Failing_Fast_If_This_Failed
28 Library           RequestsLibrary
29 Library           SSHLibrary
30 Resource          ${CURDIR}/../../../libraries/FailFast.robot
31 Resource          ${CURDIR}/../../../libraries/SetupUtils.robot
32 Resource          ${CURDIR}/../../../libraries/SSHKeywords.robot
33 Resource          ${CURDIR}/../../../libraries/Utils.robot
34 Variables         ${CURDIR}/../../../variables/Variables.py
35
36 *** Variables ***
37 ${datadir}        ${CURDIR}/../../../variables/netconf/MDSAL
38 ${dataext}        msg
39 ${ssh_netconf_pid}    -1
40
41 *** Test Cases ***
42 Connect_To_ODL_Netconf
43     [Documentation]    Connect to ODL Netconf and fail if that is not possible.
44     Open_ODL_Netconf_Connection
45     ${hello_message}=    Get_Data    hello
46     Transmit_Message    ${hello_message}
47
48 Get_Config_Running
49     [Documentation]    Make sure the configuration has only the default elements in it.
50     Check_Test_Objects_Not_Present_In_Config    get-config
51
52 Missing_Message_ID_Attribute
53     [Documentation]    Check that messages with missing "message-ID" attribute are rejected with the correct error (RFC 6241, section 4.1).
54     Perform_Test    missing-attr
55
56 Additional_Attributes_In_Message
57     [Documentation]    Check that additional attributes in messages are returned properly (RFC 6241, sections 4.1 and 4.2).
58     ${reply}=    Load_And_Send_Message    additional-attr
59     BuiltIn.Should_Contain    ${reply}    xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"
60     BuiltIn.Should_Contain    ${reply}    message-id="1"
61     BuiltIn.Should_Contain    ${reply}    attribute="something"
62     BuiltIn.Should_Contain    ${reply}    additional="otherthing"
63     BuiltIn.Should_Contain    ${reply}    xmlns:prefix="http://www.example.com/my-schema-example.html"
64
65 Edit_Config_Modules_Merge
66     [Documentation]    Request a "merge" operation adding an element in candidate configuration and check the reply.
67     Perform_Test    config-modules-merge-1
68
69 Get_Config_Running_To_Confirm_No_Edit_Before_Commit
70     [Documentation]    Make sure the running configuration is still unchanged as the change was not commited yet.
71     Check_Test_Objects_Not_Present_In_Config    get-config-no-edit-before-commit
72
73 Commit_Edit
74     [Documentation]    Commit the change and check the reply.
75     Perform_Test    commit-edit
76
77 name0_In_Config_Running_To_Confirm_Edit_After_Commit
78     [Documentation]    Check that the change is now in the configuration.
79     ${reply}=    Load_And_Send_Message    get-config-edit-after-commit
80     BuiltIn.Should_Contain    ${reply}    <name>name0</name>
81
82 name0_In_Config_Modules_Via_Restconf
83     [Documentation]    Check that the change is also visible through Restconf.
84     ${data}=    Utils.Get_Data_From_URI    config    config:modules    headers=${ACCEPT_XML}
85     BuiltIn.Should_Contain    ${data}    <name>name0</name>
86
87 Edit_Config_Modules_Create_Shall_Fail_Now
88     [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").
89     Perform_Test    config-modules-create
90
91 Delete_Modules
92     [Documentation]    Delete the created element from the candidate configuration and check the reply.
93     Perform_Test    config-modules-delete
94
95 Get_Config_Running_To_Confirm_No_Delete_Before_Commit
96     [Documentation]    Make sure the element is still present in the running configuration as the delete command was not committed yet.
97     ${reply}=    Load_And_Send_Message    get-config-no-delete-before-commit
98     BuiltIn.Should_Contain    ${reply}    <name>name0</name>
99
100 Commit_Delete
101     [Documentation]    Commit the deletion of the element and check the reply.
102     Perform_Test    commit-delete
103
104 Get_Config_Running_To_Confirm_Delete_After_Commit
105     [Documentation]    Check that the element is gone.
106     Check_Test_Objects_Not_Present_In_Config    get-config-delete-after-commit
107
108 Restconf_Get_Modules_Shall_Return_404
109     [Documentation]    Check that "Not Found" is returned when Restconf is asked for the deleted element.
110     ${response}=    RequestsLibrary.Get    config    config:modules    ${ACCEPT_XML}
111     BuiltIn.Should_Be_Equal_As_Strings    ${response.status_code}    404
112
113 Commit_No_Transaction
114     [Documentation]    Attempt to perform "commit" when there are no changes in the candidate configuration and check that it fails with the correct error.
115     Test_Commit_With_No_Transactions
116
117 Edit_Config_Another_Modules_Merge
118     [Documentation]    Create the element in the candidate configuration again and check the reply.
119     Perform_Test    config-modules-merge-2
120
121 Get_Config_Candidate
122     [Documentation]    Check that the element is present in the candidate configuration.
123     ${reply}=    Load_And_Send_Message    get-config-candidate
124     BuiltIn.Should_Contain    ${reply}    <name>name1</name>
125     BuiltIn.Should_Not_Contain    ${reply}    name0
126
127 Discard_Changes
128     [Documentation]    Ask the server to discard the candidate and check the reply.
129     Perform_Test    commit-discard
130
131 Get_Config_Candidate_To_Confirm_Discard
132     [Documentation]    Check that the element was really discarded.
133     Check_Test_Objects_Not_Present_In_Config    get-config-candidate-discard
134
135 Edit_Config_Modules_Multiple_Modules_Merge_1
136     [Documentation]    Create the element with "name2" subelement again and check the reply.
137     Perform_Test    merge-multiple-1
138
139 Edit_Config_Modules_Multiple_Modules_Merge_2
140     [Documentation]    Add a "name3" subelement to the element and check the reply.
141     Perform_Test    merge-multiple-2
142
143 Edit_Config_Modules_Multiple_Modules_Merge_3
144     [Documentation]    Add a "name4" subelement to the element and check the reply.
145     Perform_Test    merge-multiple-3
146
147 Commit_Multiple_Modules_Merge
148     [Documentation]    Commit the changes and check the reply.
149     Perform_Test    merge-multiple-commit
150
151 name2_name3_name4_In_Running_Config
152     [Documentation]    Check that the 3 subelements are now present in the running configuration.
153     ${reply}=    Load_And_Send_Message    merge-multiple-check
154     BuiltIn.Should_Contain    ${reply}    <name>name2</name>
155     BuiltIn.Should_Contain    ${reply}    <name>name3</name>
156     BuiltIn.Should_Contain    ${reply}    <name>name4</name>
157
158 name2_name3_name4_In_Config_Modules_Via_Restconf
159     [Documentation]    Check that the 3 subelements are visible via Restconf.
160     ${data}=    Utils.Get_Data_From_URI    config    config:modules    headers=${ACCEPT_XML}
161     BuiltIn.Should_Contain    ${data}    <name>name2</name>
162     BuiltIn.Should_Contain    ${data}    <name>name3</name>
163     BuiltIn.Should_Contain    ${data}    <name>name4</name>
164
165 Edit_Multiple_Modules_Merge
166     [Documentation]    Add another subelement named "test" to the element and check the reply.
167     Perform_Test    merge-multiple-edit
168
169 Commit_Multiple_Modules_Merge_Edit
170     [Documentation]    Commit the addition of the "test" subelement and check the reply.
171     Perform_Test    merge-multiple-edit-commit
172
173 Check_Multiple_Modules_Merge_Edit
174     [Documentation]    Check that the "test" subelement exists and has correct value for "port" subelement.
175     ${reply}=    Load_And_Send_Message    merge-multiple-edit-check
176     BuiltIn.Should_Contain    ${reply}    <port xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">2022</port>
177
178 Update_Multiple_Modules_Merge
179     [Documentation]    Update the value of the "port" subelement of the "test" subelement and check the reply.
180     Perform_Test    merge-multiple-update
181
182 Commit_Multiple_Modules_Merge_Update
183     [Documentation]    Commit the update and check the reply.
184     Perform_Test    merge-multiple-update-commit
185
186 Check_Multiple_Modules_Merge_Update
187     [Documentation]    Check that the value of the "port" was really updated.
188     ${reply}=    Load_And_Send_Message    merge-multiple-update-check
189     BuiltIn.Should_Contain    ${reply}    <port xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">3000</port>
190
191 Replace_Multiple_Modules_Merge
192     [Documentation]    Replace the content of the "test" with another completely different and check the reply.
193     Perform_Test    merge-multiple-replace
194
195 Commit_Multiple_Modules_Merge_Replace
196     [Documentation]    Commit the replace and check the reply.
197     Perform_Test    merge-multiple-replace-commit
198
199 Check_Multiple_Modules_Merge_Replace
200     [Documentation]    Check that the new content is there and the old content is gone.
201     ${reply}=    Load_And_Send_Message    merge-multiple-replace-check
202     BuiltIn.Should_Contain    ${reply}    <name>test</name>
203     BuiltIn.Should_Contain    ${reply}    <address xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">10.194.132.42</address>
204     BuiltIn.Should_Contain    ${reply}    <tcp-only xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">false</tcp-only>
205     BuiltIn.Should_Contain    ${reply}    <port xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">4000</port>
206     BuiltIn.Should_Contain    ${reply}    <password xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">admin</password>
207     BuiltIn.Should_Contain    ${reply}    <username xmlns="urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf">admin</username>
208     BuiltIn.Should_Not_Contain    ${reply}    <name>global-event-executor</name>
209     BuiltIn.Should_Not_Contain    ${reply}    <name>binding-osgi-broker</name>
210     BuiltIn.Should_Not_Contain    ${reply}    <name>dom-broker</name>
211     BuiltIn.Should_Not_Contain    ${reply}    <name>global-netconf-dispatcher</name>
212     BuiltIn.Should_Not_Contain    ${reply}    <name>global-netconf-processing-executor</name>
213
214 Remove_Multiple_Modules
215     [Documentation]    Remove the testing "module" element and all its subelements and check the reply.
216     Perform_Test    merge-multiple-remove
217
218 Commit_Multiple_Modules_Removal
219     [Documentation]    Commit the removal and check the reply.
220     Perform_Test    merge-multiple-remove-commit
221
222 Delete_Not_Existing_Module
223     [Documentation]    Attempt to delete the "module" element again and check that it fails with the correct error.
224     Perform_Test    delete-not-existing
225
226 Commit_Delete_Not_Existing_Module
227     [Documentation]    Attempt to commit and check the reply.
228     Test_Commit_With_No_Transactions
229     [Teardown]    Utils.Report_Failure_Due_To_Bug    4455
230
231 Remove_Not_Existing_Module
232     [Documentation]    Attempt to remove the "module" element again and check that the operation is "silently ignored".
233     Perform_Test    remove-not-existing
234
235 Commit_Remove_Not_Existing_Module
236     [Documentation]    Attempt to commit and check the reply.
237     Perform_Test    remove-not-existing-commit
238
239 Close_Session
240     [Documentation]    Close the session and check that it was closed properly.
241     Perform_Test    close-session
242
243 *** Keywords ***
244 Get_Data
245     [Arguments]    ${name}
246     [Documentation]    Load the specified data from the data directory and return it.
247     ${data}=    OperatingSystem.Get_File    ${datadir}${/}${name}.${dataext}
248     [Return]    ${data}
249
250 Open_ODL_Netconf_Connection
251     [Arguments]    ${host}=${CONTROLLER}    ${port}=${ODL_NETCONF_PORT}    ${user}=${ODL_NETCONF_USER}    ${password}=${ODL_NETCONF_PASSWORD}
252     [Documentation]    Open a netconf connecion to the given machine.
253     # The "-s netconf" flag (see the "SSHLibrary.Write" line below)    is not
254     # supported by SSHLibrary, therefore we need to use this elaborate and
255     # pretty tricky way to connect to the ODL Netconf port.
256     # TODO: Extract into NetconfKeywords as there are other tests that are
257     #    going to need to use this operation (Netconf Performance and Scaling
258     #    comes to my mind now as one of the things tested is the performance
259     #    of the direct netconf connection.
260     ${control}=    SSHLibrary.Open_Connection    ${host}    prompt=${ODL_SYSTEM_PROMPT}    timeout=10s
261     Utils.Flexible_Controller_Login
262     BuiltIn.Set_Suite_Variable    ${ssh_control}    ${control}
263     ${netconf}=    SSHLibrary.Open_Connection    ${host}    prompt=${ODL_SYSTEM_PROMPT}    timeout=10s
264     Utils.Flexible_Controller_Login
265     BuiltIn.Set_Suite_Variable    ${ssh_netconf}    ${netconf}
266     SSHLibrary.Write    sshpass -p ${password} ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ${user}\@127.0.0.1 -p ${port} -s netconf
267     ${hello}=    SSHLibrary.Read_Until    ${ODL_NETCONF_PROMPT}
268     SSHLibrary.Switch_Connection    ${ssh_control}
269     ${pid}=    SSHLibrary.Execute_Command    ps -A | grep sshpass | cut -b 1-6
270     BuiltIn.Set_Suite_Variable    ${ssh_netconf_pid}    ${pid}
271     SSHLibrary.Switch_Connection    ${ssh_netconf}
272     [Return]    ${hello}
273
274 Transmit_Message
275     [Arguments]    ${message}
276     [Documentation]    Transmit message to Netconf connection and discard the echo of the message.
277     SSHLibrary.Write    ${message}
278     SSHLibrary.Write    ${ODL_NETCONF_PROMPT}
279     SSHLibrary.Read_Until    ${ODL_NETCONF_PROMPT}
280
281 Send_Message
282     [Arguments]    ${message}
283     [Documentation]    Send message to Netconf connection and get the reply.
284     Transmit_Message    ${message}
285     ${reply}=    SSHLibrary.Read_Until    ${ODL_NETCONF_PROMPT}
286     [Return]    ${reply}
287
288 Prepare_For_Search
289     [Arguments]    ${searched_string}
290     [Documentation]    Prepare the specified string for searching in Netconf connection replies.
291     ...    The string passed to this keyword is coming from a data
292     ...    file which has different end of line conventions than
293     ...    the actual Netconf reply. This keyword patches the string
294     ...    to match what Netconf actually returns.
295     ${result}=    BuiltIn.Evaluate    "\\r\\n".join("""${searched_string}""".split("\\n"))
296     [Return]    ${result}
297
298 Load_And_Send_Message
299     [Arguments]    ${name}
300     [Documentation]    Load a message from the data file set, send it to Netconf and return the reply.
301     ${request}=    Get_Data    ${name}-request
302     ${reply}=    Send_Message    ${request}
303     [Return]    ${reply}
304
305 Load_Expected_Reply
306     [Arguments]    ${name}
307     [Documentation]    Load the expected reply from the data file set and return it.
308     ${expected_reply}=    Get_Data    ${name}-reply
309     ${expected}=    Prepare_For_Search    ${expected_reply}
310     [Return]    ${expected}
311
312 Close_ODL_Netconf_Connection
313     [Documentation]    Correctly close the Netconf connection and make sure it is really dead.
314     BuiltIn.Return_From_Keyword_If    ${ssh_netconf_pid} == -1
315     ${kill_command}=    BuiltIn.Set_Variable    kill ${ssh_netconf_pid}
316     BuiltIn.Set_Suite_Variable    ${ssh_netconf_pid}    -1
317     SSHLibrary.Switch_Connection    ${ssh_control}
318     SSHLibrary.Write    ${kill_command}
319     SSHLibrary.Read_Until_Prompt
320     SSHLibrary.Switch_Connection    ${ssh_netconf}
321     SSHLibrary.Read_Until_Prompt
322
323 Setup_Everything
324     [Documentation]    Setup resources and create session for Restconf checking.
325     SetupUtils.Setup_Utils_For_Setup_And_Teardown
326     RequestsLibrary.Create_Session    config    http://${CONTROLLER}:${RESTCONFPORT}${CONFIG_API}    auth=${AUTH}
327
328 Teardown_Everything
329     [Documentation]    Close the Netconf connection and destroy all sessions in the requests library.
330     Close_ODL_Netconf_Connection
331     RequestsLibrary.Delete_All_Sessions
332
333 Check_Test_Objects_Not_Present_In_Config
334     [Arguments]    ${name}
335     [Documentation]    Use dataset with the specified name to get the configuration and check that none of our test objects are there.
336     ${reply}=    Load_And_Send_Message    ${name}
337     BuiltIn.Should_Not_Contain    ${reply}    <name>name0</name>
338     BuiltIn.Should_Not_Contain    ${reply}    <name>name1</name>
339     BuiltIn.Should_Not_Contain    ${reply}    <name>name2</name>
340     BuiltIn.Should_Not_Contain    ${reply}    <name>name3</name>
341     BuiltIn.Should_Not_Contain    ${reply}    <name>name4</name>
342
343 Perform_Test
344     [Arguments]    ${name}
345     [Documentation]    Load and send the request from the dataset and compare the returned reply to the one stored in the dataset.
346     ${actual}=    Load_And_Send_Message    ${name}
347     ${expected}=    Load_Expected_Reply    ${name}
348     ${newline}=    BuiltIn.Evaluate    "\\r\\n"
349     BuiltIn.Should_Be_Equal    ${actual}    ${newline}${expected}${ODL_NETCONF_PROMPT}
350     [Return]    ${actual}
351
352 Send_And_Check
353     [Arguments]    ${name}    ${expected}
354     ${actual}=    Load_And_Send_Message    ${name}
355     BuiltIn.Should_Be_Equal    ${actual}    ${expected}
356
357 Test_Commit_With_No_Transactions
358     [Documentation]    Issue a "commit" RPC request and check that it fails with "No current transactions" error.
359     ${reply}=    Load_And_Send_Message    commit-no-transaction
360     ${expected}=    Load_Expected_Reply    commit-no-transaction
361     BuiltIn.Should_Contain    ${reply}    ${expected}