Spaces:
Sleeping
Sleeping
Download server/faults/system.py from brand0nwalls/NetOps: direct link, hf CLI and curl.
- Browser
- Download file 2.21 kB
-
https://huggingface.co/spaces/brand0nwalls/NetOps/resolve/main/server/faults/system.py
- Command line
-
hf download hf://spaces/brand0nwalls/NetOps/server/faults/system.py
-
curl -L -o system.py https://huggingface.co/spaces/brand0nwalls/NetOps/resolve/main/server/faults/system.py
2.21 kB
| """System faults (F33-F34): CPU exhaustion, stale routes after crash.""" | |
| from __future__ import annotations | |
| import os | |
| import time | |
| from server.constants import GroundTruth | |
| def inject_cpu_exhaustion(injector, router: str, num_hogs: int = 2) -> GroundTruth: | |
| """F33 — Spawn CPU-hogging processes to starve routing daemons.""" | |
| node = injector._nm.get_router(router) | |
| for _ in range(num_hogs): | |
| node.cmd("dd if=/dev/urandom | gzip > /dev/null &") | |
| def undo(): | |
| for pid in injector._find_bg_pids(node, "gzip"): | |
| try: | |
| os.kill(pid, 9) | |
| except ProcessLookupError: | |
| pass | |
| for pid in injector._find_bg_pids(node, "dd if=/dev/urandom"): | |
| try: | |
| os.kill(pid, 9) | |
| except ProcessLookupError: | |
| pass | |
| return injector._register(GroundTruth( | |
| fault_type="cpu_exhaustion", component=router, | |
| details={"router": router, "num_hogs": num_hogs}, | |
| ), undo) | |
| def inject_stale_routes_after_crash(injector, router: str, peer: str, | |
| cost: int = 1000) -> GroundTruth: | |
| """F34 — Kill ospfd, restart with wrong cost (compound: transient + persistent).""" | |
| node = injector._nm.get_router(router) | |
| intf = injector._get_link_intf(router, peer) | |
| pid = injector._find_daemon_pid(node, "ospfd") | |
| if pid: | |
| os.kill(pid, 9) | |
| time.sleep(3) | |
| node.cmd("/usr/lib/frr/ospfd -d") | |
| time.sleep(10) | |
| node.cmd(f'vtysh -c "conf t" -c "router ospf" -c "exit" -c "interface {intf.name}" -c "ip ospf cost {cost}" -c "end"') | |
| time.sleep(5) | |
| def undo(): | |
| node.cmd(f'vtysh -c "conf t" -c "interface {intf.name}" -c "ip ospf cost 10" -c "end"') | |
| return injector._register(GroundTruth( | |
| fault_type="stale_routes_after_crash", component=router, | |
| details={"router": router, "peer": peer, "interface": intf.name, | |
| "cost": cost}, | |
| ), undo) | |
| FAULTS = { | |
| "cpu_exhaustion": {"fn": inject_cpu_exhaustion, "difficulty": "hard", "needs": "router"}, | |
| "stale_routes_after_crash": {"fn": inject_stale_routes_after_crash, "difficulty": "hard", "needs": "link"}, | |
| } | |