-
Notifications
You must be signed in to change notification settings - Fork 7
/
test.py
73 lines (61 loc) · 2.21 KB
/
test.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
69
70
71
72
73
## cloned from Julio Perez batfish scripts ##
from datetime import datetime
from pybatfish.client.commands import (
bf_session,
bf_init_snapshot,
bf_set_network,
)
from pybatfish.client.session import Session
from pybatfish.question import load_questions
from pybatfish.client.asserts import (
assert_no_duplicate_router_ids,
assert_no_incompatible_bgp_sessions,
assert_no_unestablished_bgp_sessions,
)
from rich.console import Console
console = Console(color_system="truecolor")
def test_duplicate_rtr_ids(snap):
"""Testing for duplicate router IDs"""
console.print(
":white_exclamation_mark: [bold yellow]Testing for duplicate router IDs[/bold yellow] :white_exclamation_mark:"
)
assert_no_duplicate_router_ids(
snapshot=snap,
protocols={"ospf", "bgp"},
)
console.print(
":green_heart: [bold green]No duplicate router IDs found[/bold green] :green_heart:"
)
def test_bgp_compatibility(snap):
"""Testing for incompatible BGP sessions"""
console.print(
":white_exclamation_mark: [bold yellow]Testing for incompatible BGP sessions[/bold yellow] :white_exclamation_mark:"
)
assert_no_incompatible_bgp_sessions(
snapshot=snap,
)
console.print(
":green_heart: [bold green]All BGP sessions compatible![/bold green] :green_heart:"
)
def test_bgp_unestablished(snap):
"""Testing for BGP sessions that are not established"""
console.print(
":white_exclamation_mark: [bold yellow]Testing for unestablished BGP sessions[/bold yellow] :white_exclamation_mark:"
)
assert_no_unestablished_bgp_sessions(
snapshot=snap,
)
console.print(
":green_heart: [bold green]All BGP sessions are established![/bold green] :green_heart:"
)
if __name__ == "__main__":
NETWORK_NAME = "eos_lab"
SNAPSHOT_NAME = f"snapshot-{datetime.today().strftime('%Y-%m-%d')}"
SNAPSHOT_DIR = "./snapshots"
bf_session.host = "192.168.0.200"
bf_set_network(NETWORK_NAME)
init_snap = bf_init_snapshot(SNAPSHOT_DIR, name=SNAPSHOT_NAME, overwrite=True)
load_questions()
test_duplicate_rtr_ids(init_snap)
test_bgp_compatibility(init_snap)
test_bgp_unestablished(init_snap)