Support both empty data formats
[integration/test.git] / csit / suites / netconf / CRUD / CRUD-RPC.robot
1 *** Settings ***
2 Documentation       netconf-connector CRUD test suite.
3 ...
4 ...                 Copyright (c) 2017 Lumina Networks, 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 ...                 Perform basic operations (Create, Read, Update and Delete or CRUD) on device
12 ...                 data mounted onto a netconf connector using RPC for node addition and see if
13 ...                 they work.
14 ...
15 ...                 FIXME: Replace the BuiltIn.Should_[Not_]Contain instances in the test cases
16 ...                 that check the car list related data with calls to keywords of a Resource
17 ...                 aimed at getting interesting pieces of data from the XML files and checking
18 ...                 them against expected data sets. See MDSAL/northbound.robot suite for
19 ...                 additional information.
20
21 Library             Collections
22 Library             RequestsLibrary
23 Library             OperatingSystem
24 Library             String
25 Library             SSHLibrary    timeout=10s
26 Resource            ${CURDIR}/../../../libraries/FailFast.robot
27 Resource            ${CURDIR}/../../../libraries/NetconfKeywords.robot
28 Resource            ${CURDIR}/../../../libraries/SetupUtils.robot
29 Resource            ${CURDIR}/../../../libraries/TemplatedRequests.robot
30 Resource            ${CURDIR}/../../../libraries/CompareStream.robot
31 Resource            ${CURDIR}/../../../variables/Variables.robot
32
33 Suite Setup         Setup_Everything
34 Suite Teardown      Teardown_Everything
35 Test Setup          SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
36
37
38 *** Variables ***
39 ${directory_with_template_folders}      ${CURDIR}/../../../variables/netconf/CRUD
40 ${device_name}                          netconf-test-device
41 ${device_type_rpc}                      rpc-device
42 ${device_type_rpc_create}               rpc-create-device
43 ${device_type_rpc_delete}               rpc-delete-device
44 ${USE_NETCONF_CONNECTOR}                ${False}
45 ${delete_location}                      delete_location
46
47
48 *** Test Cases ***
49 Start_Testtool
50     [Documentation]    Deploy and start test tool, then wait for all its devices to become online.
51     [Tags]    odlmicro_ign
52     NetconfKeywords.Install_And_Start_Testtool
53     ...    device-count=1
54     ...    schemas=${CURDIR}/../../../variables/netconf/CRUD/schemas
55     ...    mdsal=true
56
57 Check_Device_Is_Not_Configured_At_Beginning
58     [Documentation]    Sanity check making sure our device is not there. Fail if found.
59     [Tags]    critical
60     NetconfKeywords.Check_Device_Has_No_Netconf_Connector    ${device_name}
61
62 Configure_Device_On_Netconf
63     [Documentation]    Make request to configure a testtool device on Netconf connector.
64     [Tags]    critical
65     NetconfKeywords.Configure_Device_In_Netconf
66     ...    ${device_name}
67     ...    device_type=${device_type_rpc_create}
68     ...    http_timeout=2
69     ...    http_method=post
70
71 Check_ODL_Has_Netconf_Connector_For_Device
72     [Documentation]    Get the list of configured devices and search for our device there. Fail if not found.
73     [Tags]    critical
74     ${count}=    NetconfKeywords.Count_Netconf_Connectors_For_Device    ${device_name}
75     Builtin.Should_Be_Equal_As_Strings    ${count}    1
76
77 Wait_For_Device_To_Become_Connected
78     [Documentation]    Wait until the device becomes available through Netconf.
79     NetconfKeywords.Wait_Device_Connected    ${device_name}
80
81 Check_Device_Data_Is_Empty
82     [Documentation]    Get the device data and make sure it is empty.
83     ${escaped}=    BuiltIn.Regexp_Escape    ${ODL_NETCONF_NAMESPACE}
84     Check_Config_Data    <data xmlns\="${escaped}"(\/>|><\/data>)    ${True}
85
86 Create_Device_Data_Label_Via_Xml
87     [Documentation]    Send a sample test data label into the device and check that the request went OK.
88     ${template_as_string}=    BuiltIn.Create_Dictionary    DEVICE_NAME=${device_name}
89     TemplatedRequests.Post_As_Xml_Templated    ${directory_with_template_folders}${/}dataorig    ${template_as_string}
90
91 Check_Device_Data_Label_Is_Created
92     [Documentation]    Get the device data label and make sure it contains the created content.
93     Check_Config_Data
94     ...    <data xmlns="${ODL_NETCONF_NAMESPACE}"><cont xmlns="urn:opendaylight:test:netconf:crud"><l>Content</l></cont></data>
95
96 Modify_Device_Data_Label_Via_Xml
97     [Documentation]    Send a request to change the sample test data label and check that the request went OK.
98     ${template_as_string}=    BuiltIn.Create_Dictionary    DEVICE_NAME=${device_name}
99     TemplatedRequests.Put_As_Xml_Templated    ${directory_with_template_folders}${/}datamod1    ${template_as_string}
100
101 Check_Device_Data_Label_Is_Modified
102     [Documentation]    Get the device data label and make sure it contains the modified content.
103     Check_Config_Data
104     ...    <data xmlns="${ODL_NETCONF_NAMESPACE}"><cont xmlns="urn:opendaylight:test:netconf:crud"><l>Modified Content</l></cont></data>
105
106 Deconfigure_Device_From_Netconf_Temporarily
107     [Documentation]    Make request to deconfigure the testtool device on Netconf connector.
108     ...    This is the first part of the "configure/deconfigure" cycle of the device
109     ...    The purpose of cycling the device like this is to see that the configuration
110     ...    data was really stored in the device.
111     [Tags]    critical
112     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
113     NetconfKeywords.Configure_Device_In_Netconf
114     ...    ${device_name}
115     ...    device_type=${device_type_rpc_delete}
116     ...    http_timeout=2
117     ...    http_method=post
118
119 Wait_For_Device_To_Be_Gone
120     [Documentation]    Wait for the device to completely disappear.
121     NetconfKeywords.Wait_Device_Fully_Removed    ${device_name}
122
123 Configure_The_Device_Back
124     [Documentation]    Configure the device again.
125     ...    This is the second step of the device configuration.
126     [Tags]    critical
127     NetconfKeywords.Configure_Device_In_Netconf
128     ...    ${device_name}
129     ...    device_type=${device_type_rpc_create}
130     ...    http_timeout=2
131     ...    http_method=post
132
133 Wait_For_Device_To_Reconnect
134     [Documentation]    Wait until the device becomes available through Netconf.
135     NetconfKeywords.Wait_Device_Connected    ${device_name}
136
137 Check_Modified_Device_Data_Is_Still_There
138     [Documentation]    Get the device data and make sure it contains the created content.
139     BuiltIn.Wait_Until_Keyword_Succeeds
140     ...    60s
141     ...    1s
142     ...    Check_Config_Data
143     ...    <data xmlns="${ODL_NETCONF_NAMESPACE}"><cont xmlns="urn:opendaylight:test:netconf:crud"><l>Modified Content</l></cont></data>
144
145 Modify_Device_Data_Again
146     [Documentation]    Send a request to change the sample test data and check that the request went OK.
147     ${template_as_string}=    BuiltIn.Create_Dictionary    DEVICE_NAME=${device_name}
148     TemplatedRequests.Put_As_Xml_Templated    ${DIRECTORY_WITH_TEMPLATE_FOLDERS}${/}datamod2    ${template_as_string}
149
150 Check_Device_Data_Is_Modified_Again
151     [Documentation]    Get the device data and make sure it contains the created content.
152     Check_Config_Data
153     ...    <data xmlns="${ODL_NETCONF_NAMESPACE}"><cont xmlns="urn:opendaylight:test:netconf:crud"><l>Another Modified Content</l></cont></data>
154
155 Modify_Device_Data_Label_Via_Json
156     [Documentation]    Send a JSON request to change the sample test data label and check that the request went OK.
157     ${template_as_string}=    BuiltIn.Create_Dictionary    DEVICE_NAME=${device_name}
158     TemplatedRequests.Put_As_Json_Templated
159     ...    ${directory_with_template_folders}${/}datamodjson
160     ...    ${template_as_string}
161
162 Check_Device_Data_Label_Is_Modified_Via_Json
163     [Documentation]    Get the device data label as XML and make sure it matches the content posted as JSON in the previous case.
164     Check_Config_Data
165     ...    <data xmlns="${ODL_NETCONF_NAMESPACE}"><cont xmlns="urn:opendaylight:test:netconf:crud"><l>Content Modified via JSON</l></cont></data>
166
167 Create_Car_List
168     [Documentation]    Send a request to create a list of cars in the sample test data label and check that the request went OK.
169     ${template_as_string}=    BuiltIn.Create_Dictionary    DEVICE_NAME=${device_name}
170     TemplatedRequests.Post_As_Xml_Templated    ${directory_with_template_folders}${/}cars    ${template_as_string}
171
172 Check_Car_List_Created
173     [Documentation]    Get the device data label as XML and make sure it matches the content posted as JSON in the previous case.
174     ${data}=    Get_Config_Data
175     BuiltIn.Should_Contain    ${data}    <id>KEEP</id>
176     BuiltIn.Should_Not_Contain    ${data}    <id>SMALL</id>
177     BuiltIn.Should_Not_Contain    ${data}    <model>Isetta</model>
178     BuiltIn.Should_Not_Contain    ${data}    <manufacturer>BMW</manufacturer>
179     BuiltIn.Should_Not_Contain    ${data}    <year>1953</year>
180     BuiltIn.Should_Not_Contain    ${data}    <category>microcar</category>
181     BuiltIn.Should_Not_Contain    ${data}    <id>TOYOTA</id>
182     BuiltIn.Should_Not_Contain    ${data}    <model>Camry</model>
183     BuiltIn.Should_Not_Contain    ${data}    <manufacturer>Toyota</manufacturer>
184     BuiltIn.Should_Not_Contain    ${data}    <year>1982</year>
185     BuiltIn.Should_Not_Contain    ${data}    <category>sedan</category>
186
187 Add_Device_Data_Item_1_Via_XML_Post
188     [Documentation]    Send a request to create a data item in the test list and check that the request went OK.
189     ${template_as_string}=    BuiltIn.Create_Dictionary    DEVICE_NAME=${device_name}
190     TemplatedRequests.Post_As_Xml_Templated    ${directory_with_template_folders}${/}item1    ${template_as_string}
191
192 Check_Item1_Is_Created
193     [Documentation]    Get the device data as XML and make sure it matches the content posted as JSON in the previous case.
194     ${data}=    Get_Config_Data
195     BuiltIn.Should_Contain    ${data}    <id>SMALL</id>
196     BuiltIn.Should_Contain    ${data}    <model>Isetta</model>
197     BuiltIn.Should_Contain    ${data}    <manufacturer>BMW</manufacturer>
198     BuiltIn.Should_Contain    ${data}    <year>1953</year>
199     BuiltIn.Should_Contain    ${data}    <category>microcar</category>
200     BuiltIn.Should_Not_Contain    ${data}    <id>TOYOTA</id>
201     BuiltIn.Should_Not_Contain    ${data}    <model>Camry</model>
202     BuiltIn.Should_Not_Contain    ${data}    <manufacturer>Toyota</manufacturer>
203     BuiltIn.Should_Not_Contain    ${data}    <year>1982</year>
204     BuiltIn.Should_Not_Contain    ${data}    <category>sedan</category>
205
206 Add_Device_Data_Item_2_Via_JSON_Post
207     [Documentation]    Send a JSON request to change the sample test data and check that the request went OK.
208     ${template_as_string}=    BuiltIn.Create_Dictionary    DEVICE_NAME=${device_name}
209     TemplatedRequests.Post_As_Json_Templated    ${directory_with_template_folders}${/}item2    ${template_as_string}
210
211 Check_Item2_Is_Created
212     [Documentation]    Get the device data as XML and make sure it matches the content posted as JSON in the previous case.
213     ${data}=    Get_Config_Data
214     BuiltIn.Should_Contain    ${data}    <id>SMALL</id>
215     BuiltIn.Should_Contain    ${data}    <model>Isetta</model>
216     BuiltIn.Should_Contain    ${data}    <manufacturer>BMW</manufacturer>
217     BuiltIn.Should_Contain    ${data}    <year>1953</year>
218     BuiltIn.Should_Contain    ${data}    <category>microcar</category>
219     BuiltIn.Should_Contain    ${data}    <id>TOYOTA</id>
220     BuiltIn.Should_Contain    ${data}    <model>Camry</model>
221     BuiltIn.Should_Contain    ${data}    <manufacturer>Toyota</manufacturer>
222     BuiltIn.Should_Contain    ${data}    <year>1982</year>
223     BuiltIn.Should_Contain    ${data}    <category>sedan</category>
224
225 Delete_Device_Data
226     [Documentation]    Send a request to delete the sample test data on the device and check that the request went OK.
227     ${template_as_string}=    BuiltIn.Create_Dictionary    DEVICE_NAME=${device_name}
228     TemplatedRequests.Delete_Templated    ${directory_with_template_folders}${/}datamod1    ${template_as_string}
229     TemplatedRequests.Delete_Templated    ${directory_with_template_folders}${/}item1    ${template_as_string}
230
231 Check_Device_Data_Is_Deleted
232     [Documentation]    Get the device data and make sure it is empty again.
233     ${escaped}=    BuiltIn.Regexp_Escape    ${ODL_NETCONF_NAMESPACE}
234     Check_Config_Data    <data xmlns\="${escaped}"(\/>|><\/data>)    ${True}
235
236 Deconfigure_Device_From_Netconf
237     [Documentation]    Make request to deconfigure the testtool device on Netconf connector.
238     [Tags]    critical
239     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
240     NetconfKeywords.Configure_Device_In_Netconf
241     ...    ${device_name}
242     ...    device_type=${device_type_rpc_delete}
243     ...    http_timeout=2
244     ...    http_method=post
245
246 Check_Device_Going_To_Be_Gone_After_Deconfiguring
247     [Documentation]    Check that the device is really going to be gone. Fail
248     ...    if found after one minute. This is an expected behavior as the
249     ...    delete request is sent to the config subsystem which then triggers
250     ...    asynchronous destruction of the netconf connector referring to the
251     ...    device and the device's data. This test makes sure this
252     ...    asynchronous operation does not take unreasonable amount of time
253     ...    by making sure that both the netconf connector and the device's
254     ...    data is gone before reporting success.
255     [Tags]    critical
256     NetconfKeywords.Wait_Device_Fully_Removed    ${device_name}
257
258
259 *** Keywords ***
260 Setup_Everything
261     [Documentation]    Initialize SetupUtils. Setup everything needed for the test cases.
262     # Setup resources used by the suite.
263     SetupUtils.Setup_Utils_For_Setup_And_Teardown
264     RequestsLibrary.Create_Session    operational    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}${REST_API}    auth=${AUTH}
265     NetconfKeywords.Setup_Netconf_Keywords
266     ${device_type_rpc}=    BuiltIn.Set_Variable_If
267     ...    """${USE_NETCONF_CONNECTOR}""" == """True"""
268     ...    default
269     ...    ${device_type_rpc}
270
271 Teardown_Everything
272     [Documentation]    Teardown the test infrastructure, perform cleanup and release all resources.
273     RequestsLibrary.Delete_All_Sessions
274     BuiltIn.Run_Keyword_And_Ignore_Error    NetconfKeywords.Stop_Testtool
275
276 Get_Config_Data
277     [Documentation]    Get and return the config data from the device.
278     ${url}=    Builtin.Set_Variable
279     ...    ${REST_API}/network-topology:network-topology/topology=topology-netconf/node=${device_name}/yang-ext:mount?content=config
280     ${data}=    TemplatedRequests.Get_As_Xml_From_Uri    ${url}
281     RETURN    ${data}
282
283 Check_Config_Data
284     [Arguments]    ${expected}    ${regex}=False    ${contains}=False
285     ${data}=    Get_Config_Data
286     IF    ${regex}
287         BuiltIn.Should Match Regexp    ${data}    ${expected}
288     ELSE IF    ${contains}
289         BuiltIn.Should_Contain    ${data}    ${expected}
290     ELSE
291         BuiltIn.Should_Be_Equal_As_Strings    ${data}    ${expected}
292     END