Disable SSE notifications
[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 Suite Setup       Setup_Everything
28 Suite Teardown    Teardown_Everything
29 Test Setup        SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
30 Test Teardown     SetupUtils.Teardown_Test_Show_Bugs_And_Start_Fast_Failing_If_Test_Failed
31 Library           Collections
32 Library           OperatingSystem
33 Library           RequestsLibrary
34 Library           SSHLibrary    timeout=10s
35 Library           XML
36 Resource          ${CURDIR}/../../../libraries/ClusterManagement.robot
37 Resource          ${CURDIR}/../../../libraries/FailFast.robot
38 Resource          ${CURDIR}/../../../libraries/KarafKeywords.robot
39 Resource          ${CURDIR}/../../../libraries/NetconfKeywords.robot
40 Resource          ${CURDIR}/../../../libraries/Restconf.robot
41 Resource          ${CURDIR}/../../../libraries/SetupUtils.robot
42 Resource          ${CURDIR}/../../../libraries/SSHKeywords.robot
43 Resource          ${CURDIR}/../../../libraries/TemplatedRequests.robot
44 Resource          ${CURDIR}/../../../libraries/WaitForFailure.robot
45 Resource          ${CURDIR}/../../../variables/Variables.robot
46
47 *** Variables ***
48 ${TEMPLATE_FOLDER}    ${CURDIR}/templates
49 ${RESTCONF_SUBSCRIBE_URI}    restconf/operations/sal-remote:create-data-change-event-subscription
50 ${RESTCONF_SUBSCRIBE_DATA}    subscribe.xml
51 ${NODES_STREAM_PATH}    opendaylight-inventory:nodes/datastore=CONFIGURATION/scope=BASE
52 ${RESTCONF_GET_SUBSCRIPTION_URI}    restconf/streams/stream/data-change-event-subscription/${NODES_STREAM_PATH}
53 ${RFC8040_NOTIFICATIONS_STREAMS_URI}    rests/data/ietf-restconf-monitoring:restconf-state/streams
54 ${RFC8040_GET_SUBSCRIPTION_URI}    ${RFC8040_NOTIFICATIONS_STREAMS_URI}/stream/data-change-event-subscription/${NODES_STREAM_PATH}
55 ${RESTCONF_CONFIG_DATA}    config_data.xml
56 ${RECEIVER_LOG_FILE}    wsreceiver.log
57 ${RECEIVER_OPTIONS}    ${EMPTY}
58 ${CONTROLLER_LOG_LEVEL}    INFO
59
60 *** Test Cases ***
61 Clean_Config
62     [Documentation]    Make sure config inventory is empty.
63     [Tags]    critical
64     ${uri} =    Restconf.Generate URI    opendaylight-inventory:nodes    config
65     TemplatedRequests.Delete_From_Uri    uri=${uri}    additional_allowed_status_codes=${DELETED_STATUS_CODES}
66     # TODO: Rework also other test cases to use TemplatedRequests.
67
68 Create_Subscription
69     [Documentation]    Subscribe for notifications.
70     [Tags]    critical
71     # check get streams url passes prior to creating a subscription
72     ${resp} =    RequestsLibrary.Get_Request    restconf    ${RFC8040_NOTIFICATIONS_STREAMS_URI}    headers=${SEND_ACCEPT_XML_HEADERS}
73     Log_Response    ${resp}
74     BuiltIn.Should_Contain    ${ALLOWED_STATUS_CODES}    ${resp.status_code}
75     ${body} =    OperatingSystem.Get_File    ${TEMPLATE_FOLDER}/${RESTCONF_SUBSCRIBE_DATA}
76     BuiltIn.Log    ${RESTCONF_SUBSCRIBE_URI}
77     BuiltIn.Log    ${body}
78     ${uri} =    Restconf.Generate URI    sal-remote:create-data-change-event-subscription    rpc
79     ${resp} =    RequestsLibrary.Post_Request    restconf    ${uri}    headers=${SEND_ACCEPT_XML_HEADERS}    data=${body}
80     Log_Response    ${resp}
81     BuiltIn.Should_Contain    ${ALLOWED_STATUS_CODES}    ${resp.status_code}
82
83 Check_Notification_Stream
84     [Documentation]    Check any notification stream via RESTCONF is accessible
85     [Tags]    critical
86     ${resp} =    RequestsLibrary.Get_Request    restconf    ${RFC8040_NOTIFICATIONS_STREAMS_URI}    headers=${SEND_ACCEPT_XML_HEADERS}
87     Log_Response    ${resp}
88     BuiltIn.Should_Contain    ${ALLOWED_STATUS_CODES}    ${resp.status_code}
89     ${root}=    XML.Parse XML    ${resp.content}
90     ${name}=    Get Elements Texts    ${root}    stream/name
91     BuiltIn.Log    ${name[0]}
92     ${resp} =    RequestsLibrary.Get_Request    restconf    ${RFC8040_NOTIFICATIONS_STREAMS_URI}/stream=${name[0]}/access=JSON/location    headers=${SEND_ACCEPT_XML_HEADERS}
93     Log_Response    ${resp}
94     BuiltIn.Should_Contain    ${ALLOWED_STATUS_CODES}    ${resp.status_code}
95
96 Check_Subscription
97     [Documentation]    Get & check subscription ...
98     [Tags]    critical
99     ${uri} =    Set Variable If    "${USE_RFC8040}" == "False"    ${RESTCONF_GET_SUBSCRIPTION_URI}    ${RFC8040_GET_SUBSCRIPTION_URI}
100     ${resp} =    RequestsLibrary.Get_Request    restconf    ${uri}    headers=${SEND_ACCEPT_XML_HEADERS}
101     Log_Response    ${resp}
102     BuiltIn.Should_Contain    ${ALLOWED_STATUS_CODES}    ${resp.status_code}
103     ${location} =    XML.Get Element Text    ${resp.content}
104     BuiltIn.Log    ${location}
105     BuiltIn.Log    ${resp.headers["Location"]}
106     Should Contain    ${location}    ${resp.headers["Location"]}
107     BuiltIn.Set_Suite_Variable    ${location}
108
109 Start_Receiver
110     [Documentation]    Start the websocket listener
111     ${output} =    SSHLibrary.Write    python wsreceiver.py --uri ${location} --count 2 --logfile ${RECEIVER_LOG_FILE} ${RECEIVER_OPTIONS}
112     BuiltIn.Log    ${output}
113     ${output} =    SSHLibrary.Read    delay=2s
114     BuiltIn.Log    ${output}
115
116 Change_Config
117     [Documentation]    Make a change in configuration.
118     [Tags]    critical
119     ${body} =    OperatingSystem.Get_File    ${TEMPLATE_FOLDER}/${RESTCONF_CONFIG_DATA}
120     ${uri} =    Set Variable If    "${USE_RFC8040}" == "False"    ${CONFIG_API}    rests/data
121     BuiltIn.Log    ${body}
122     ${resp} =    RequestsLibrary.Post_Request    restconf    ${uri}    headers=${SEND_ACCEPT_XML_HEADERS}    data=${body}
123     Log_Response    ${resp}
124     BuiltIn.Should_Contain    ${ALLOWED_STATUS_CODES}    ${resp.status_code}
125     ${uri} =    Restconf.Generate URI    opendaylight-inventory:nodes    config
126     ${resp} =    RequestsLibrary.Delete_Request    restconf    ${uri}    headers=${SEND_ACCEPT_XML_HEADERS}
127     Log_Response    ${resp}
128     BuiltIn.Should_Contain    ${ALLOWED_STATUS_CODES}    ${resp.status_code}
129
130 Check_Create_Notification
131     [Documentation]    Check the websocket listener log for a change notification.
132     [Tags]    critical
133     ${notification} =    SSHLibrary.Execute_Command    cat ${RECEIVER_LOG_FILE}
134     BuiltIn.Log    ${notification}
135     BuiltIn.Set_Suite_Variable    ${notification}
136     BuiltIn.Should_Contain    ${notification}    <notification xmlns=
137     BuiltIn.Should_Contain    ${notification}    <eventTime>
138     BuiltIn.Should_Contain    ${notification}    <data-changed-notification xmlns=
139     BuiltIn.Should_Contain    ${notification}    <operation>created</operation>
140     BuiltIn.Should_Contain    ${notification}    </data-change-event>
141     BuiltIn.Should_Contain    ${notification}    </data-changed-notification>
142     BuiltIn.Should_Contain    ${notification}    </notification>
143
144 Check_Bug_3934
145     [Documentation]    Check the websocket listener log for the bug correction.
146     [Tags]    critical
147     ${data} =    OperatingSystem.Get_File    ${TEMPLATE_FOLDER}/${RESTCONF_CONFIG_DATA}
148     BuiltIn.Log    ${data}
149     BuiltIn.Log    ${notification}
150     ${packed_data} =    String.Remove_String    ${data}    ${SPACE}
151     ${packed_notification} =    String.Remove_String    ${notification}    ${SPACE}
152     BuiltIn.Should_Contain    ${packed_notification}    ${packed_data}
153     [Teardown]    Report_Failure_Due_To_Bug    3934
154
155 Check_Delete_Notification
156     [Documentation]    Check the websocket listener log for a delete notification.
157     [Tags]    critical
158     BuiltIn.Should_Contain    ${notification}    <operation>deleted</operation>
159
160 *** Keywords ***
161 Setup_Everything
162     [Documentation]    SSH-login to mininet machine, create HTTP session,
163     ...    prepare directories for responses, put Python tool to mininet machine, setup imported resources.
164     SetupUtils.Setup_Utils_For_Setup_And_Teardown
165     Disable SSE On Controller    ${CONTROLLER}
166     ClusterManagement.Stop_Members_From_List_Or_All
167     ClusterManagement.Start_Members_From_List_Or_All
168     KarafKeywords.Open_Controller_Karaf_Console_On_Background
169     TemplatedRequests.Create_Default_Session
170     SSHLibrary.Set_Default_Configuration    prompt=${TOOLS_SYSTEM_PROMPT}
171     SSHLibrary.Open_Connection    ${TOOLS_SYSTEM_IP}    alias=receiver
172     SSHKeywords.Flexible_Mininet_Login
173     SSHLibrary.Put_File    ${CURDIR}/../../../../tools/wstools/wsreceiver.py
174     ${output_log}    ${error_log} =    SSHLibrary.Execute Command    sudo apt-get install -y python-pip    return_stdout=True    return_stderr=True
175     BuiltIn.Log    ${output_log}
176     BuiltIn.Log    ${error_log}
177     ${output_log} =    SSHLibrary.Execute_Command    sudo pip install websocket-client
178     BuiltIn.Log    ${output_log}
179     ${output_log} =    SSHLibrary.Execute_Command    python -c "help('modules')"
180     BuiltIn.Log    ${output_log}
181     Should Contain    ${output_log}    websocket
182     RequestsLibrary.Create Session    restconf    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}
183     BuiltIn.Log    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}
184     KarafKeywords.Execute_Controller_Karaf_Command_On_Background    log:set ${CONTROLLER_LOG_LEVEL}
185
186 Teardown_Everything
187     [Documentation]    Close connections.
188     ...    Tear down imported Resources.
189     RequestsLibrary.Delete_All_Sessions
190     SSHLibrary.Close_All_Connections
191
192 Log_Response
193     [Arguments]    ${resp}
194     [Documentation]    Log response.
195     BuiltIn.Log    ${resp}
196     BuiltIn.Log    ${resp.headers}
197     BuiltIn.Log    ${resp.content}