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