ad7bebc76c3a835a1fbc58b5ffee1fde245d3526
[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}    network-topology:network-topology/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 --uri ${location} --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/network-topology:network-topology
107     ...    /rests/data/network-topology:network-topology
108     ${resp} =    RequestsLibrary.Put_Request    restconf    ${uri}    headers=${SEND_ACCEPT_XML_HEADERS}    data=${body}
109     Log_Response    ${resp}
110     BuiltIn.Should_Contain    ${ALLOWED_STATUS_CODES}    ${resp.status_code}
111     ${uri} =    BuiltIn.Set_Variable_If    "${USE_RFC8040}" == "False"    /restconf/config/network-topology:network-topology/topology/netconf-notif
112     ...    /rests/data/network-topology:network-topology/topology=netconf-notif
113     ${resp} =    RequestsLibrary.Delete_Request    restconf    ${uri}    headers=${SEND_ACCEPT_XML_HEADERS}
114     Log_Response    ${resp}
115     BuiltIn.Should_Contain    ${ALLOWED_STATUS_CODES}    ${resp.status_code}
116
117 Check_Notification
118     [Documentation]    Check the WSS/SSE listener log for a change notification.
119     [Tags]    critical
120     ${notification} =    SSHLibrary.Execute_Command    cat ${RECEIVER_LOG_FILE}
121     BuiltIn.Log    ${notification}
122     BuiltIn.Set_Suite_Variable    ${notification}
123     BuiltIn.Should_Contain    ${notification}    <notification xmlns=
124     BuiltIn.Should_Contain    ${notification}    <eventTime>
125     BuiltIn.Should_Contain    ${notification}    <data-changed-notification xmlns=
126     BuiltIn.Should_Contain    ${notification}    <operation>updated</operation>
127     BuiltIn.Should_Contain    ${notification}    </data-change-event>
128     BuiltIn.Should_Contain    ${notification}    </data-changed-notification>
129     BuiltIn.Should_Contain    ${notification}    </notification>
130
131 Check_Delete_Notification
132     [Documentation]    Check the websocket listener log for a delete notification.
133     [Tags]    critical
134     BuiltIn.Should_Contain    ${notification}    <operation>deleted</operation>
135
136 Check_Bug_3934
137     [Documentation]    Check the websocket listener log for the bug correction.
138     [Tags]    critical
139     ${data} =    OperatingSystem.Get_File    ${TEMPLATE_FOLDER}/${RESTCONF_CONFIG_DATA}
140     BuiltIn.Log    ${data}
141     BuiltIn.Log    ${notification}
142     ${packed_data} =    String.Remove_String    ${data}    \n
143     ${packed_data} =    String.Remove_String    ${packed_data}    ${SPACE}
144     ${packed_notification} =    String.Remove_String    ${notification}    \n
145     ${packed_notification} =    String.Remove_String    ${packed_notification}    \\n
146     ${packed_notification} =    String.Remove_String    ${packed_notification}    ${SPACE}
147     BuiltIn.Should_Contain    ${packed_notification}    ${packed_data}
148     [Teardown]    Report_Failure_Due_To_Bug    3934
149
150 *** Keywords ***
151 Setup_Everything
152     [Documentation]    SSH-login to mininet machine, create HTTP session,
153     ...    prepare directories for responses, put Python tool to mininet machine, setup imported resources.
154     SetupUtils.Setup_Utils_For_Setup_And_Teardown
155     KarafKeywords.Open_Controller_Karaf_Console_On_Background
156     SSHKeywords.Open_Connection_To_Tools_System
157     SSHLibrary.Put_File    ${CURDIR}/../../../../tools/wstools/wsreceiver.py
158     SSHLibrary.Put_File    ${CURDIR}/../../../../tools/wstools/ssereceiver.py
159     SSHLibrary.Execute Command    sudo apt-get install -y python-pip    return_stdout=True    return_stderr=True
160     SSHLibrary.Execute_Command    sudo pip install websocket-client    return_stdout=True    return_stderr=True
161     SSHLibrary.Execute Command    sudo python3 -m pip install asyncio aiohttp aiohttp-sse-client coroutine    return_stdout=True    return_stderr=True
162     RequestsLibrary.Create Session    restconf    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}
163     KarafKeywords.Execute_Controller_Karaf_Command_On_Background    log:set ${CONTROLLER_LOG_LEVEL}
164
165 Teardown_Everything
166     [Documentation]    Close connections.
167     ...    Tear down imported Resources.
168     RequestsLibrary.Delete_All_Sessions
169     SSHLibrary.Close_All_Connections
170
171 Log_Response
172     [Arguments]    ${resp}
173     [Documentation]    Log response.
174     BuiltIn.Log    ${resp}
175     BuiltIn.Log    ${resp.headers}
176     BuiltIn.Log    ${resp.text}