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