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