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