Update Robot Framework format - step 10
[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}
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     Run_Keyword_If_Less_Than_Neon    Check_Config_Data    <data xmlns\="${ODL_NETCONF_NAMESPACE}"></data>
71     Run_Keyword_If_At_Least_Neon    Check_Config_Data    <data xmlns\="${ODL_NETCONF_NAMESPACE}"/>
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     CompareStream.Run_Keyword_If_At_Most_Nitrogen
104     ...    NetconfKeywords.Remove_Device_From_Netconf
105     ...    ${DEVICE_NAME}
106     ...    location=${DELETE_LOCATION}
107     CompareStream.Run_Keyword_If_At_Least_Oxygen
108     ...    NetconfKeywords.Configure_Device_In_Netconf
109     ...    ${DEVICE_NAME}
110     ...    device_type=${DEVICE_TYPE_RPC_DELETE}
111     ...    http_timeout=2
112     ...    http_method=post
113
114 Check_Device_Going_To_Be_Gone_After_Deconfiguring
115     [Documentation]    Check that the device is really going to be gone. Fail
116     ...    if found after one minute. This is an expected behavior as the
117     ...    delete request is sent to the config subsystem which then triggers
118     ...    asynchronous destruction of the netconf connector referring to the
119     ...    device and the device's data. This test makes sure this
120     ...    asynchronous operation does not take unreasonable amount of time
121     ...    by making sure that both the netconf connector and the device's
122     ...    data is gone before reporting success.
123     [Tags]    critical
124     NetconfKeywords.Wait_Device_Fully_Removed    ${DEVICE_NAME}
125
126
127 *** Keywords ***
128 Setup_Everything
129     [Documentation]    Initialize SetupUtils. Setup everything needed for the test cases.
130     SetupUtils.Setup_Utils_For_Setup_And_Teardown
131     RequestsLibrary.Create_Session    operational    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}${REST_API}    auth=${AUTH}
132     NetconfKeywords.Setup_Netconf_Keywords
133     ${DEVICE_TYPE_RPC} =    BuiltIn.Set_Variable_If
134     ...    """${USE_NETCONF_CONNECTOR}""" == """True"""
135     ...    default
136     ...    ${DEVICE_TYPE_RPC}
137     ${DEVICE_TYPE} =    CompareStream.Set_Variable_If_At_Most_Nitrogen
138     ...    ${DEVICE_TYPE_RPC}
139     ...    ${DEVICE_TYPE_RPC_CREATE}
140     BuiltIn.Set_Suite_Variable    ${DEVICE_TYPE}
141     OperatingSystem.File Should Exist    ${RPC_FILE}
142     NetconfKeywords.Install_And_Start_Testtool
143     ...    device-count=1
144     ...    schemas=${CURDIR}/../../../variables/netconf/CRUD/schemas
145     ...    rpc_config=${RPC_FILE}
146     ...    mdsal=true
147
148 Teardown_Everything
149     [Documentation]    Teardown the test infrastructure, perform cleanup and release all resources.
150     RequestsLibrary.Delete_All_Sessions
151     BuiltIn.Run_Keyword_And_Ignore_Error    NetconfKeywords.Stop_Testtool
152
153 Get_Config_Data
154     [Documentation]    Get and return the config data from the device.
155     ${url} =    Builtin.Set_Variable
156     ...    ${REST_API}/network-topology:network-topology/topology=topology-netconf/node=${DEVICE_NAME}/yang-ext:mount?content=config
157     ${data} =    TemplatedRequests.Get_As_Xml_From_Uri    ${url}
158     RETURN    ${data}
159
160 Check_Config_Data
161     [Arguments]    ${expected}    ${contains}=False
162     ${data} =    Get_Config_Data
163     IF    not ${contains}
164         BuiltIn.Should_Be_Equal_As_Strings    ${data}    ${expected}
165     END
166     IF    ${contains}    BuiltIn.Should_Contain    ${data}    ${expected}