Replaced NetconfViaRestconf.robot with TemplatedRequests.robot
[integration/test.git] / csit / suites / netconf / clustering / CRUD.robot
1 *** Settings ***
2 Documentation     netconf clustered CRUD test suite.
3 ...
4 ...               Copyright (c) 2016 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 ...               Perform basic operations (Create, Read, Update and Delete or CRUD) on device
12 ...               data mounted onto a netconf connector and see if they work.
13 ...
14 ...               The suite recognizes 3 nodes, "CONFIGURER" (the node that configures the
15 ...               device at the beginning and then deconfigures it at the end), "SETTER" (the
16 ...               node that manipulates the data on the device) and "CHECKER" (the node that
17 ...               checks the data on the device). The configured device and the results of each
18 ...               data operation on it is expected to be visible on all nodes so after each
19 ...               operation three test cases make sure they can see the result on their
20 ...               respective nodes.
21 ...
22 ...               The 3 nodes are configured by placing "node1", "node2" or "node3" into the
23 ...               ${NODE_CONFIGURER}, ${NODE_SETTER} and ${NODE_CHECKER} to make the node
24 ...               a "CONFIGURER", "SETTER" and "CHECKER" respectively. The "nodeX" name refers
25 ...               to the node with its IP address configured with the ${ODL_SYSTEM_X_IP}
26 ...               variable where the "X" is 1, 2 or 3.
27 ...
28 ...               The suite checks the integrity of the presence of the device and the data
29 ...               seen on the device only for nodes that have at least one of the roles
30 ...               ("CONFIGURER", "SETTER" and "CHECKER") assigned. A better design would have
31 ...               a "checker list" of sorts and have only one checking test case that runs
32 ...               through the check list and performs the test on each node listed. However
33 ...               this currently has fairly low priority due to Beryllium delivery date so
34 ...               it was left out.
35 Suite Setup       Setup_Everything
36 Suite Teardown    Teardown_Everything
37 Test Setup        SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
38 Library           Collections
39 Library           RequestsLibrary
40 Library           OperatingSystem
41 Library           String
42 Library           SSHLibrary    timeout=10s
43 Resource          ${CURDIR}/../../../libraries/FailFast.robot
44 Resource          ${CURDIR}/../../../libraries/KarafKeywords.robot
45 Resource          ${CURDIR}/../../../libraries/NetconfKeywords.robot
46 Resource          ${CURDIR}/../../../libraries/SetupUtils.robot
47 Resource          ${CURDIR}/../../../libraries/TemplatedRequests.robot
48 Resource          ${CURDIR}/../../../libraries/Utils.robot
49 Variables         ${CURDIR}/../../../variables/Variables.py
50
51 *** Variables ***
52 ${NODE_CONFIGURER}    node1
53 ${NODE_SETTER}    node2
54 ${NODE_CHECKER}    node3
55 ${DEVICE_CHECK_TIMEOUT}    60s
56 ${DEVICE_NAME}    netconf-test-device
57 ${directory_with_template_folders}    ${CURDIR}/../../../variables/netconf/CRUD
58 ${empty_data}     <data xmlns="${ODL_NETCONF_NAMESPACE}"></data>
59 ${original_data}    <data xmlns="${ODL_NETCONF_NAMESPACE}"><cont xmlns="urn:opendaylight:test:netconf:crud"><l>Content</l></cont></data>
60 ${modified_data}    <data xmlns="${ODL_NETCONF_NAMESPACE}"><cont xmlns="urn:opendaylight:test:netconf:crud"><l>Modified Content</l></cont></data>
61
62 *** Test Cases ***
63 Start_Testtool
64     [Documentation]    Deploy and start test tool, then wait for all its devices to become online.
65     NetconfKeywords.Install_And_Start_Testtool    device-count=1    schemas=${CURDIR}/../../../variables/netconf/CRUD/schemas
66
67 Check_Device_Is_Not_Mounted_At_Beginning
68     [Documentation]    Sanity check making sure our device is not there. Fail if found.
69     [Tags]    critical
70     NetconfKeywords.Check_Device_Has_No_Netconf_Connector    ${DEVICE_NAME}    session=${NODE_CONFIGURER}
71
72 Configure_Device_On_Netconf
73     [Documentation]    Make request to configure a testtool device on Netconf connector
74     [Tags]    critical
75     NetconfKeywords.Configure_Device_In_Netconf    ${DEVICE_NAME}    device_type=configure-via-topology    session=${NODE_CONFIGURER}
76     [Teardown]    Utils.Report_Failure_Due_To_Bug    5089
77
78 Check_Configurer_Has_Netconf_Connector_For_Device
79     [Documentation]    Get the list of mounts and search for our device there. Fail if not found.
80     [Tags]    critical
81     BuiltIn.Wait_Until_Keyword_Succeeds    ${DEVICE_CHECK_TIMEOUT}    1s    Check_Device_Instance_Count    1    session=${NODE_CONFIGURER}
82
83 Wait_For_Device_To_Become_Visible_For_Configurer
84     [Documentation]    Wait until the device becomes visible on configurer node.
85     NetconfKeywords.Wait_Device_Connected    ${DEVICE_NAME}    session=${NODE_CONFIGURER}
86
87 Wait_For_Device_To_Become_Visible_For_Checker
88     [Documentation]    Wait until the device becomes visible on checker node.
89     NetconfKeywords.Wait_Device_Connected    ${DEVICE_NAME}    session=${NODE_CHECKER}
90
91 Wait_For_Device_To_Become_Visible_For_Setter
92     [Documentation]    Wait until the device becomes visible on setter node.
93     NetconfKeywords.Wait_Device_Connected    ${DEVICE_NAME}    session=${NODE_SETTER}
94
95 Check_Device_Data_Is_Seen_As_Empty_On_Configurer
96     [Documentation]    Get the device data as seen by configurer and make sure it is empty.
97     BuiltIn.Wait_Until_Keyword_Succeeds    ${DEVICE_CHECK_TIMEOUT}    1s    Check_Config_Data    ${NODE_CONFIGURER}    ${empty_data}
98
99 Check_Device_Data_Is_Seen_As_Empty_On_Checker
100     [Documentation]    Get the device data as seen by checker and make sure it is empty.
101     BuiltIn.Wait_Until_Keyword_Succeeds    ${DEVICE_CHECK_TIMEOUT}    1s    Check_Config_Data    ${NODE_CHECKER}    ${empty_data}
102
103 Check_Device_Data_Is_Seen_As_Empty_On_Setter
104     [Documentation]    Get the device data as seen by setter and make sure it is empty.
105     BuiltIn.Wait_Until_Keyword_Succeeds    ${DEVICE_CHECK_TIMEOUT}    1s    Check_Config_Data    ${NODE_SETTER}    ${empty_data}
106
107 Create_Device_Data
108     [Documentation]    Send some sample test data into the device and check that the request went OK.
109     ${template_as_string}=    BuiltIn.Set_Variable    {'DEVICE_NAME': '${DEVICE_NAME}'}
110     TemplatedRequests.Post_As_Xml_Templated    ${directory_with_template_folders}${/}dataorig    ${template_as_string}    session=${NODE_SETTER}
111
112 Check_New_Device_Data_Is_Visible_On_Setter
113     [Documentation]    Get the device data and make sure it contains the created content.
114     BuiltIn.Wait_Until_Keyword_Succeeds    ${DEVICE_CHECK_TIMEOUT}    1s    Check_Config_Data    ${NODE_SETTER}    ${original_data}
115
116 Check_New_Device_Data_Is_Visible_On_Checker
117     [Documentation]    Check that the created device data make their way into the checker node.
118     BuiltIn.Wait_Until_Keyword_Succeeds    ${DEVICE_CHECK_TIMEOUT}    1s    Check_Config_Data    ${NODE_CHECKER}    ${original_data}
119
120 Check_New_Device_Data_Is_Visible_On_Configurer
121     [Documentation]    Check that the created device data make their way into the configurer node.
122     BuiltIn.Wait_Until_Keyword_Succeeds    ${DEVICE_CHECK_TIMEOUT}    1s    Check_Config_Data    ${NODE_CONFIGURER}    ${original_data}
123
124 Modify_Device_Data
125     [Documentation]    Send a request to change the sample test data and check that the request went OK.
126     ${template_as_string}=    BuiltIn.Set_Variable    {'DEVICE_NAME': '${DEVICE_NAME}'}
127     TemplatedRequests.Put_As_Xml_Templated    ${directory_with_template_folders}${/}datamod1    ${template_as_string}    session=${NODE_SETTER}
128     [Teardown]    Utils.Report_Failure_Due_To_Bug    4968
129
130 Check_Device_Data_Is_Modified
131     [Documentation]    Get the device data and make sure it contains the modified content.
132     Check_Config_Data    ${NODE_SETTER}    ${modified_data}
133     [Teardown]    Utils.Report_Failure_Due_To_Bug    4968
134
135 Check_Modified_Device_Data_Is_Visible_On_Checker
136     [Documentation]    Check that the modified device data make their way into the checker node.
137     BuiltIn.Wait_Until_Keyword_Succeeds    60s    1s    Check_Config_Data    ${NODE_CHECKER}    ${modified_data}
138     [Teardown]    Utils.Report_Failure_Due_To_Bug    4968
139
140 Check_Modified_Device_Data_Is_Visible_On_Configurer
141     [Documentation]    Check that the modified device data make their way into the configurer node.
142     BuiltIn.Wait_Until_Keyword_Succeeds    60s    1s    Check_Config_Data    ${NODE_CONFIGURER}    ${modified_data}
143     [Teardown]    Utils.Report_Failure_Due_To_Bug    4968
144
145 Delete_Device_Data
146     [Documentation]    Send a request to delete the sample test data on the device and check that the request went OK.
147     ${template_as_string}=    BuiltIn.Set_Variable    {'DEVICE_NAME': '${DEVICE_NAME}'}
148     TemplatedRequests.Delete_Templated    ${directory_with_template_folders}${/}datamod1    ${template_as_string}    session=${NODE_SETTER}
149     [Teardown]    Utils.Report_Failure_Due_To_Bug    4968
150
151 Check_Device_Data_Is_Deleted
152     [Documentation]    Get the device data and make sure it is empty again.
153     Check_Config_Data    ${NODE_SETTER}    ${empty_data}
154     [Teardown]    Utils.Report_Failure_Due_To_Bug    4968
155
156 Check_Device_Data_Deletion_Is_Visible_On_Checker
157     [Documentation]    Check that the device data deletion makes its way into the checker node.
158     BuiltIn.Wait_Until_Keyword_Succeeds    60s    1s    Check_Config_Data    ${NODE_CHECKER}    ${empty_data}
159     [Teardown]    Utils.Report_Failure_Due_To_Bug    4968
160
161 Check_Device_Data_Deletion_Is_Visible_On_Configurer
162     [Documentation]    Check that the device data deletion makes its way into the checker node.
163     BuiltIn.Wait_Until_Keyword_Succeeds    60s    1s    Check_Config_Data    ${NODE_CONFIGURER}    ${empty_data}
164     [Teardown]    Utils.Report_Failure_Due_To_Bug    4968
165
166 Deconfigure_Device_In_Netconf
167     [Documentation]    Make request to deconfigure the device on Netconf connector.
168     [Tags]    critical
169     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
170     NetconfKeywords.Remove_Device_From_Netconf    ${DEVICE_NAME}    session=${NODE_CONFIGURER}
171
172 Check_Device_Deconfigured_On_Configurer
173     [Documentation]    Check that the device is really going to be gone. Fail if still there after one minute.
174     ...    This is an expected behavior as the unmount request is sent to the config subsystem which
175     ...    then triggers asynchronous disconnection of the device which is reflected in the operational
176     ...    data once completed. This test makes sure this asynchronous operation does not take
177     ...    unreasonable amount of time.
178     [Tags]    critical
179     NetconfKeywords.Wait_Device_Fully_Removed    ${DEVICE_NAME}    session=${NODE_CONFIGURER}
180
181 Check_Device_Deconfigured_On_Checker
182     [Documentation]    Check that the device is going to be gone from the checker node. Fail if still there after one minute.
183     [Tags]    critical
184     NetconfKeywords.Wait_Device_Fully_Removed    ${DEVICE_NAME}    session=${NODE_CHECKER}
185
186 Check_Device_Deconfigured_On_Setter
187     [Documentation]    Check that the device is going to be gone from the setter node. Fail if still there after one minute.
188     [Tags]    critical
189     NetconfKeywords.Wait_Device_Fully_Removed    ${DEVICE_NAME}    session=${NODE_SETTER}
190
191 *** Keywords ***
192 Setup_Everything
193     [Documentation]    Setup everything needed for the test cases.
194     # Setup resources used by the suite.
195     SetupUtils.Setup_Utils_For_Setup_And_Teardown
196     NetconfKeywords.Setup_Netconf_Keywords    create_session_for_templated_requests=False
197     RequestsLibrary.Create_Session    node1    http://${ODL_SYSTEM_1_IP}:${RESTCONFPORT}    headers=${HEADERS_XML}    auth=${AUTH}
198     RequestsLibrary.Create_Session    node2    http://${ODL_SYSTEM_2_IP}:${RESTCONFPORT}    headers=${HEADERS_XML}    auth=${AUTH}
199     RequestsLibrary.Create_Session    node3    http://${ODL_SYSTEM_3_IP}:${RESTCONFPORT}    headers=${HEADERS_XML}    auth=${AUTH}
200
201 Teardown_Everything
202     [Documentation]    Teardown the test infrastructure, perform cleanup and release all resources.
203     RequestsLibrary.Delete_All_Sessions
204     NetconfKeywords.Stop_Testtool
205
206 Check_Device_Instance_Count
207     [Arguments]    ${expected}    ${session}
208     ${count}    NetconfKeywords.Count_Netconf_Connectors_For_Device    ${DEVICE_NAME}    session=${session}
209     Builtin.Should_Be_Equal_As_Strings    ${count}    ${expected}
210
211 Check_Config_Data
212     [Arguments]    ${node}    ${expected}    ${contains}=False
213     ${url}=    Builtin.Set_Variable    ${CONFIG_API}/network-topology:network-topology/topology/topology-netconf/node/${DEVICE_NAME}/yang-ext:mount
214     ${data}=    TemplatedRequests.Get_As_Xml_From_Uri    ${url}    session=${node}
215     BuiltIn.Run_Keyword_Unless    ${contains}    BuiltIn.Should_Be_Equal_As_Strings    ${data}    ${expected}
216     BuiltIn.Run_Keyword_If    ${contains}    BuiltIn.Should_Contain    ${data}    ${expected}