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