updating bgpingest suites to support openconfig for carbon
[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 Library           RequestsLibrary
14 Resource          ${CURDIR}/ScalarClosures.robot
15 Resource          ${CURDIR}/TemplatedRequests.robot
16 Resource          ${CURDIR}/WaitUtils.robot
17
18 *** Variables ***
19 ${CHANGE_COUNTER_TEMPLATE_FOLDER}    ${CURDIR}/../variables/bgpuser
20
21 *** Keywords ***
22 CC_Setup
23     [Documentation]    Initialize dependency libraries.
24     TemplatedRequests.Create_Default_Session
25     WaitUtils.WU_Setup    # includes ScalarClosures.SC_Setup
26     ${counter} =    ScalarClosures.Closure_From_Keyword_And_Arguments    Get_Change_Count
27     BuiltIn.Set_Suite_Variable    ${ChangeCounter__getter}    ${counter}
28
29 Get_Change_Count
30     [Documentation]    GET data change request, assert status 200, return the value.
31     ${response} =    RequestsLibrary.Get_Request    operational    data-change-counter:data-change-counter
32     BuiltIn.Should_Be_Equal    ${response.status_code}    ${200}    Got status: ${response.status_code} and message: ${response.text}
33     # TODO: The following line can be insecure. Should we use regexp instead?
34     # TODO: beware of new releases (carbon ...) and mind if more counters are used
35     ${count} =    BuiltIn.Run Keyword If    "${ODL_STREAM}" in ["beryllium", "stable-lithium"]    BuiltIn.Evaluate    ${response.text}["data-change-counter"]["count"]
36     ...    ELSE    BuiltIn.Evaluate    ${response.text}["data-change-counter"]["counter"][0]["count"]
37     [Return]    ${count}
38
39 Reconfigure_Topology_Name
40     [Arguments]    ${topology_name}=example-linkstate-topology
41     [Documentation]    Configure data change counter to count transactions affecting
42     ...    ${topology_name} instead of previously configured topology name.
43     &{mapping}    Create Dictionary    DEVICE_NAME=${DEVICE_NAME}    TOPOLOGY_NAME=${topology_name}
44     TemplatedRequests.Put_As_Xml_Templated    ${CHANGE_COUNTER_TEMPLATE_FOLDER}${/}change_counter    mapping=${mapping}
45
46 Wait_For_Change_Count_To_Become_Stable
47     [Arguments]    ${timeout}=60s    ${period}=1s    ${repetitions}=4    ${count_to_overcome}=-1
48     [Documentation]    Each ${period} get count. After ${repetitions} of constant value above ${count_to_overcome} within ${timeout}, Return validator output. Fail early on getter error.
49     ${validator} =    WaitUtils.Create_Limiting_Stability_Safe_Stateful_Validator_From_Value_To_Overcome    maximum_invalid=${count_to_overcome}
50     ${result} =    WaitUtils.Wait_For_Getter_Error_Or_Safe_Stateful_Validator_Consecutive_Success    timeout=${timeout}    period=${period}    count=${repetitions}    getter=${ChangeCounter__getter}    safe_validator=${validator}
51     ...    initial_state=${count_to_overcome}
52     [Return]    ${result}