Netconfready: Add longer wait
[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 ...               By default this is done by querying netconf-connector and
15 ...               seeing whether it works. Some testsuites expect netconf-connector
16 ...               to be ready as soon as possible and will fail if it is not. We
17 ...               want to see a failure if this is the cause of the failure.
18 ...
19 ...               If the netconf-connector is not ready upon startup (as seen by
20 ...               the first test case failing), the second case starts to repeat
21 ...               the query for a minute to see whether it is going "to fix itself"
22 ...               within the minute. If yes, then the testcase will pass, which
23 ...               indicates that the "ODL cooldown" of 1 minute is not long enough
24 ...               to allow for netconf-connector to initialize properly.
25 ...               If this fails, one more check with even longer timeout is run.
26 ...
27 ...               If the USE_NETCONF_CONNECTOR is forced to be False by the Robot
28 ...               invocation argument, then the suite does not use netconf
29 ...               connector for the readiness detection but merely waits for the
30 ...               Netconf topology to appear. This is a weaker condition when
31 ...               Netconf connector is about to be used but is necessary if the
32 ...               suite in question does not use the Netconf connector.
33 ...
34 ...               If the first test case passed, then the second test case does
35 ...               nothing.
36 ...
37 ...               The third test case then checks whether Netconf can pretty print
38 ...               data. This sometimes makes problems, most likely due to too
39 ...               new Robot Requests library with an interface incompatible with
40 ...               this test suite.
41 Suite Setup       Setup_Everything
42 Suite Teardown    Teardown_Everything
43 Test Setup        SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
44 Test Teardown     SetupUtils.Teardown_Test_Show_Bugs_If_Test_Failed
45 Library           RequestsLibrary
46 Resource          ${CURDIR}/../../../libraries/NetconfKeywords.robot
47 Resource          ${CURDIR}/../../../libraries/SetupUtils.robot
48 Resource          ${CURDIR}/../../../libraries/SSHKeywords.robot
49 Variables         ${CURDIR}/../../../variables/Variables.py
50
51 *** Variables ***
52 ${netconf_is_ready}    False
53 ${NETCONFREADY_WAIT}    60s
54 ${NETCONFREADY_FALLBACK_WAIT}    1200s
55 ${USE_NETCONF_CONNECTOR}    True
56 ${DEBUG_LOGGING_FOR_EVERYTHING}    False
57 ${NETCONFREADY_WAIT_MDSAL}    60s
58
59 *** Test Cases ***
60 Check_Whether_Netconf_Is_Up_And_Running
61     [Documentation]    Make one request to Netconf topology to see whether Netconf is up and running.
62     [Tags]    exclude
63     Check_Netconf_Up_And_Running
64     BuiltIn.Set_Suite_Variable    ${netconf_is_ready}    True
65
66 Wait_For_Netconf
67     [Documentation]    Wait for the Netconf to go up for configurable time.
68     [Tags]    critical
69     BuiltIn.Run_Keyword_Unless    ${netconf_is_ready}    BuiltIn.Wait_Until_Keyword_Succeeds    ${NETCONFREADY_WAIT}    1s    Check_Netconf_Up_And_Running
70     BuiltIn.Set_Suite_Variable    ${netconf_is_ready}    True
71
72 Wait_Even_Longer
73     [Documentation]    Bugs such as 7175 may require to wait longer till netconf-connector works.
74     [Tags]    critical
75     BuiltIn.Pass_Execution_If    ${netconf_is_ready}    Netconf was detected to be up and running so bug 5014 did not show up.
76     BuiltIn.Wait_Until_Keyword_Succeeds    ${NETCONFREADY_FALLBACK_WAIT}    10s    Check_Netconf_Up_And_Running
77     BuiltIn.Set_Suite_Variable    ${netconf_is_ready}    True
78
79 Check_For_Bug_5014
80     [Documentation]    If Netconf appears to be down, it may be due to bug 5014. Check if it is so and fail if yes.
81     ...    Bug 5014 is about Netconf playing dead on boot until a device
82     ...    configuration request is sent to it. To uncover this attempt to
83     ...    configure and then deconfigure a device and then check if Netconf
84     ...    is now up and running. If that turns out to be true, fail the case
85     ...    as this signifies the bug 5014 to be present. Skip this testcase
86     ...    if Netconf is detected to be up and running.
87     [Tags]    critical
88     BuiltIn.Pass_Execution_If    ${netconf_is_ready}    Netconf was detected to be up and running so bug 5014 did not show up.
89     ${status}    ${error}=    BuiltIn.Run_Keyword_And_Ignore_Error    Check_Netconf_Usable
90     BuiltIn.Run_Keyword_If    '${status}'=='PASS'    BuiltIn.Set_Suite_Variable    ${netconf_is_ready}    True
91     BuiltIn.Should_Be_Equal    '${status}'    'FAIL'
92
93 Check_Whether_Netconf_Can_Pretty_Print
94     [Documentation]    Make one request to netconf-connector and see if it works.
95     [Tags]    critical
96     BuiltIn.Run_Keyword_Unless    ${netconf_is_ready}    Fail    Netconf is not ready so it can't pretty-print now.
97     Check_Netconf_Up_And_Running    ?prettyPrint=true
98
99 Wait_For_MDSAL
100     [Documentation]    Wait for the MDSAL feature to become online
101     ${status}    ${message}=    BuiltIn.Run_Keyword_And_Ignore_Error    KarafKeywords.Verify_Feature_Is_Installed    odl-netconf-mdsal
102     BuiltIn.Run_Keyword_If    '${status}' == 'FAIL'    BuiltIn.Pass_Execution    The 'odl-netconf-mdsal' feature is not installed so no need to wait for it.
103     SSHKeywords.Open_Connection_To_ODL_System
104     BuiltIn.Wait_Until_Keyword_Succeeds    ${NETCONFREADY_WAIT_MDSAL}    1s    Check_Netconf_MDSAL_Up_And_Running
105     SSHLibrary.Close_Connection
106
107 *** Keywords ***
108 Setup_Everything
109     [Documentation]    Initialize SetupUtils. Setup requests library and log into karaf.log that the netconf readiness wait starts.
110     SetupUtils.Setup_Utils_For_Setup_And_Teardown
111     ${connector}=    BuiltIn.Set_Variable_If    ${USE_NETCONF_CONNECTOR}    /node/controller-config/yang-ext:mount/config:modules/module/odl-sal-netconf-connector-cfg:sal-netconf-connector/controller-config    ${EMPTY}
112     BuiltIn.Set_Suite_Variable    ${netconf_connector}    ${connector}
113     BuiltIn.Comment    A workaround for EOF error follows. TODO: Create a test case for the EOF bug, possibly tagged "exclude".
114     BuiltIn.Wait_Until_Keyword_Succeeds    2x    1s    KarafKeywords.Open_Controller_Karaf_Console_On_Background
115     KarafKeywords.Log_Message_To_Controller_Karaf    Starting Netconf readiness test suite
116     BuiltIn.Run_Keyword_If    ${DEBUG_LOGGING_FOR_EVERYTHING}    KarafKeywords.Execute_Controller_Karaf_Command_On_Background    log:set DEBUG
117     RequestsLibrary.Create_Session    ses    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}
118     NetconfKeywords.Setup_Netconf_Keywords
119
120 Teardown_Everything
121     [Documentation]    Destroy all sessions in the requests library and log into karaf.log that the netconf readiness wait is over.
122     KarafKeywords.Log_Message_To_Controller_Karaf    Ending Netconf readiness test suite
123     RequestsLibrary.Delete_All_Sessions
124
125 Check_Netconf_Up_And_Running
126     [Arguments]    ${pretty_print}=${EMPTY}
127     [Documentation]    Make a request to netconf connector's list of mounted devices and check that the request was successful.
128     ${response}=    RequestsLibrary.Get_Request    ses    restconf/config/network-topology:network-topology/topology/topology-netconf${netconf_connector}${pretty_print}
129     BuiltIn.Log    ${response.text}
130     ${status}=    BuiltIn.Run_Keyword_And_Return_Status    BuiltIn.Should_Contain    ${response.text}    data model content does not exist
131     BuiltIn.Run_Keyword_If    ${status}    BuiltIn.Set_Suite_Variable    ${netconf_not_ready_cause}    5832
132     BuiltIn.Run_Keyword_If    ${status}    SetupUtils.Set_Known_Bug_Id    5832
133     BuiltIn.Should_Be_Equal_As_Strings    ${response.status_code}    200
134
135 Check_Netconf_Usable
136     NetconfKeywords.Configure_Device_In_Netconf    test-device    device_type=configure-via-topology
137     NetconfKeywords.Remove_Device_From_Netconf    test-device
138     Check_Netconf_Up_And_Running
139
140 Check_Netconf_MDSAL_Up_And_Running
141     ${count}=    SSHKeywords.Count_Port_Occurences    ${ODL_NETCONF_MDSAL_PORT}    LISTEN    java
142     BuiltIn.Should_Be_Equal_As_Integers    ${count}    1