Support both empty data formats
[integration/test.git] / csit / suites / netconf / CRUD-ACTION / CRUD-ACTION.robot
1 *** Settings ***
2 Documentation       netconf-connector CRUD-Action test suite.
3 ...
4 ...                 Copyright (c) 2019 Ericsson Software Technology AB. 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 supporting Yang 1.1
13 ...                 addition and see if invoking Action Operation work.
14
15 Library             Collections
16 Library             RequestsLibrary
17 Library             OperatingSystem
18 Library             String
19 Library             SSHLibrary    timeout=10s
20 Resource            ${CURDIR}/../../../libraries/CompareStream.robot
21 Resource            ${CURDIR}/../../../libraries/FailFast.robot
22 Resource            ${CURDIR}/../../../libraries/NetconfKeywords.robot
23 Resource            ${CURDIR}/../../../libraries/SetupUtils.robot
24 Resource            ${CURDIR}/../../../libraries/TemplatedRequests.robot
25 Resource            ${CURDIR}/../../../variables/Variables.robot
26
27 Suite Setup         Setup_Everything
28 Suite Teardown      Teardown_Everything
29 Test Setup          SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
30
31
32 *** Variables ***
33 ${DIRECTORY_WITH_TEMPLATE_FOLDERS}      ${CURDIR}/../../../variables/netconf/CRUD
34 ${DEVICE_NAME}                          netconf-test-device
35 ${DEVICE_TYPE_RPC}                      rpc-device
36 ${DEVICE_TYPE_RPC_CREATE}               rpc-create-device
37 ${DEVICE_TYPE_RPC_DELETE}               rpc-delete-device
38 ${USE_NETCONF_CONNECTOR}                ${False}
39 ${DELETE_LOCATION}                      delete_location
40 ${RPC_FILE}                             ${CURDIR}/../../../variables/netconf/CRUD/customaction/customaction.xml
41
42
43 *** Test Cases ***
44 Check_Device_Is_Not_Configured_At_Beginning
45     [Documentation]    Sanity check making sure our device is not there. Fail if found.
46     [Tags]    critical
47     NetconfKeywords.Check_Device_Has_No_Netconf_Connector    ${DEVICE_NAME}
48
49 Configure_Device_On_Netconf
50     [Documentation]    Make request to configure a testtool device on Netconf connector.
51     [Tags]    critical
52     NetconfKeywords.Configure_Device_In_Netconf
53     ...    ${DEVICE_NAME}
54     ...    device_type=${DEVICE_TYPE_RPC_CREATE}
55     ...    http_timeout=2
56     ...    http_method=post
57
58 Check_ODL_Has_Netconf_Connector_For_Device
59     [Documentation]    Get the list of configured devices and search for our device there. Fail if not found.
60     [Tags]    critical
61     ${count} =    NetconfKeywords.Count_Netconf_Connectors_For_Device    ${DEVICE_NAME}
62     Builtin.Should_Be_Equal_As_Strings    ${count}    1
63
64 Wait_For_Device_To_Become_Connected
65     [Documentation]    Wait until the device becomes available through Netconf.
66     NetconfKeywords.Wait_Device_Connected    ${DEVICE_NAME}
67
68 Check_Device_Data_Is_Empty
69     [Documentation]    Get the device data and make sure it is empty.
70     ${escaped} =    BuiltIn.Regexp_Escape    ${ODL_NETCONF_NAMESPACE}
71     Check_Config_Data    <data xmlns\="${escaped}"(\/>|><\/data>)    ${True}
72
73 Invoke_Yang1.1_Action_Via_Xml_Post
74     [Documentation]    Send a sample test data label into the device and check that the request went OK.
75     ${template_as_string} =    BuiltIn.Create_Dictionary    DEVICE_NAME=${device_name}
76     TemplatedRequests.Post_As_Xml_Templated
77     ...    ${DIRECTORY_WITH_TEMPLATE_FOLDERS}${/}dataorigaction
78     ...    ${template_as_string}
79
80 Invoke_Yang1.1_Action_Via_Json_Post
81     [Documentation]    Send a sample test data label into the device and check that the request went OK.
82     ${template_as_string} =    BuiltIn.Create_Dictionary    DEVICE_NAME=${device_name}
83     TemplatedRequests.Post_As_Json_RFC8040_Templated
84     ...    ${DIRECTORY_WITH_TEMPLATE_FOLDERS}${/}dataorigaction
85     ...    ${template_as_string}
86
87 Invoke_Yang1.1_Augmentation_Via_Xml_Post
88     [Documentation]    Send a sample test data label into the device and check that the request went OK.
89     ${template_as_string} =    BuiltIn.Create_Dictionary    DEVICE_NAME=${device_name}
90     TemplatedRequests.Post_As_Xml_Templated    ${DIRECTORY_WITH_TEMPLATE_FOLDERS}${/}augment    ${template_as_string}
91
92 Invoke_Yang1.1_Augmentation_Via_Json_Post
93     [Documentation]    Send a sample test data label into the device and check that the request went OK.
94     ${template_as_string} =    BuiltIn.Create_Dictionary    DEVICE_NAME=${device_name}
95     TemplatedRequests.Post_As_Json_RFC8040_Templated
96     ...    ${DIRECTORY_WITH_TEMPLATE_FOLDERS}${/}augment
97     ...    ${template_as_string}
98
99 Deconfigure_Device_From_Netconf
100     [Documentation]    Make request to deconfigure the testtool device on Netconf connector.
101     [Tags]    critical
102     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
103     NetconfKeywords.Configure_Device_In_Netconf
104     ...    ${DEVICE_NAME}
105     ...    device_type=${DEVICE_TYPE_RPC_DELETE}
106     ...    http_timeout=2
107     ...    http_method=post
108
109 Check_Device_Going_To_Be_Gone_After_Deconfiguring
110     [Documentation]    Check that the device is really going to be gone. Fail
111     ...    if found after one minute. This is an expected behavior as the
112     ...    delete request is sent to the config subsystem which then triggers
113     ...    asynchronous destruction of the netconf connector referring to the
114     ...    device and the device's data. This test makes sure this
115     ...    asynchronous operation does not take unreasonable amount of time
116     ...    by making sure that both the netconf connector and the device's
117     ...    data is gone before reporting success.
118     [Tags]    critical
119     NetconfKeywords.Wait_Device_Fully_Removed    ${DEVICE_NAME}
120
121
122 *** Keywords ***
123 Setup_Everything
124     [Documentation]    Initialize SetupUtils. Setup everything needed for the test cases.
125     SetupUtils.Setup_Utils_For_Setup_And_Teardown
126     RequestsLibrary.Create_Session    operational    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}${REST_API}    auth=${AUTH}
127     NetconfKeywords.Setup_Netconf_Keywords
128     ${DEVICE_TYPE_RPC} =    BuiltIn.Set_Variable_If
129     ...    """${USE_NETCONF_CONNECTOR}""" == """True"""
130     ...    default
131     ...    ${DEVICE_TYPE_RPC}
132     OperatingSystem.File Should Exist    ${RPC_FILE}
133     NetconfKeywords.Install_And_Start_Testtool
134     ...    device-count=1
135     ...    schemas=${CURDIR}/../../../variables/netconf/CRUD/schemas
136     ...    rpc_config=${RPC_FILE}
137     ...    mdsal=true
138
139 Teardown_Everything
140     [Documentation]    Teardown the test infrastructure, perform cleanup and release all resources.
141     RequestsLibrary.Delete_All_Sessions
142     BuiltIn.Run_Keyword_And_Ignore_Error    NetconfKeywords.Stop_Testtool
143
144 Get_Config_Data
145     [Documentation]    Get and return the config data from the device.
146     ${url} =    Builtin.Set_Variable
147     ...    ${REST_API}/network-topology:network-topology/topology=topology-netconf/node=${DEVICE_NAME}/yang-ext:mount?content=config
148     ${data} =    TemplatedRequests.Get_As_Xml_From_Uri    ${url}
149     RETURN    ${data}
150
151 Check_Config_Data
152     [Arguments]    ${expected}    ${regex}=False    ${contains}=False
153     ${data} =    Get_Config_Data
154     IF    ${regex}
155         BuiltIn.Should Match Regexp    ${data}    ${expected}
156     ELSE IF    ${contains}
157         BuiltIn.Should_Contain    ${data}    ${expected}
158     ELSE
159         BuiltIn.Should_Be_Equal_As_Strings    ${data}    ${expected}
160     END