07fd8cd274e1a7603c5b4ba34f063b9ed743bc22
[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    restconf    url=${RFC8040_DCN_STREAM_URI}    headers=${SEND_ACCEPT_XML_HEADERS}
80     Log_Response    ${resp}
81     BuiltIn.Should_Contain    ${ALLOWED_STATUS_CODES}    ${resp.status_code}
82     ${location} =    XML.Get_Element_Text    ${resp.content}
83     BuiltIn.Log    ${location}
84     BuiltIn.Log    ${resp.headers["Location"]}
85     Should Contain    ${location}    ${resp.headers["Location"]}
86     BuiltIn.Set_Suite_Variable    ${location}
87
88 List_DCN_Streams
89     [Documentation]    List DCN streams.
90     [Tags]    critical
91     ${resp} =    RequestsLibrary.Get_On_Session    restconf    url=${RFC8040_DCN_STREAM_URI}    headers=${SEND_ACCEPT_XML_HEADERS}
92     Log_Response    ${resp}
93     BuiltIn.Should_Contain    ${ALLOWED_STATUS_CODES}    ${resp.status_code}
94     Comment    Stream only shows in RFC URL.
95     BuiltIn.Should_Contain    ${resp.text}    ${NODES_STREAM_PATH}
96
97 Start_Receiver
98     [Documentation]    Start the websocket listener
99     ${output} =    SSHLibrary.Write    python3 ssereceiver.py --uri ${location} --logfile ${RECEIVER_LOG_FILE}
100     BuiltIn.Log    ${output}
101     ${output} =    SSHLibrary.Read    delay=2s
102     BuiltIn.Log    ${output}
103
104 Change_DS_Config
105     [Documentation]    Make a change in DS configuration.
106     [Tags]    critical
107     ${body} =    OperatingSystem.Get_File    ${TEMPLATE_FOLDER}/${RESTCONF_CONFIG_DATA}
108     ${uri} =    BuiltIn.Set_Variable    /rests/data/network-topology:network-topology
109     ${resp} =    RequestsLibrary.Put_On_Session
110     ...    restconf
111     ...    ${uri}
112     ...    headers=${SEND_ACCEPT_XML_HEADERS}
113     ...    data=${body}
114     Log_Response    ${resp}
115     BuiltIn.Should_Contain    ${ALLOWED_STATUS_CODES}    ${resp.status_code}
116     ${uri} =    BuiltIn.Set_Variable    /rests/data/network-topology:network-topology/topology=netconf-notif
117     ${resp} =    RequestsLibrary.Delete_On_Session    restconf    ${uri}    headers=${SEND_ACCEPT_XML_HEADERS}
118     Log_Response    ${resp}
119     BuiltIn.Should_Contain    ${ALLOWED_STATUS_CODES}    ${resp.status_code}
120
121 Check_Notification
122     [Documentation]    Check the WSS/SSE listener log for a change notification.
123     [Tags]    critical
124     ${notification} =    SSHLibrary.Execute_Command    cat ${RECEIVER_LOG_FILE}
125     BuiltIn.Log    ${notification}
126     BuiltIn.Set_Suite_Variable    ${notification}
127     BuiltIn.Should_Contain    ${notification}    <notification xmlns=
128     BuiltIn.Should_Contain    ${notification}    <eventTime>
129     BuiltIn.Should_Contain    ${notification}    <data-changed-notification xmlns=
130     BuiltIn.Should_Contain    ${notification}    <operation>updated</operation>
131     BuiltIn.Should_Contain    ${notification}    </data-change-event>
132     BuiltIn.Should_Contain    ${notification}    </data-changed-notification>
133     BuiltIn.Should_Contain    ${notification}    </notification>
134
135 Check_Delete_Notification
136     [Documentation]    Check the websocket listener log for a delete notification.
137     [Tags]    critical
138     BuiltIn.Should_Contain    ${notification}    <operation>deleted</operation>
139
140 Check_Bug_3934
141     [Documentation]    Check the websocket listener log for the bug correction.
142     [Tags]    critical
143     ${data} =    OperatingSystem.Get_File    ${TEMPLATE_FOLDER}/${RESTCONF_CONFIG_DATA}
144     BuiltIn.Log    ${data}
145     BuiltIn.Log    ${notification}
146     ${packed_data} =    String.Remove_String    ${data}    \n
147     ${packed_data} =    String.Remove_String    ${packed_data}    ${SPACE}
148     ${packed_notification} =    String.Remove_String    ${notification}    \n
149     ${packed_notification} =    String.Remove_String    ${packed_notification}    \\n
150     ${packed_notification} =    String.Remove_String    ${packed_notification}    ${SPACE}
151     BuiltIn.Should_Contain    ${packed_notification}    ${packed_data}
152     [Teardown]    Report_Failure_Due_To_Bug    3934
153
154
155 *** Keywords ***
156 Setup_Everything
157     [Documentation]    SSH-login to mininet machine, create HTTP session,
158     ...    prepare directories for responses, put Python tool to mininet machine, setup imported resources.
159     SetupUtils.Setup_Utils_For_Setup_And_Teardown
160     KarafKeywords.Open_Controller_Karaf_Console_On_Background
161     SSHKeywords.Open_Connection_To_Tools_System
162     SSHLibrary.Put_File    ${CURDIR}/../../../../tools/wstools/wsreceiver.py
163     SSHLibrary.Put_File    ${CURDIR}/../../../../tools/wstools/ssereceiver.py
164     SSHLibrary.Execute_Command    sudo apt-get install -y python3-pip    return_stdout=True    return_stderr=True
165     SSHLibrary.Execute_Command
166     ...    sudo python3 -m pip install --upgrade pip setuptools wheel
167     ...    return_stdout=True
168     ...    return_stderr=True
169     SSHLibrary.Execute_Command
170     ...    sudo python3 -m pip install websocket-client asyncio aiohttp aiohttp-sse-client coroutine
171     ...    return_stdout=True
172     ...    return_stderr=True
173     RequestsLibrary.Create_Session    restconf    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}
174     KarafKeywords.Execute_Controller_Karaf_Command_On_Background    log:set ${CONTROLLER_LOG_LEVEL}
175
176 Teardown_Everything
177     [Documentation]    Close connections.
178     ...    Tear down imported Resources.
179     RequestsLibrary.Delete_All_Sessions
180     SSHLibrary.Close_All_Connections
181
182 Log_Response
183     [Documentation]    Log response.
184     [Arguments]    ${resp}
185     BuiltIn.Log    ${resp}
186     BuiltIn.Log    ${resp.headers}
187     BuiltIn.Log    ${resp.text}