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}/ShardStability.robot
19 Resource ${CURDIR}/WaitUtils.robot
20 Resource ${CURDIR}/ScalarClosures.robot
24 [Documentation] Call dependency setups and construct suite variables.
25 WaitUtils.WU_Setup # includes ScalarClosures.SC_Setup
28 [Arguments] ${session}=operational ${topology}=example-ipv4-topology
29 [Documentation] GET the ${topology} data, check status is 200, return the topology data.
31 ... Contrary to Utils.Get_Data_From_URI, this does not Log the (potentially huge) content.
32 ${response} = RequestsLibrary.Get_Request ${session} network-topology:network-topology/topology/${topology}
33 Run_Keyword_If ${response.status_code} != 200 Fail Get on ${topology} returned status code ${response.status_code} with message: ${response.text}
34 [Return] ${response.text}
36 Get_Ipv4_Topology_Count
37 [Arguments] ${session}=operational ${topology}=example-ipv4-topology
38 [Documentation] Get topology. If not fail, return number of prefixes in the topology.
39 ${topology} = Get_Ipv4_Topology session=${session} topology=${topology}
40 # Triple quotes are precaution against formatted output.
41 ${prefix_count} = Builtin.Evaluate len(re.findall('"prefix":"', '''${topology}''')) modules=re
42 [Return] ${prefix_count}
44 Get_Ipv4_Topology_Count_With_Shards_Check
45 [Arguments] ${shards_list} ${details_exp} ${session}=operational ${topology}=example-ipv4-topology
46 [Documentation] Get topology after the shards stability check passes. If not fail, return number of prefixes in the topology.
47 ${details_actual}= ShardStability.Shards_Stability_Get_Details ${shards_list} http_timeout=125
48 ShardStability.Shards_Stability_Compare_Same ${details_actual} stateless_details=${details_exp}
49 ${topology} = Get_Ipv4_Topology session=${session} topology=${topology}
50 # Triple quotes are precaution against formatted output.
51 ${prefix_count} = Builtin.Evaluate len(re.findall('"prefix":"', '''${topology}''')) modules=re
52 [Return] ${prefix_count}
54 Check_Ipv4_Topology_Count
55 [Arguments] ${expected_count} ${session}=operational ${topology}=example-ipv4-topology
56 [Documentation] Check that the count of prefixes matches the expected count. Fails if it does not. In either case, collect garbage.
57 ${actual_count} = ScalarClosures.Run_Keyword_And_Collect_Garbage Get_Ipv4_Topology_Count session=${session} topology=${topology}
58 BuiltIn.Should_Be_Equal_As_Strings ${actual_count} ${expected_count}
60 Check_Ipv4_Topology_Is_Empty
61 [Arguments] ${session}=operational ${topology}=example-ipv4-topology
62 [Documentation] Example_Ipv4_Topology has to give status 200 with zero prefixes.
64 ... Functional suites should use a more strict Keyword which tests for the whole JSON structure.
65 Check_Ipv4_Topology_Count 0 session=${session} topology=${topology}
67 Wait_For_Ipv4_Topology_Prefixes_To_Become_Stable
68 [Arguments] ${timeout}=60s ${period}=5s ${repetitions}=1 ${excluded_count}=-1 ${session}=operational ${topology}=example-ipv4-topology
69 ... ${shards_list}=${EMPTY} ${shards_details}=${EMPTY}
70 [Documentation] Each ${period} get prefix count. When called with shard list, the check is done before the count is get. After ${repetitions} of stable different from ${excluded_count} within ${timeout}, Return validator output. Fail early on getter error.
71 # This is very similar to ChangeCounter keyword, but attempt to extract common code would increase overall code size.
72 ${getter} = BuiltIn.Run_Keyword_If """${shards_list}"""=="""${EMPTY}""" ScalarClosures.Closure_From_Keyword_And_Arguments Get_Ipv4_Topology_Count session=${session} topology=${topology}
73 ... ELSE ScalarClosures.Closure_From_Keyword_And_Arguments Get_Ipv4_Topology_Count_With_Shards_Check ${shards_list} ${shards_details} session=${session}
74 ... topology=${topology}
75 ${validator} = ScalarClosures.Closure_From_Keyword_And_Arguments WaitUtils.Excluding_Stability_Safe_Stateful_Validator_As_Keyword state_holder data_holder excluded_value=${excluded_count}
76 ${result} = WaitUtils.Wait_For_Getter_Error_Or_Safe_Stateful_Validator_Consecutive_Success timeout=${timeout} period=${period} count=${repetitions} getter=${getter} safe_validator=${validator}
77 ... initial_state=${excluded_count}