87431997c3529378514a70b8962ecfb6e23a9cb9
[integration/test.git] / csit / suites / netconf / CRUD / CRUD.robot
1 *** Settings ***
2 Documentation     netconf-connector CRUD 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 ...               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 Suite Setup       Setup_Everything
14 Suite Teardown    Teardown_Everything
15 Test Setup        SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
16 Library           Collections
17 Library           RequestsLibrary
18 Library           OperatingSystem
19 Library           String
20 Library           SSHLibrary    timeout=10s
21 Resource          ${CURDIR}/../../../libraries/FailFast.robot
22 Resource          ${CURDIR}/../../../libraries/KarafKeywords.robot
23 Resource          ${CURDIR}/../../../libraries/NetconfKeywords.robot
24 Resource          ${CURDIR}/../../../libraries/NetconfViaRestconf.robot
25 Resource          ${CURDIR}/../../../libraries/SetupUtils.robot
26 Resource          ${CURDIR}/../../../libraries/Utils.robot
27 Variables         ${CURDIR}/../../../variables/Variables.py
28
29 *** Variables ***
30 ${DIRECTORY_WITH_TEMPLATE_FOLDERS}    ${CURDIR}/../../../variables/netconf/CRUD
31 ${device_name}    netconf-test-device
32
33 *** Test Cases ***
34 Start_Testtool
35     [Documentation]    Deploy and start test tool, then wait for all its devices to become online.
36     NetconfKeywords.Install_And_Start_Testtool    device-count=1    schemas=${CURDIR}/../../../variables/netconf/CRUD/schemas
37
38 Check_Device_Is_Not_Configured_At_Beginning
39     [Documentation]    Sanity check making sure our device is not there. Fail if found.
40     [Tags]    critical
41     NetconfKeywords.Check_Device_Has_No_Netconf_Connector    ${device_name}
42
43 Configure_Device_On_Netconf
44     [Documentation]    Make request to configure a testtool device on Netconf connector.
45     [Tags]    critical
46     NetconfKeywords.Configure_Device_In_Netconf    ${device_name}
47
48 Check_ODL_Has_Netconf_Connector_For_Device
49     [Documentation]    Get the list of configured devices and search for our device there. Fail if not found.
50     [Tags]    critical
51     ${count}    NetconfKeywords.Count_Netconf_Connectors_For_Device    ${device_name}
52     Builtin.Should_Be_Equal_As_Strings    ${count}    1
53
54 Wait_For_Device_To_Become_Connected
55     [Documentation]    Wait until the device becomes available through Netconf.
56     NetconfKeywords.Wait_Device_Connected    ${device_name}
57
58 Check_Device_Data_Is_Empty
59     [Documentation]    Get the device data and make sure it is empty.
60     Check_Config_Data    <data xmlns="${ODL_NETCONF_NAMESPACE}"></data>
61
62 Create_Device_Data
63     [Documentation]    Send some sample test data into the device and check that the request went OK.
64     ${template_as_string}=    BuiltIn.Set_Variable    {'DEVICE_NAME': '${device_name}'}
65     NetconfViaRestconf.Post_Xml_Template_Folder_Via_Restconf    ${DIRECTORY_WITH_TEMPLATE_FOLDERS}${/}dataorig    ${template_as_string}
66
67 Check_Device_Data_Is_Created
68     [Documentation]    Get the device data and make sure it contains the created content.
69     Check_Config_Data    <data xmlns="${ODL_NETCONF_NAMESPACE}"><cont xmlns="urn:opendaylight:test:netconf:crud"><l>Content</l></cont></data>
70
71 Modify_Device_Data
72     [Documentation]    Send a request to change the sample test data and check that the request went OK.
73     ${template_as_string}=    BuiltIn.Set_Variable    {'DEVICE_NAME': '${device_name}'}
74     NetconfViaRestconf.Put_Xml_Template_Folder_Via_Restconf    ${DIRECTORY_WITH_TEMPLATE_FOLDERS}${/}datamod1    ${template_as_string}
75
76 Check_Device_Data_Is_Modified
77     [Documentation]    Get the device data and make sure it contains the created content.
78     Check_Config_Data    <data xmlns="${ODL_NETCONF_NAMESPACE}"><cont xmlns="urn:opendaylight:test:netconf:crud"><l>Modified Content</l></cont></data>
79
80 Modify_Device_Data_Via_JSON
81     [Documentation]    Send a JSON request to change the sample test data and check that the request went OK.
82     ${template_as_string}=    BuiltIn.Set_Variable    {'DEVICE_NAME': '${device_name}'}
83     NetconfViaRestconf.Put_Json_Template_Folder_Via_Restconf    ${DIRECTORY_WITH_TEMPLATE_FOLDERS}${/}datamodjson    ${template_as_string}
84
85 Check_Device_Data_Is_Modified_Via_JSON
86     [Documentation]    Get the device data as XML and make sure it matches the content posted as JSON in the previous case.
87     Check_Config_Data    <data xmlns="${ODL_NETCONF_NAMESPACE}"><cont xmlns="urn:opendaylight:test:netconf:crud"><l>Content Modified via JSON</l></cont></data>
88
89 Delete_Device_Data
90     [Documentation]    Send a request to delete the sample test data on the device and check that the request went OK.
91     ${template_as_string}=    BuiltIn.Set_Variable    {'DEVICE_NAME': '${device_name}'}
92     NetconfViaRestconf.Delete_Xml_Template_Folder_Via_Restconf    ${DIRECTORY_WITH_TEMPLATE_FOLDERS}${/}datamod1    ${template_as_string}
93
94 Check_Device_Data_Is_Deleted
95     [Documentation]    Get the device data and make sure it is empty again.
96     Check_Config_Data    <data xmlns="${ODL_NETCONF_NAMESPACE}"></data>
97
98 Deconfigure_Device_From_Netconf
99     [Documentation]    Make request to deconfigure the testtool device on Netconf connector.
100     [Tags]    critical
101     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
102     NetconfKeywords.Remove_Device_From_Netconf    ${device_name}
103
104 Check_Device_Going_To_Be_Gone_After_Deconfiguring
105     [Documentation]    Check that the device is really going to be gone. Fail
106     ...    if found after one minute. This is an expected behavior as the
107     ...    delete request is sent to the config subsystem which then triggers
108     ...    asynchronous destruction of the netconf connector referring to the
109     ...    device and the device's data. This test makes sure this
110     ...    asynchronous operation does not take unreasonable amount of time
111     ...    by making sure that both the netconf connector and the device's
112     ...    data is gone before reporting success.
113     [Tags]    critical
114     NetconfKeywords.Wait_Device_Fully_Removed    ${device_name}
115
116 *** Keywords ***
117 Setup_Everything
118     [Documentation]    Setup everything needed for the test cases.
119     # Setup resources used by the suite.
120     SetupUtils.Setup_Utils_For_Setup_And_Teardown
121     RequestsLibrary.Create_Session    operational    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}${OPERATIONAL_API}    auth=${AUTH}
122     NetconfKeywords.Setup_Netconf_Keywords
123
124 Teardown_Everything
125     [Documentation]    Teardown the test infrastructure, perform cleanup and release all resources.
126     Teardown_Netconf_Via_Restconf
127     RequestsLibrary.Delete_All_Sessions
128     BuiltIn.Run_Keyword_And_Ignore_Error    NetconfKeywords.Stop_Testtool
129
130 Check_Config_Data
131     [Arguments]    ${expected}    ${contains}=False
132     ${url}=    Builtin.Set_Variable    network-topology:network-topology/topology/topology-netconf/node/${device_name}/yang-ext:mount
133     ${data}=    Utils.Get_Data_From_URI    nvr_session    ${url}    headers=${ACCEPT_XML}
134     BuiltIn.Run_Keyword_Unless    ${contains}    BuiltIn.Should_Be_Equal_As_Strings    ${data}    ${expected}
135     BuiltIn.Run_Keyword_If    ${contains}    BuiltIn.Should_Contain    ${data}    ${expected}