-
Notifications
You must be signed in to change notification settings - Fork 4
/
test_fabric_interfaces.py
executable file
·68 lines (59 loc) · 1.79 KB
/
test_fabric_interfaces.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
67
68
#!/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",
]
INTERFACE_LIST = [
"ethernet-1/1",
"ethernet-1/2",
"ethernet-1/3",
"ethernet-1/4",
"ethernet-1/5",
"ethernet-1/6",
]
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_interface_status(response: requests.models.Response) -> tuple:
interface_state = response.json()["result"][0]
if interface_state["admin-state"] == "enable":
if interface_state["oper-state"] == "up":
state_str = "up/up"
state_bool = True
else:
state_str = "up/down"
state_bool = False
else:
state_str = "down"
state_bool = False
return (state_bool, state_str)
for device in DEVICE_LIST:
url = f"https://{device}{jsonrpc_path}"
for interface in INTERFACE_LIST:
response = requests.post(
url,
data=json.dumps(
build_rpc_request(
path=f"/interface[name={interface}]", datastore="state"
)
),
headers=headers,
auth=requests.auth.HTTPBasicAuth(*default_cred),
verify="clab-dc1-pods/.tls/ca/ca.pem",
)
success, result = assert_interface_status(response)
if success:
print(f"\U00002705 {device}: {interface}: {result}")
else:
print(f"\U0000274C {device}: {interface}: {result}")