-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_10x_support.py
More file actions
executable file
·85 lines (65 loc) · 2.54 KB
/
test_10x_support.py
File metadata and controls
executable file
·85 lines (65 loc) · 2.54 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env python3
"""
Manual diagnostic for controller support file download with UniFi Network 10.x.
"""
import sys
import time
from pathlib import Path
def main() -> int:
# Initialize NSS
import nss.nss as nss_core
from trust import ensure_nss_db
nss_db_dir = Path.home() / ".netcon-sync"
ensure_nss_db(nss_db_dir)
nss_core.nss_init(str(nss_db_dir))
import unifi_utils
from config import UNIFI_SITE_ID
print("=" * 80)
print("Testing Controller Support File with UniFi Network 10.x Format")
print("=" * 80)
print("\n[1] Logging in...")
unifi_utils.login()
print(" [OK] Logged in\n")
print("[2] Triggering support file generation (UniFi Network 10.x format)...")
endpoint = f"/api/s/{UNIFI_SITE_ID}/cmd/system"
payload = {
"cmd": "support",
"userAgent": "unifi-climgr/1.0",
"language": "en-US",
}
response = unifi_utils.make_unifi_api_call("POST", endpoint, json=payload)
print(" [OK] Generation triggered")
print(f" Response: {response}\n")
print("[3] Attempting download from /dl/support (no wait)...")
try:
response = unifi_utils.make_unifi_api_call("GET", "/dl/support", stream=True)
chunk = response.read(100)
response.close()
if chunk and chunk[:2] == b"\x1f\x8b":
print(" [SUCCESS] Got gzip file immediately!\n")
print("[4] Downloading full file...")
timestamp = time.strftime("%Y%m%d-%H%M%S")
filename = f"test_controller_10x_{timestamp}.tar.gz"
download_start = time.time()
response = unifi_utils.make_unifi_api_call("GET", "/dl/support", stream=True)
total_bytes = 0
with open(filename, "wb") as f:
while True:
chunk = response.read(1024 * 1024)
if not chunk:
break
f.write(chunk)
total_bytes += len(chunk)
response.close()
download_time = time.time() - download_start
speed_mbps = (total_bytes / (1024 * 1024)) / download_time if download_time > 0 else 0
print(f"\n[SUCCESS] Downloaded {total_bytes} bytes in {download_time:.1f}s ({speed_mbps:.1f} MB/s)")
print(f" File saved: {filename}")
return 0
print(" [FAIL] Response not a gzip file")
except Exception as e:
print(f" [FAIL] {e}")
print("\n[FAIL] Download failed")
return 1
if __name__ == "__main__":
sys.exit(main())