Migrate Get Requests invocations(libraries)
[integration/test.git] / csit / libraries / ChangeCounter.robot
1 *** Settings ***
2 Documentation       Robot keyword library (Resource) for common handling of data change counter.
3 ...
4 ...                 Copyright (c) 2015 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 ...                 This resource creates a "default" session using TemplatedRequests.Create_Default_Session
12 ...                 which points to (an analogue of) http://${ODL_SYSTEM_IP}:${RESTCONFPORT}
13
14 Library             RequestsLibrary
15 Resource            ${CURDIR}/CompareStream.robot
16 Resource            ${CURDIR}/ScalarClosures.robot
17 Resource            ${CURDIR}/TemplatedRequests.robot
18 Resource            ${CURDIR}/WaitUtils.robot
19
20
21 *** Variables ***
22 ${CHANGE_COUNTER_TEMPLATE_FOLDER}       ${CURDIR}/../variables/bgpuser
23 ${CC_DATA_CHANGE_COUNTER_URL}           ${REST_API}/data-change-counter:data-change-counter?content=nonconfig
24
25
26 *** Keywords ***
27 CC_Setup
28     [Documentation]    Initialize dependency libraries.
29     TemplatedRequests.Create_Default_Session
30     WaitUtils.WU_Setup    # includes ScalarClosures.SC_Setup
31     ${counter} =    ScalarClosures.Closure_From_Keyword_And_Arguments    Get_Change_Count
32     BuiltIn.Set_Suite_Variable    ${ChangeCounter__getter}    ${counter}
33
34 Get_Change_Count
35     [Documentation]    GET data change request, assert status 200, return the value.
36     [Arguments]    ${session}=operational
37     ${response} =    RequestsLibrary.GET On Session    ${session}    url=${CC_DATA_CHANGE_COUNTER_URL}    expected_status=200
38     # CompareStream.Set_Variable_If_At_Least_Else cannot be used direcly, because ${response.text}["data-change-counter"]["count"] would be
39     # evaluated before the stream comparison and it causes failures
40     BuiltIn.Log    ${response.text}
41     ${count} =    BuiltIn.Evaluate
42     ...    json.loads('${response.text}')["data-change-counter:data-change-counter"]["counter"][0]["count"]
43     ...    modules=json
44     RETURN    ${count}
45
46 Reconfigure_Topology_Name
47     [Documentation]    Configure data change counter to count transactions affecting
48     ...    ${topology_name} instead of previously configured topology name.
49     [Arguments]    ${topology_name}=example-linkstate-topology
50     &{mapping} =    Create Dictionary    DEVICE_NAME=${DEVICE_NAME}    TOPOLOGY_NAME=${topology_name}
51     TemplatedRequests.Put_As_Xml_Templated    ${CHANGE_COUNTER_TEMPLATE_FOLDER}${/}change_counter    mapping=${mapping}
52
53 Wait_For_Change_Count_To_Become_Stable
54     [Documentation]    Each ${period} get count. After ${repetitions} of constant value above ${count_to_overcome} within ${timeout}, Return validator output. Fail early on getter error.
55     [Arguments]    ${timeout}=60s    ${period}=1s    ${repetitions}=4    ${count_to_overcome}=-1
56     ${validator} =    WaitUtils.Create_Limiting_Stability_Safe_Stateful_Validator_From_Value_To_Overcome
57     ...    maximum_invalid=${count_to_overcome}
58     ${result} =    WaitUtils.Wait_For_Getter_Error_Or_Safe_Stateful_Validator_Consecutive_Success
59     ...    timeout=${timeout}
60     ...    period=${period}
61     ...    count=${repetitions}
62     ...    getter=${ChangeCounter__getter}
63     ...    safe_validator=${validator}
64     ...    initial_state=${count_to_overcome}
65     RETURN    ${result}