Replace 'Run Keyword Unless'
[integration/test.git] / csit / suites / netconf / ready / netconfready.robot
1 *** Settings ***
2 Documentation     netconf-connector readiness test suite.
3 ...
4 ...               Copyright (c) 2015,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 ...
11 ...               Try to detect whether Netconf is up and running and wait for
12 ...               it for a configurable time if it is not yet up and running.
13 ...
14 ...               This is achieved by the test Check_Whether_Netconf_Topology_Is_Ready. This test case
15 ...               does not use controller-config device. This test case is skipped (Pass Execution) if
16 ...               the usage of controller-config device is indicated.
17 ...               Testing itself is done by creating a netconf test device configured
18 ...               to all odl nodes one by one and check if GET works from mounted
19 ...               device. GET is done from all the odl nodes and it works for both, 1 or 3 nodes
20 ...               setup.
21 ...
22 ...               The next test cases are basically dedicated to test readiness of the netconf using
23 ...               controller-config device. This device is created when odl-netconf-connector-ssh|all
24 ...               feature is installed. Robot variable USE_NETCONF_CONNECTOR should be set to True.
25 ...               Connector test cases change behavior depending on ${USE_NETCONF_CONNECTOR}. If True,
26 ...               they check data mounted behind controller-config is readable, if False they only check
27 ...               topology-netconf is readable.
28 ...
29 ...               Some testsuites expect netconf-connector to be ready as soon as possible and will
30 ...               fail if it is not. We want to see a failure if this is the cause of the failure.
31 ...
32 ...
33 ...               The usage of netconf-connector happens in other suites than netconf,
34 ...               especially bgpcep to configure odl's bgp peers. Testing the readiness
35 ...               of the netconf-connector must be invoked by the Robot invocation
36 ...               argument USE_NETCONF_CONNECTOR. By default it is set to False and
37 ...               test jobs should be responsible to set it to True if needed. In the
38 ...               default configuration the affected test cases waits for the netconf
39 ...               topology to appear only.
40 ...
41 ...               If the netconf-connector is not ready upon startup and it's usage is set
42 ...               to True (as seen by the second test case failing), the next case starts
43 ...               to repeat the query for a minute to see whether it is going "to fix itself"
44 ...               within the minute. If yes, then the testcase will pass, which
45 ...               indicates that the "ODL cooldown" of 1 minute is not long enough
46 ...               to allow for netconf-connector to initialize properly.
47 ...               If this fails, one more check with even longer timeout is run.
48 ...               If the Check_Whether_Netconf_Is_Up_And_Running pass, then the next test
49 ...               case does nothing.
50 ...
51 ...               The other test case then checks whether Netconf can pretty print
52 ...               data. This sometimes makes problems, most likely due to too
53 ...               new Robot Requests library with an interface incompatible with
54 ...               this test suite.
55 Suite Setup       Setup_Everything
56 Suite Teardown    Teardown_Everything
57 Test Setup        SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
58 Test Teardown     SetupUtils.Teardown_Test_Show_Bugs_If_Test_Failed
59 Resource          ${CURDIR}/../../../libraries/ClusterManagement.robot
60 Resource          ${CURDIR}/../../../libraries/CompareStream.robot
61 Resource          ${CURDIR}/../../../libraries/KarafKeywords.robot
62 Library           RequestsLibrary
63 Resource          ${CURDIR}/../../../libraries/NetconfKeywords.robot
64 Resource          ${CURDIR}/../../../libraries/SetupUtils.robot
65 Resource          ${CURDIR}/../../../libraries/SSHKeywords.robot
66 Variables         ${CURDIR}/../../../variables/Variables.py
67
68 *** Variables ***
69 ${netconf_is_ready}    False
70 ${NETCONFREADY_WAIT}    60s
71 ${NETCONFREADY_FALLBACK_WAIT}    1200s
72 ${USE_NETCONF_CONNECTOR}    False
73 ${DEBUG_LOGGING_FOR_EVERYTHING}    False
74 ${NETCONFREADY_WAIT_MDSAL}    60s
75 ${DEVICE_NAME}    test-device
76 ${DEVICE_PORT}    2830
77 ${NETCONF_FOLDER}    ${CURDIR}/../../../variables/netconf/device
78
79 *** Test Cases ***
80 Check_Whether_Netconf_Topology_Is_Ready
81     [Tags]    ODLMICRO_IGN
82     [Documentation]    Checks netconf readiness.
83     BuiltIn.Pass_Execution_If    ${USE_NETCONF_CONNECTOR}==${True}    Netconf connector is used. Next testcases do their job in this case.
84     BuiltIn.Wait_Until_Keyword_Succeeds    10x    1s    Check_Netconf_Topology_Ready
85
86 Check_Whether_Netconf_Connector_Is_Up_And_Running
87     [Documentation]    Make one request to Netconf topology to see whether Netconf is up and running.
88     [Tags]    exclude
89     Check_Netconf_Up_And_Running
90     BuiltIn.Set_Suite_Variable    ${netconf_is_ready}    True
91
92 Wait_For_Netconf_Connector
93     [Documentation]    Wait for the Netconf to go up for configurable time.
94     [Tags]    critical
95     BuiltIn.Run_Keyword_If    not ${netconf_is_ready}    BuiltIn.Wait_Until_Keyword_Succeeds    ${NETCONFREADY_WAIT}    1s    Check_Netconf_Up_And_Running
96     BuiltIn.Set_Suite_Variable    ${netconf_is_ready}    True
97
98 Wait_Even_Longer
99     [Documentation]    Bugs such as 7175 may require to wait longer till netconf-connector works.
100     [Tags]    critical
101     BuiltIn.Pass_Execution_If    ${netconf_is_ready}    Netconf was detected to be up and running so bug 5014 did not show up.
102     BuiltIn.Wait_Until_Keyword_Succeeds    ${NETCONFREADY_FALLBACK_WAIT}    10s    Check_Netconf_Up_And_Running
103     BuiltIn.Set_Suite_Variable    ${netconf_is_ready}    True
104
105 Check_For_Bug_5014
106     [Documentation]    If Netconf appears to be down, it may be due to bug 5014. Check if it is so and fail if yes.
107     ...    Bug 5014 is about Netconf playing dead on boot until a device
108     ...    configuration request is sent to it. To uncover this attempt to
109     ...    configure and then deconfigure a device and then check if Netconf
110     ...    is now up and running. If that turns out to be true, fail the case
111     ...    as this signifies the bug 5014 to be present. Skip this testcase
112     ...    if Netconf is detected to be up and running.
113     [Tags]    critical
114     BuiltIn.Pass_Execution_If    ${netconf_is_ready}    Netconf was detected to be up and running so bug 5014 did not show up.
115     ${status}    ${error}=    BuiltIn.Run_Keyword_And_Ignore_Error    Check_Netconf_Usable
116     BuiltIn.Run_Keyword_If    '${status}'=='PASS'    BuiltIn.Set_Suite_Variable    ${netconf_is_ready}    True
117     BuiltIn.Should_Be_Equal    '${status}'    'FAIL'
118
119 Check_Whether_Netconf_Can_Pretty_Print
120     [Documentation]    Make one request to netconf-connector and see if it works.
121     [Tags]    critical
122     BuiltIn.Run_Keyword_If    not ${netconf_is_ready}    Fail    Netconf is not ready so it can't pretty-print now.
123     Check_Netconf_Up_And_Running    ?odl-pretty-print=true
124
125 Wait_For_MDSAL
126     [Tags]    ODLMICRO_IGN
127     [Documentation]    Wait for the MDSAL feature to become online
128     ${status}    ${message}=    BuiltIn.Run_Keyword_And_Ignore_Error    KarafKeywords.Verify_Feature_Is_Installed    odl-netconf-mdsal
129     BuiltIn.Run_Keyword_If    '${status}' == 'FAIL'    BuiltIn.Pass_Execution    The 'odl-netconf-mdsal' feature is not installed so no need to wait for it.
130     SSHKeywords.Open_Connection_To_ODL_System
131     BuiltIn.Wait_Until_Keyword_Succeeds    ${NETCONFREADY_WAIT_MDSAL}    1s    Check_Netconf_MDSAL_Up_And_Running
132     SSHLibrary.Close_Connection
133
134 *** Keywords ***
135 Setup_Everything
136     [Documentation]    Initialize SetupUtils. Setup requests library and log into karaf.log that the netconf readiness wait starts.
137     SetupUtils.Setup_Utils_For_Setup_And_Teardown
138     ${connector}=    Set_Netconf_Connector
139     BuiltIn.Set_Suite_Variable    ${netconf_connector}    ${connector}
140     BuiltIn.Comment    A workaround for EOF error follows. TODO: Create a test case for the EOF bug, possibly tagged "exclude".
141     BuiltIn.Wait_Until_Keyword_Succeeds    2x    1s    KarafKeywords.Open_Controller_Karaf_Console_On_Background
142     KarafKeywords.Log_Message_To_Controller_Karaf    Starting Netconf readiness test suite
143     BuiltIn.Run_Keyword_If    ${DEBUG_LOGGING_FOR_EVERYTHING}    KarafKeywords.Execute_Controller_Karaf_Command_On_Background    log:set DEBUG
144     RequestsLibrary.Create_Session    ses    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}
145     NetconfKeywords.Setup_Netconf_Keywords
146
147 Teardown_Everything
148     [Documentation]    Destroy all sessions in the requests library and log into karaf.log that the netconf readiness wait is over.
149     KarafKeywords.Log_Message_To_Controller_Karaf    Ending Netconf readiness test suite
150     RequestsLibrary.Delete_All_Sessions
151
152 Set_Netconf_Connector
153     [Documentation]    Sets netconf connector verify url according to the ${ODL_STREAM} and ${USE_NETCONF_CONNECTOR} combination
154     ${streamconnector}=    Set Variable    /node/controller-config/yang-ext:mount/config:modules/module/sal-restconf-service:json-restconf-service-impl/json-restconf-service-impl
155     ${connector}=    BuiltIn.Set_Variable_If    ${USE_NETCONF_CONNECTOR}    ${streamconnector}    ${EMPTY}
156     BuiltIn.Return_From_Keyword    ${connector}
157
158 Check_Netconf_Topology_Ready
159     [Documentation]    Verifies the netconf readiness for every odl node.
160     FOR    ${idx}    IN    @{ClusterManagement__member_index_list}
161         Verify_Netconf_Topology_Ready_For_Node    ${idx}
162     END
163
164 Verify_Netconf_Topology_Ready_For_Node
165     [Arguments]    ${node_index}
166     [Documentation]    Netconf readines for a node is done by creating a netconf device connected to that node
167     ...    and performing GET operation got from the device's mount point.
168     ${session} =    ClusterManagement.Resolve_Http_Session_For_Member    member_index=${node_index}
169     Configure_Netconf_Device    ${DEVICE_NAME}    ${session}    ${ODL_SYSTEM_${node_index}_IP}
170     &{mapping}    BuiltIn.Create_Dictionary    DEVICE_NAME=${DEVICE_NAME}
171     Wait_Netconf_Device_Mounted    ${DEVICE_NAME}    ${session}    ${mapping}
172     FOR    ${idx}    IN    @{ClusterManagement__member_index_list}
173         ${mod_session}=    ClusterManagement.Resolve_Http_Session_For_Member    member_index=${idx}
174         BuiltIn.Wait_Until_Keyword_Succeeds    5x    3s    TemplatedRequests.Get_As_Xml_Templated    ${NETCONF_FOLDER}${/}netconf-state    mapping=${mapping}
175         ...    session=${mod_session}
176     END
177     [Teardown]    Remove_Netconf_Device    ${DEVICE_NAME}    ${session}
178
179 Configure_Netconf_Device
180     [Arguments]    ${device_name}    ${session}    ${device_ip}
181     [Documentation]    Configures the device via REST api.
182     NetconfKeywords.Configure_Device_In_Netconf    ${device_name}    device_type=full-uri-device    device_port=${DEVICE_PORT}    device_address=${device_ip}    device_user=admin    device_password=admin
183     ...    session=${session}
184
185 Remove_Netconf_Device
186     [Arguments]    ${device_name}    ${session}
187     [Documentation]    Removes configured device
188     NetconfKeywords.Remove_Device_From_Netconf    ${device_name}    session=${session}
189
190 Wait_Netconf_Device_Mounted
191     [Arguments]    ${device_name}    ${session}    ${mapping}    ${timeout}=30s
192     [Documentation]    Checks weather the device was mounted.
193     BuiltIn.Wait_Until_Keyword_Succeeds    ${timeout}    3s    TemplatedRequests.Get_As_Xml_Templated    ${NETCONF_FOLDER}${/}full-uri-mount    mapping=${mapping}    session=${session}
194
195 Check_Netconf_Up_And_Running
196     [Arguments]    ${pretty_print}=${EMPTY}
197     [Documentation]    Make a request to netconf connector's list of mounted devices and check that the request was successful.
198     ${response}=    RequestsLibrary.Get_Request    ses    rests/data/network-topology:network-topology/topology\=topology-netconf${netconf_connector}${pretty_print}
199     BuiltIn.Log    ${response.text}
200     ${status}=    BuiltIn.Run_Keyword_And_Return_Status    BuiltIn.Should_Contain    ${response.text}    data model content does not exist
201     BuiltIn.Run_Keyword_If    ${status}    BuiltIn.Set_Suite_Variable    ${netconf_not_ready_cause}    5832
202     BuiltIn.Run_Keyword_If    ${status}    SetupUtils.Set_Known_Bug_Id    5832
203     BuiltIn.Should_Be_Equal_As_Strings    ${response.status_code}    200
204
205 Check_Netconf_Usable
206     NetconfKeywords.Configure_Device_In_Netconf    test-device    device_type=configure-via-topology
207     NetconfKeywords.Remove_Device_From_Netconf    test-device
208     Check_Netconf_Up_And_Running
209
210 Check_Netconf_MDSAL_Up_And_Running
211     ${count}=    SSHKeywords.Count_Port_Occurences    ${ODL_NETCONF_MDSAL_PORT}    LISTEN    java
212     BuiltIn.Should_Be_Equal_As_Integers    ${count}    1