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