Testplan and suite for 1 iBGP peer performance tests
[integration/test.git] / csit / libraries / PrefixCounting.robot
1 *** Settings ***
2 Documentation     Robot keyword library (Resource) for common BGP actions concerned with counting prefixes.
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 ...               Currently, all keywords count prefixes only in example-ipv4-topology.
12 ...               Prefix is identified by simplistic regular expression on JSON data.
13 ...
14 ...               This resource assumes that RequestsLibrary has open a connection named "operational"
15 ...               which points to (an analogue of) http://${ODL_SYSTEM_IP}:${RESTCONFPORT}/${OPERATIONAL_API}
16 Library           RequestsLibrary
17 Resource          ${CURDIR}/WaitUtils.robot
18
19 *** Keywords ***
20 PC_Setup
21     [Documentation]    Call dependency setups and construct suite variables.
22     WaitUtils.WU_Setup    # includes ScalarClosures.SC_Setup
23     ${getter} =    ScalarClosures.Closure_From_Keyword_And_Arguments    Get_Ipv4_Topology_Count
24     BuiltIn.Set_Suite_Variable    ${PrefixCounting__getter}    ${getter}
25
26 Get_Ipv4_Topology
27     [Documentation]    GET the example-ipv4-topology data, check status is 200, return the topology data.
28     ...
29     ...    Contrary to Utils.Get_Data_From_URI, this does not Log the (potentially huge) content.
30     ${response} =    RequestsLibrary.Get_Request    operational    network-topology:network-topology/topology/example-ipv4-topology
31     Run_Keyword_If    ${response.status_code} != 200    Fail    Get on example-ipv4-topology returned status code ${response.status_code} with message: ${response.text}
32     [Return]    ${response.text}
33
34 Get_Ipv4_Topology_Count
35     [Documentation]    Get topology. If not fail, return number of prefixes in the topology.
36     ${topology} =    Get_Ipv4_Topology
37     # Triple quotes are precaution against formatted output.
38     ${prefix_count} =    Builtin.Evaluate    len(re.findall('"prefix":"', '''${topology}'''))    modules=re
39     [Return]    ${prefix_count}
40
41 Check_Ipv4_Topology_Count
42     [Arguments]    ${expected_count}
43     [Documentation]    Check that the count of prefixes matches the expected count. Fails if it does not. In either case, collect garbage.
44     ${actual_count} =    ScalarClosures.Run_Keyword_And_Collect_Garbage    Get_Ipv4_Topology_Count
45     BuiltIn.Should_Be_Equal_As_Strings    ${actual_count}    ${expected_count}
46
47 Check_Ipv4_Topology_Is_Empty
48     [Documentation]    Example_Ipv4_Topology has to give status 200 with zero prefixes.
49     ...
50     ...    Functional suites should use a more strict Keyword which tests for the whole JSON structure.
51     Check_Ipv4_Topology_Count    0
52
53 Wait_For_Ipv4_Topology_Prefixes_To_Become_Stable
54     [Arguments]    ${timeout}=60s    ${period}=5s    ${repetitions}=1    ${excluded_count}=-1
55     [Documentation]    Each ${period} get prefix count. After ${repetitions} of stable different from ${excluded_count} within ${timeout}, Return validator output. Fail early on getter error.
56     # This is very similar to ChangeCounter keyword, but attempt to extract common code would increase overall code size.
57     ${validator} =    ScalarClosures.Closure_From_Keyword_And_Arguments    WaitUtils.Excluding_Stability_Safe_Stateful_Validator_As_Keyword    state_holder    data_holder    excluded_value=${excluded_count}
58     ${result} =    WaitUtils.Wait_For_Getter_Error_Or_Safe_Stateful_Validator_Consecutive_Success    timeout=${timeout}    period=${period}    count=${repetitions}    getter=${PrefixCounting__getter}    safe_validator=${validator}
59     ...    initial_state=${excluded_count}
60     [Return]    ${result}