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