63ea61d26cc4fdfb07ef603970c76a38e1d2ad27
[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           OperatingSystem
32 Library           SSHLibrary    timeout=10s
33 Library           RequestsLibrary
34 Library           Collections
35 Variables         ${CURDIR}/../../../variables/Variables.py
36 Resource          ${CURDIR}/../../../libraries/FailFast.robot
37 Resource          ${CURDIR}/../../../libraries/KarafKeywords.robot
38 Resource          ${CURDIR}/../../../libraries/SetupUtils.robot
39 Resource          ${CURDIR}/../../../libraries/SSHKeywords.robot
40 Resource          ${CURDIR}/../../../libraries/Utils.robot
41 Resource          ${CURDIR}/../../../libraries/TemplatedRequests.robot
42 Resource          ${CURDIR}/../../../libraries/WaitForFailure.robot
43
44 *** Variables ***
45 ${TEMPLATE_FOLDER}    ${CURDIR}/templates
46 ${RESTCONF_SUBSCRIBE_URI}    restconf/operations/sal-remote:create-data-change-event-subscription
47 ${RESTCONF_SUBSCRIBE_DATA}    subscribe.xml
48 ${RESTCONF_GET_SUBSCRIPTION_URI}    restconf/streams/stream/data-change-event-subscription/opendaylight-inventory:nodes/datastore=CONFIGURATION/scope=BASE
49 ${RESTCONF_CONFIG_URI}    restconf/config
50 ${RESTCONF_CONFIG_DATA}    config_data.xml
51 ${RECEIVER_LOG_FILE}    wsreceiver.log
52 ${RECEIVER_OPTIONS}    ${EMPTY}
53 ${CONTROLLER_LOG_LEVEL}    INFO
54
55 *** Test Cases ***
56 Clean_Config
57     [Documentation]    Make sure config inventory is empty.
58     [Tags]    critical
59     BuiltIn.Log    ${CONFIG_NODES_API}
60     TemplatedRequests.Delete_From_Uri    uri=${CONFIG_NODES_API}    allow_404=True
61     # TODO: Rework also other test cases to use TemplatedRequests.
62
63 Create_Subscribtion
64     [Documentation]    Subscribe for notifications.
65     [Tags]    critical
66     ${body} =    OperatingSystem.Get_File    ${TEMPLATE_FOLDER}/${RESTCONF_SUBSCRIBE_DATA}
67     BuiltIn.Log    ${RESTCONF_SUBSCRIBE_URI}
68     BuiltIn.Log    ${body}
69     ${resp} =    RequestsLibrary.Post_Request    restconf    ${RESTCONF_SUBSCRIBE_URI}    headers=${SEND_ACCEPT_XML_HEADERS}    data=${body}
70     Log_Response    ${resp}
71     BuiltIn.Should_Be_Equal_As_Strings    ${resp.status_code}    200
72
73 Check_Subscribtion
74     [Documentation]    Get & check subscribtion ...
75     [Tags]    critical
76     ${resp} =    RequestsLibrary.Get_Request    restconf    ${RESTCONF_GET_SUBSCRIPTION_URI}    headers=${SEND_ACCEPT_XML_HEADERS}
77     Log_Response    ${resp}
78     BuiltIn.Should_Be_Equal_As_Strings    ${resp.status_code}    200    Response    status code error
79     ${location} =    Collections.Get_From_Dictionary    ${resp.headers}    location
80     BuiltIn.Log    ${location}
81     BuiltIn.Set_Suite_Variable    ${location}
82
83 Start_Receiver
84     [Documentation]    Start the websocket listener
85     ${output} =    SSHLibrary.Write    python wsreceiver.py --uri ${location} --count 2 --logfile ${RECEIVER_LOG_FILE} ${RECEIVER_OPTIONS}
86     BuiltIn.Log    ${output}
87     ${output} =    SSHLibrary.Read    delay=2s
88     BuiltIn.Log    ${output}
89
90 Change_Config
91     [Documentation]    Make a change in configuration.
92     [Tags]    critical
93     ${body} =    OperatingSystem.Get_File    ${TEMPLATE_FOLDER}/${RESTCONF_CONFIG_DATA}
94     BuiltIn.Log    ${RESTCONF_CONFIG_URI}
95     BuiltIn.Log    ${body}
96     ${resp} =    RequestsLibrary.Post_Request    restconf    ${RESTCONF_CONFIG_URI}    headers=${SEND_ACCEPT_XML_HEADERS}    data=${body}
97     Log_Response    ${resp}
98     BuiltIn.Should_Be_Equal_As_Strings    ${resp.status_code}    204
99     BuiltIn.Log    ${CONFIG_NODES_API}
100     ${resp} =    RequestsLibrary.Delete_Request    restconf    ${CONFIG_NODES_API}    headers=${SEND_ACCEPT_XML_HEADERS}
101     Log_Response    ${resp}
102     BuiltIn.Should_Be_Equal_As_Strings    ${resp.status_code}    200
103
104 Check_Create_Notification
105     [Documentation]    Check the websocket listener log for a change notification.
106     [Tags]    critical
107     ${notification} =    SSHLibrary.Execute_Command    cat ${RECEIVER_LOG_FILE}
108     BuiltIn.Log    ${notification}
109     BuiltIn.Set_Suite_Variable    ${notification}
110     BuiltIn.Should_Contain    ${notification}    <notification xmlns=
111     BuiltIn.Should_Contain    ${notification}    <eventTime>
112     BuiltIn.Should_Contain    ${notification}    <data-changed-notification xmlns=
113     BuiltIn.Should_Contain    ${notification}    <operation>created</operation>
114     BuiltIn.Should_Contain    ${notification}    </data-change-event>
115     BuiltIn.Should_Contain    ${notification}    </data-changed-notification>
116     BuiltIn.Should_Contain    ${notification}    </notification>
117
118 Check_Bug_3934
119     [Documentation]    Check the websocket listener log for the bug correction.
120     [Tags]    critical
121     ${data} =    OperatingSystem.Get_File    ${TEMPLATE_FOLDER}/${RESTCONF_CONFIG_DATA}
122     BuiltIn.Log    ${data}
123     BuiltIn.Log    ${notification}
124     ${packed_data} =    String.Remove_String    ${data}    ${SPACE}
125     ${packed_notification} =    String.Remove_String    ${notification}    ${SPACE}
126     BuiltIn.Should_Contain    ${packed_notification}    ${packed_data}
127     [Teardown]    Report_Failure_Due_To_Bug    3934
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 *** Keywords ***
135 Setup_Everything
136     [Documentation]    SSH-login to mininet machine, create HTTP session,
137     ...    prepare directories for responses, put Python tool to mininet machine, setup imported resources.
138     SetupUtils.Setup_Utils_For_Setup_And_Teardown
139     TemplatedRequests.Create_Default_Session
140     SSHLibrary.Set_Default_Configuration    prompt=${TOOLS_SYSTEM_PROMPT}
141     SSHLibrary.Open_Connection    ${TOOLS_SYSTEM_IP}    alias=receiver
142     Utils.Flexible_Mininet_Login
143     SSHLibrary.Put_File    ${CURDIR}/../../../../tools/wstools/wsreceiver.py
144     ${output_log}    ${error_log} =    SSHLibrary.Execute Command    sudo apt-get install -y python-pip    return_stdout=True    return_stderr=True
145     BuiltIn.Log    ${output_log}
146     BuiltIn.Log    ${error_log}
147     ${output_log} =    SSHLibrary.Execute_Command    sudo pip install websocket-client
148     BuiltIn.Log    ${output_log}
149     ${output_log} =    SSHLibrary.Execute_Command    python -c "help('modules')"
150     BuiltIn.Log    ${output_log}
151     Should Contain    ${output_log}    websocket
152     RequestsLibrary.Create Session    restconf    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}
153     BuiltIn.Log    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}
154     KarafKeywords.Execute_Controller_Karaf_Command_On_Background    log:set ${CONTROLLER_LOG_LEVEL}
155
156 Teardown_Everything
157     [Documentation]    Close connections.
158     ...    Tear down imported Resources.
159     RequestsLibrary.Delete_All_Sessions
160     SSHLibrary.Close_All_Connections
161
162 Log_Response
163     [Arguments]    ${resp}
164     [Documentation]    Log response.
165     BuiltIn.Log    ${resp}
166     BuiltIn.Log    ${resp.headers}
167     BuiltIn.Log    ${resp.content}