-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexec_commands.py
More file actions
executable file
·59 lines (50 loc) · 2.3 KB
/
Copy pathexec_commands.py
File metadata and controls
executable file
·59 lines (50 loc) · 2.3 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
#!/usr/bin/env python3
"""Minimal script for executing simple commands on daemons"""
from sandd import Server
import time
import sys
print("Starting SandD server...")
server = Server("127.0.0.1", 8765)
print(f"✓ Server started on {server.address}")
print("\nStart a daemon with:")
print(" ./target/release/sandd --server-url ws://127.0.0.1:8765/ws")
print("\nWaiting for daemons (Ctrl+C to exit)...\n")
try:
while True:
daemons = server.list_daemons()
stats = server.get_stats()
print(f"\rConnected: {stats.total_daemons} | Platforms: {stats.by_platform}", end="", flush=True)
if daemons and len(daemons) > 0:
for daemon in daemons:
daemon_id = daemon.id
try:
# Test 1: Python script
result = server.exec(
daemon_id,
"python3 -c 'import sys; print(f\"Python {sys.version_info.major}.{sys.version_info.minor}\")'",
timeout=5
)
if result.success:
print(f"\n✓ Python test passed on {daemon_id}: {result.stdout.strip()}")
else:
print(f"\n✗ Python test failed on {daemon_id}: exit_code={result.exit_code}")
# Test 2: Wrong Python script (intentional error)
result = server.exec(
daemon_id,
"python3 -c 'undefined_variable'",
timeout=5
)
if not result.success:
print(f"✓ Error handling test passed on {daemon_id}, stderr: {result.stderr.strip()}")
else:
print(f"✗ Error handling test failed on {daemon_id}: expected error but got success")
# Test 3: Echo command
result = server.exec(daemon_id, "echo 'Hello from daemon!'", timeout=5)
if result.success:
print(f"✓ Echo test passed on {daemon_id}: {result.stdout.strip()}")
except Exception as e:
print(f"\n✗ Command failed on {daemon_id}: {e}")
time.sleep(2)
except KeyboardInterrupt:
print("\n\nShutting down...")
sys.exit(0)