391dc6b585e6130af9010de268b413827c878066
[integration/test.git] / csit / suites / netconf / notifications / notifications_basic.robot
1 *** Settings ***
2 Documentation       Basic tests for BGP application peer.
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 ...                 Test suite performs basic subscribtion case for data store notifications.
11 ...                 For procedure description see the
12 ...                 https://wiki.opendaylight.org/view/OpenDaylight_Controller:MD-SAL:Restconf:Change_event_notification_subscription
13 ...
14 ...
15 ...                 This suite uses inventory (config part) as an area to make dummy writes into,
16 ...                 just to trigger data change listener to produce a notification.
17 ...                 Openflowplugin may have some data there, and before Boron, netconf-connector
18 ...                 was also exposing some data in inventory.
19 ...
20 ...                 To avoid unexpected responses, this suite depetes all data from config inventory,
21 ...                 so this suite should not be followed by any suite expecting default data there.
22 ...
23 ...                 Covered bugs:
24 ...                 Bug 3934 - Websockets: Scope ONE doesn't work correctly
25 ...
26 ...                 TODO: Use cars/people model for data
27
28 Library             Collections
29 Library             OperatingSystem
30 Library             RequestsLibrary
31 Library             SSHLibrary    timeout=10s
32 Library             XML
33 Resource            ${CURDIR}/../../../libraries/ClusterManagement.robot
34 Resource            ${CURDIR}/../../../libraries/FailFast.robot
35 Resource            ${CURDIR}/../../../libraries/KarafKeywords.robot
36 Resource            ${CURDIR}/../../../libraries/NetconfKeywords.robot
37 Resource            ${CURDIR}/../../../libraries/Restconf.robot
38 Resource            ${CURDIR}/../../../libraries/SetupUtils.robot
39 Resource            ${CURDIR}/../../../libraries/SSHKeywords.robot
40 Resource            ${CURDIR}/../../../libraries/TemplatedRequests.robot
41 Resource            ${CURDIR}/../../../libraries/WaitForFailure.robot
42 Resource            ${CURDIR}/../../../variables/Variables.robot
43
44 Suite Setup         Setup_Everything
45 Suite Teardown      Teardown_Everything
46 Test Setup          SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
47 Test Teardown       SetupUtils.Teardown_Test_Show_Bugs_And_Start_Fast_Failing_If_Test_Failed
48
49
50 *** Variables ***
51 ${TEMPLATE_FOLDER}              ${CURDIR}/templates
52 ${RFC8040_STREAMS_URI}          rests/data/ietf-restconf-monitoring:restconf-state/streams
53 ${NODES_STREAM_PATH}            network-topology:network-topology/datastore=CONFIGURATION/scope=BASE
54 ${RFC8040_DCN_STREAM_URI}       ${RFC8040_STREAMS_URI}/stream/data-change-event-subscription/${NODES_STREAM_PATH}
55 ${RESTCONF_SUBSCRIBE_DATA}      subscribe.xml
56 ${RESTCONF_CONFIG_DATA}         config_data.xml
57 ${RECEIVER_LOG_FILE}            receiver.log
58 ${CONTROLLER_LOG_LEVEL}         INFO
59
60
61 *** Test Cases ***
62 Create_DCN_Stream
63     [Documentation]    Create DCN stream.
64     [Tags]    critical
65     Comment    Create DCN subscription
66     ${body} =    OperatingSystem.Get_File    ${TEMPLATE_FOLDER}/${RESTCONF_SUBSCRIBE_DATA}
67     ${uri} =    Restconf.Generate URI    sal-remote:create-data-change-event-subscription    rpc
68     ${resp} =    RequestsLibrary.Post_On_Session
69     ...    restconf
70     ...    ${uri}
71     ...    headers=${SEND_ACCEPT_XML_HEADERS}
72     ...    data=${body}
73     Log_Response    ${resp}
74     BuiltIn.Should_Contain    ${ALLOWED_STATUS_CODES}    ${resp.status_code}
75
76 Subscribe_To_DCN_Stream
77     [Documentation]    Subscribe to DCN streams.
78     [Tags]    critical
79     ${resp} =    RequestsLibrary.Get_On_Session
80     ...    restconf
81     ...    url=${RFC8040_DCN_STREAM_URI}
82     ...    headers=${SEND_ACCEPT_XML_HEADERS}
83     Log_Response    ${resp}
84     BuiltIn.Should_Contain    ${ALLOWED_STATUS_CODES}    ${resp.status_code}
85     ${location} =    XML.Get_Element_Text    ${resp.content}
86     BuiltIn.Log    ${location}
87     BuiltIn.Log    ${resp.headers["Location"]}
88     Should Contain    ${location}    ${resp.headers["Location"]}
89     BuiltIn.Set_Suite_Variable    ${location}
90
91 List_DCN_Streams
92     [Documentation]    List DCN streams.
93     [Tags]    critical
94     ${resp} =    RequestsLibrary.Get_On_Session
95     ...    restconf
96     ...    url=${RFC8040_DCN_STREAM_URI}
97     ...    headers=${SEND_ACCEPT_XML_HEADERS}
98     Log_Response    ${resp}
99     BuiltIn.Should_Contain    ${ALLOWED_STATUS_CODES}    ${resp.status_code}
100     Comment    Stream only shows in RFC URL.
101     BuiltIn.Should_Contain    ${resp.text}    ${NODES_STREAM_PATH}
102
103 Start_Receiver
104     [Documentation]    Start the websocket listener
105     ${output} =    SSHLibrary.Write    python3 ssereceiver.py --uri ${location} --logfile ${RECEIVER_LOG_FILE}
106     BuiltIn.Log    ${output}
107     ${output} =    SSHLibrary.Read    delay=2s
108     BuiltIn.Log    ${output}
109
110 Change_DS_Config
111     [Documentation]    Make a change in DS configuration.
112     [Tags]    critical
113     ${body} =    OperatingSystem.Get_File    ${TEMPLATE_FOLDER}/${RESTCONF_CONFIG_DATA}
114     ${uri} =    BuiltIn.Set_Variable    /rests/data/network-topology:network-topology
115     ${resp} =    RequestsLibrary.Put_On_Session
116     ...    restconf
117     ...    ${uri}
118     ...    headers=${SEND_ACCEPT_XML_HEADERS}
119     ...    data=${body}
120     Log_Response    ${resp}
121     BuiltIn.Should_Contain    ${ALLOWED_STATUS_CODES}    ${resp.status_code}
122     ${uri} =    BuiltIn.Set_Variable    /rests/data/network-topology:network-topology/topology=netconf-notif
123     ${resp} =    RequestsLibrary.Delete_On_Session    restconf    ${uri}    headers=${SEND_ACCEPT_XML_HEADERS}
124     Log_Response    ${resp}
125     BuiltIn.Should_Contain    ${ALLOWED_STATUS_CODES}    ${resp.status_code}
126
127 Check_Notification
128     [Documentation]    Check the WSS/SSE listener log for a change notification.
129     [Tags]    critical
130     ${notification} =    SSHLibrary.Execute_Command    cat ${RECEIVER_LOG_FILE}
131     BuiltIn.Log    ${notification}
132     BuiltIn.Set_Suite_Variable    ${notification}
133     BuiltIn.Should_Contain    ${notification}    <notification xmlns=
134     BuiltIn.Should_Contain    ${notification}    <eventTime>
135     BuiltIn.Should_Contain    ${notification}    <data-changed-notification xmlns=
136     BuiltIn.Should_Contain    ${notification}    <operation>updated</operation>
137     BuiltIn.Should_Contain    ${notification}    </data-change-event>
138     BuiltIn.Should_Contain    ${notification}    </data-changed-notification>
139     BuiltIn.Should_Contain    ${notification}    </notification>
140
141 Check_Delete_Notification
142     [Documentation]    Check the websocket listener log for a delete notification.
143     [Tags]    critical
144     BuiltIn.Should_Contain    ${notification}    <operation>deleted</operation>
145
146 Check_Bug_3934
147     [Documentation]    Check the websocket listener log for the bug correction.
148     [Tags]    critical
149     ${data} =    OperatingSystem.Get_File    ${TEMPLATE_FOLDER}/${RESTCONF_CONFIG_DATA}
150     BuiltIn.Log    ${data}
151     BuiltIn.Log    ${notification}
152     ${packed_data} =    String.Remove_String    ${data}    \n
153     ${packed_data} =    String.Remove_String    ${packed_data}    ${SPACE}
154     ${packed_notification} =    String.Remove_String    ${notification}    \n
155     ${packed_notification} =    String.Remove_String    ${packed_notification}    \\n
156     ${packed_notification} =    String.Remove_String    ${packed_notification}    ${SPACE}
157     BuiltIn.Should_Contain    ${packed_notification}    ${packed_data}
158     [Teardown]    Report_Failure_Due_To_Bug    3934
159
160
161 *** Keywords ***
162 Setup_Everything
163     [Documentation]    SSH-login to mininet machine, create HTTP session,
164     ...    prepare directories for responses, put Python tool to mininet machine, setup imported resources.
165     SetupUtils.Setup_Utils_For_Setup_And_Teardown
166     KarafKeywords.Open_Controller_Karaf_Console_On_Background
167     SSHKeywords.Open_Connection_To_Tools_System
168     SSHLibrary.Put_File    ${CURDIR}/../../../../tools/wstools/wsreceiver.py
169     SSHLibrary.Put_File    ${CURDIR}/../../../../tools/wstools/ssereceiver.py
170     SSHLibrary.Execute_Command    sudo apt-get install -y python3-pip    return_stdout=True    return_stderr=True
171     SSHLibrary.Execute_Command
172     ...    sudo python3 -m pip install --upgrade pip setuptools wheel
173     ...    return_stdout=True
174     ...    return_stderr=True
175     SSHLibrary.Execute_Command
176     ...    sudo python3 -m pip install websocket-client asyncio aiohttp aiohttp-sse-client coroutine
177     ...    return_stdout=True
178     ...    return_stderr=True
179     RequestsLibrary.Create_Session    restconf    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}
180     KarafKeywords.Execute_Controller_Karaf_Command_On_Background    log:set ${CONTROLLER_LOG_LEVEL}
181
182 Teardown_Everything
183     [Documentation]    Close connections.
184     ...    Tear down imported Resources.
185     RequestsLibrary.Delete_All_Sessions
186     SSHLibrary.Close_All_Connections
187
188 Log_Response
189     [Documentation]    Log response.
190     [Arguments]    ${resp}
191     BuiltIn.Log    ${resp}
192     BuiltIn.Log    ${resp.headers}
193     BuiltIn.Log    ${resp.text}