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