-
Notifications
You must be signed in to change notification settings - Fork 4
/
test_fabric_bgp_peers.py
executable file
·66 lines (56 loc) · 2.21 KB
/
test_fabric_bgp_peers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python3
import requests
import json
DEVICE_LIST = [
"clab-dc1-pods-pod1-sp1",
"clab-dc1-pods-pod1-sp2",
"clab-dc1-pods-pod1-sp3",
]
VRF = "default"
BGP_PEERS = {"underlay": 6, "overlay-fabric": 6}
BGP_GROUPS = ["underlay", "overlay-fabric"]
PREFIX_COUNTS = {"recieved": {"underlay": 6, "overlay-fabric": 48}}
jsonrpc_path = "/jsonrpc"
default_cred = ("admin", "NokiaSrl1!")
headers = {"Content-type": "application/json"}
def build_rpc_request(path: str, datastore: str) -> str:
body = {
"jsonrpc": "2.0",
"id": 0,
"method": "get",
"params": {"commands": [{"path": path, "datastore": datastore}]},
}
return body
def assert_bgp_peer_status(response: requests.models.Response, bgp_group: str) -> tuple:
peer_status = response.json()["result"][0]
if peer_status["total-peers"] == BGP_PEERS[bgp_group]:
if peer_status["up-peers"] == BGP_PEERS[bgp_group]:
state_str = f"peers expected {BGP_PEERS[bgp_group]} ... cfgd {peer_status['total-peers']} / {peer_status['up-peers']} up"
state_bool = True
else:
state_str = f"peers expected {BGP_PEERS[bgp_group]} ... cfgd {peer_status['total-peers']} / {peer_status['up-peers']} up"
state_bool = False
else:
state_str = f"peers expected {BGP_PEERS[bgp_group]} ... cfgd {peer_status['total-peers']} / {peer_status['up-peers']} up"
state_bool = False
return (state_bool, state_str)
for group in BGP_GROUPS:
for device in DEVICE_LIST:
url = f"https://{device}{jsonrpc_path}"
response = requests.post(
url,
data=json.dumps(
build_rpc_request(
path=f"/network-instance[name={VRF}]/protocols/bgp/group[group-name={group}]/statistics",
datastore="state",
)
),
headers=headers,
auth=requests.auth.HTTPBasicAuth(*default_cred),
verify="clab-dc1-pods/.tls/ca/ca.pem",
)
success, result = assert_bgp_peer_status(response, group)
if success:
print(f"\U00002705 {device}: {group}: {result}")
else:
print(f"\U0000274C {device}: {group}: {result}")