Fix bgpcep testtool deploy when running with snapshots.
[integration/test.git] / csit / libraries / WaitForFailure.robot
1 *** Settings ***
2 Documentation     Robot keyword Resource for catching a later failure in temporarily passing repeated check.
3 ...
4 ...               Copyright (c) 2015-2017 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 ...               Terminology:
12 ...               "cell_sequence" is a sequence of Robot cells, usually executable.
13 ...               "keyword_name" is a first cell in that sequence, entry point of execution,
14 ...               the item defined in Keywords table (or in a Library or Resource)
15 ...               which may take arguments (the rest of cell sequence).
16 ...               Note that this may not work correctly with named arguments, due to ordering,
17 ...               so positional cells are strongly suggested to be positional arguments.
18 ...               "Keyword" or "keyword" may refer to keyword_name or executable cell sequence,
19 ...               or both, depending on context.
20
21 *** Keywords ***
22 Log_Failable_Keyword
23     [Arguments]    @{cell_sequence}
24     [Documentation]    Execute failable Keyword. Log the resulting value when it does not fail.
25     ...    Deprecated, was used in previous implementation of higher-level keywords.
26     ${result} =    BuiltIn.Run_Keyword    @{cell_sequence}
27     BuiltIn.Log    ${result}
28     [Return]    ${result}
29
30 Keyword_Should_Fail_In_Any_Way
31     [Arguments]    @{cell_sequence}
32     [Documentation]    Try to run the Keyword and Log the result. Pass and return the error on any failure, Fail otherwise.
33     ...    Deprecated, was used in previous implementation of higher-level keywords.
34     ${error} =    BuiltIn.Run_Keyword_And_Expect_Error    *    Log_Failable_Keyword    @{cell_sequence}
35     # '*' means we really catch all types of errors.
36     [Return]    ${error}
37
38 Invert_Failure
39     [Arguments]    @{cell_sequence}
40     [Documentation]    The response of Keyword execution is either a return value or a failure message.
41     ...    This keyword calls the argument keyword and returns its failure message string,
42     ...    or fails with its return value converted to string.
43     ${status}    ${output} =    BuiltIn.Run_Keyword_And_Ignore_Error    @{cell_sequence}
44     BuiltIn.Run_Keyword_If    "${status}" != "PASS"    BuiltIn.Return_From_Keyword    ${output}
45     ${output} =    BuiltIn.Convert_To_String    ${output}
46     BuiltIn.Fail    ${output}
47
48 Confirm_Keyword_Fails_Within_Timeout
49     [Arguments]    ${timeout}    ${refresh}    @{cell_list}
50     [Documentation]    Some Keywords need several tries to finally fail, this keyword passes if and only if the failure ultimately happens.
51     # Arguments with default values interact badly with varargs, so using WUKS argument style.
52     BuiltIn.Run_Keyword_And_Return    BuiltIn.Wait_Until_Keyword_Succeeds    ${timeout}    ${refresh}    Invert_Failure    @{cell_list}
53
54 Verify_Keyword_Never_Passes_Within_Timeout
55     [Arguments]    ${timeout}    ${refresh}    @{cell_list}
56     [Documentation]    Some negative checks report false failure for a short time. This keyword verifies no pass does happen within timeout period.
57     BuiltIn.Run_Keyword_And_Return    Invert_Failure    BuiltIn.Wait_Until_Keyword_Succeeds    ${timeout}    ${refresh}    @{cell_list}
58
59 Verify_Keyword_Does_Not_Fail_Within_Timeout
60     [Arguments]    ${timeout}    ${refresh}    @{cell_list}
61     [Documentation]    Some positive checks report false success for a short time. This keyword verifies no failure does happen within timeout period.
62     ...    This implementation needs more complicated logic than, Verify_Keyword_Never_Passes_Within_Timeout,
63     ...    so use that keyword in case you have a negative check handy.
64     BuiltIn.Run_Keyword_And_Return    Invert_Failure    Confirm_Keyword_Fails_Within_Timeout    ${timeout}    ${refresh}    @{cell_list}
65     # TODO: Remove the added comment text of time running out to restore last Keyword return value.