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