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