Skip to content

Commit 1b92b8e

Browse files
committed
control: use zipapp to create archive, send as configmap to commander
1 parent 297bcf4 commit 1b92b8e

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

resources/scenarios/commander.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from test_framework.test_node import TestNode
2222
from test_framework.util import PortSeed, get_rpc_proxy
2323

24-
WARNET_FILE = Path(os.path.dirname(__file__)) / "warnet.json"
24+
WARNET_FILE = Path("/warnet.json")
2525

2626
try:
2727
with open(WARNET_FILE) as file:

src/warnet/control.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import base64
2+
import io
23
import json
34
import os
45
import subprocess
56
import sys
67
import time
8+
import zipapp
79
from concurrent.futures import ThreadPoolExecutor, as_completed
810
from pathlib import Path
911

@@ -167,14 +169,13 @@ def run(scenario_file: str, additional_args: tuple[str]):
167169
Pass `-- --help` to get individual scenario help
168170
"""
169171
scenario_path = Path(scenario_file).resolve()
172+
scenario_dir = scenario_path.parent
170173
scenario_name = scenario_path.stem
171174

172175
if additional_args and ("--help" in additional_args or "-h" in additional_args):
173176
return subprocess.run([sys.executable, scenario_path, "--help"])
174177

175-
with open(scenario_path, "rb") as file:
176-
scenario_data = base64.b64encode(file.read()).decode()
177-
178+
# Collect tank data for warnet.json
178179
name = f"commander-{scenario_name.replace('_', '')}-{int(time.time())}"
179180
namespace = get_default_namespace()
180181
tankpods = get_mission("tank")
@@ -191,9 +192,21 @@ def run(scenario_file: str, additional_args: tuple[str]):
191192
for tank in tankpods
192193
]
193194

194-
# Encode warnet data
195+
# Encode tank data for warnet.json
195196
warnet_data = base64.b64encode(json.dumps(tanks).encode()).decode()
196197

198+
# Create in-memory buffer to store python archive instead of writing to disk
199+
archive_buffer = io.BytesIO()
200+
201+
# Compile python archive
202+
zipapp.create_archive(
203+
source=scenario_dir, target=archive_buffer, main=f"{scenario_name}:main", compressed=True
204+
)
205+
206+
# Encode the binary data as Base64
207+
archive_buffer.seek(0)
208+
archive_data = base64.b64encode(archive_buffer.read()).decode()
209+
197210
try:
198211
# Construct Helm command
199212
helm_command = [
@@ -205,9 +218,9 @@ def run(scenario_file: str, additional_args: tuple[str]):
205218
"--set",
206219
f"fullnameOverride={name}",
207220
"--set",
208-
f"scenario={scenario_data}",
209-
"--set",
210221
f"warnet={warnet_data}",
222+
"--set",
223+
f"archive={archive_data}",
211224
]
212225

213226
# Add additional arguments

0 commit comments

Comments
 (0)