Add RESTCONF RFC8040 SSE test
[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 ${DRAFT_STREAMS_URI}    restconf/streams
50 ${RFC8040_STREAMS_URI}    rests/data/ietf-restconf-monitoring:restconf-state/streams
51 ${NODES_STREAM_PATH}    opendaylight-inventory:nodes/datastore=CONFIGURATION/scope=BASE
52 ${DRAFT_DCN_STREAM_URI}    ${DRAFT_STREAMS_URI}/stream/data-change-event-subscription/${NODES_STREAM_PATH}
53 ${RFC8040_DCN_STREAM_URI}    ${RFC8040_STREAMS_URI}/stream/data-change-event-subscription/${NODES_STREAM_PATH}
54 ${RESTCONF_SUBSCRIBE_DATA}    subscribe.xml
55 ${RESTCONF_CONFIG_DATA}    config_data.xml
56 ${RECEIVER_LOG_FILE}    receiver.log
57 ${RECEIVER_OPTIONS}    ${EMPTY}
58 ${CONTROLLER_LOG_LEVEL}    INFO
59
60 *** Test Cases ***
61 Create_DCN_Stream
62     [Documentation]    Create DCN stream.
63     [Tags]    critical
64     Comment    Create DCN subscription
65     ${body} =    OperatingSystem.Get_File    ${TEMPLATE_FOLDER}/${RESTCONF_SUBSCRIBE_DATA}
66     ${uri} =    Restconf.Generate URI    sal-remote:create-data-change-event-subscription    rpc
67     ${resp} =    RequestsLibrary.Post_Request    restconf    ${uri}    headers=${SEND_ACCEPT_XML_HEADERS}    data=${body}
68     Log_Response    ${resp}
69     BuiltIn.Should_Contain    ${ALLOWED_STATUS_CODES}    ${resp.status_code}
70
71 Subscribe_To_DCN_Stream
72     [Documentation]    Subscribe to DCN streams.
73     [Tags]    critical
74     ${uri} =    Set Variable If    "${USE_RFC8040}" == "False"    ${DRAFT_DCN_STREAM_URI}    ${RFC8040_DCN_STREAM_URI}
75     ${resp} =    RequestsLibrary.Get_Request    restconf    ${uri}    headers=${SEND_ACCEPT_XML_HEADERS}
76     Log_Response    ${resp}
77     BuiltIn.Should_Contain    ${ALLOWED_STATUS_CODES}    ${resp.status_code}
78     ${location} =    XML.Get_Element_Text    ${resp.content}
79     BuiltIn.Log    ${location}
80     BuiltIn.Log    ${resp.headers["Location"]}
81     Should Contain    ${location}    ${resp.headers["Location"]}
82     BuiltIn.Set_Suite_Variable    ${location}
83
84 List_DCN_Streams
85     [Documentation]    List DCN streams.
86     [Tags]    critical
87     ${uri} =    BuiltIn.Set_Variable_If    "${USE_RFC8040}" == "False"    ${DRAFT_STREAMS_URI}    ${RFC8040_STREAMS_URI}
88     ${resp} =    RequestsLibrary.Get_Request    restconf    ${uri}    headers=${SEND_ACCEPT_XML_HEADERS}
89     Log_Response    ${resp}
90     BuiltIn.Should_Contain    ${ALLOWED_STATUS_CODES}    ${resp.status_code}
91     Comment    Stream only shows in RFC URL.
92     BuiltIn.Run_Keyword_If    "${USE_RFC8040}" == "True"    BuiltIn.Should_Contain    ${resp.text}    ${NODES_STREAM_PATH}
93
94 Start_Receiver
95     [Documentation]    Start the websocket listener
96     ${output} =    BuiltIn.Run_Keyword_If    "${USE_RFC8040}" == "False"    SSHLibrary.Write    python wsreceiver.py --uri ${location} --count 2 --logfile ${RECEIVER_LOG_FILE} ${RECEIVER_OPTIONS}
97     ...    ELSE    SSHLibrary.Write    python3 ssereceiver.py --controller ${ODL_SYSTEM_IP} --logfile ${RECEIVER_LOG_FILE}
98     BuiltIn.Log    ${output}
99     ${output} =    SSHLibrary.Read    delay=2s
100     BuiltIn.Log    ${output}
101
102 Change_DS_Config
103     [Documentation]    Make a change in DS configuration.
104     [Tags]    critical
105     ${body} =    OperatingSystem.Get_File    ${TEMPLATE_FOLDER}/${RESTCONF_CONFIG_DATA}
106     ${uri} =    BuiltIn.Set_Variable_If    "${USE_RFC8040}" == "False"    /restconf/config    /rests/data
107     ${resp} =    RequestsLibrary.Post_Request    restconf    ${uri}    headers=${SEND_ACCEPT_XML_HEADERS}    data=${body}
108     Log_Response    ${resp}
109     BuiltIn.Should_Contain    ${ALLOWED_STATUS_CODES}    ${resp.status_code}
110     ${uri} =    Restconf.Generate URI    opendaylight-inventory:nodes    config
111     ${resp} =    RequestsLibrary.Delete_Request    restconf    ${uri}    headers=${SEND_ACCEPT_XML_HEADERS}
112     Log_Response    ${resp}
113     BuiltIn.Should_Contain    ${ALLOWED_STATUS_CODES}    ${resp.status_code}
114
115 Check_Notification
116     [Documentation]    Check the WSS/SSE listener log for a change notification.
117     [Tags]    critical
118     ${notification} =    SSHLibrary.Execute_Command    cat ${RECEIVER_LOG_FILE}
119     BuiltIn.Log    ${notification}
120     BuiltIn.Set_Suite_Variable    ${notification}
121     BuiltIn.Should_Contain    ${notification}    <notification xmlns=
122     BuiltIn.Should_Contain    ${notification}    <eventTime>
123     BuiltIn.Should_Contain    ${notification}    <data-changed-notification xmlns=
124     BuiltIn.Should_Contain    ${notification}    <operation>created</operation>
125     BuiltIn.Should_Contain    ${notification}    </data-change-event>
126     BuiltIn.Should_Contain    ${notification}    </data-changed-notification>
127     BuiltIn.Should_Contain    ${notification}    </notification>
128
129 Check_Delete_Notification
130     [Documentation]    Check the websocket listener log for a delete notification.
131     [Tags]    critical
132     BuiltIn.Should_Contain    ${notification}    <operation>deleted</operation>
133
134 Check_Bug_3934
135     [Documentation]    Check the websocket listener log for the bug correction.
136     [Tags]    critical
137     ${data} =    OperatingSystem.Get_File    ${TEMPLATE_FOLDER}/${RESTCONF_CONFIG_DATA}
138     BuiltIn.Log    ${data}
139     BuiltIn.Log    ${notification}
140     ${packed_data} =    String.Remove_String    ${data}    \n
141     ${packed_data} =    String.Remove_String    ${packed_data}    ${SPACE}
142     ${packed_notification} =    String.Remove_String    ${notification}    \n
143     ${packed_notification} =    String.Remove_String    ${packed_notification}    \\n
144     ${packed_notification} =    String.Remove_String    ${packed_notification}    ${SPACE}
145     BuiltIn.Should_Contain    ${packed_notification}    ${packed_data}
146     [Teardown]    Report_Failure_Due_To_Bug    3934
147
148 *** Keywords ***
149 Setup_Everything
150     [Documentation]    SSH-login to mininet machine, create HTTP session,
151     ...    prepare directories for responses, put Python tool to mininet machine, setup imported resources.
152     SetupUtils.Setup_Utils_For_Setup_And_Teardown
153     KarafKeywords.Open_Controller_Karaf_Console_On_Background
154     SSHKeywords.Open_Connection_To_Tools_System
155     SSHLibrary.Put_File    ${CURDIR}/../../../../tools/wstools/wsreceiver.py
156     SSHLibrary.Put_File    ${CURDIR}/../../../../tools/wstools/ssereceiver.py
157     SSHLibrary.Execute Command    sudo apt-get install -y python-pip    return_stdout=True    return_stderr=True
158     SSHLibrary.Execute_Command    sudo pip install websocket-client    return_stdout=True    return_stderr=True
159     SSHLibrary.Execute Command    sudo python3 -m pip install asyncio aiohttp aiohttp-sse-client coroutine    return_stdout=True    return_stderr=True
160     RequestsLibrary.Create Session    restconf    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}
161     KarafKeywords.Execute_Controller_Karaf_Command_On_Background    log:set ${CONTROLLER_LOG_LEVEL}
162
163 Teardown_Everything
164     [Documentation]    Close connections.
165     ...    Tear down imported Resources.
166     RequestsLibrary.Delete_All_Sessions
167     SSHLibrary.Close_All_Connections
168
169 Log_Response
170     [Arguments]    ${resp}
171     [Documentation]    Log response.
172     BuiltIn.Log    ${resp}
173     BuiltIn.Log    ${resp.headers}
174     BuiltIn.Log    ${resp.text}