Skip to content

Commit d41d7bd

Browse files
committed
add: save appwrappers to .codeflare/appwrapper/ directory.
1 parent 996264a commit d41d7bd

File tree

3 files changed

+33
-17
lines changed

3 files changed

+33
-17
lines changed

src/codeflare_sdk/cluster/cluster.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ def __init__(self, config: ClusterConfiguration):
6060
"""
6161
self.config = config
6262
self.app_wrapper_yaml = self.create_app_wrapper()
63-
self.app_wrapper_name = self.app_wrapper_yaml.split(".")[0]
63+
self.app_wrapper_name = self.app_wrapper_yaml.replace(".yaml", "").split("/")[
64+
-1
65+
]
6466

6567
def evaluate_dispatch_priority(self):
6668
priority_class = self.config.dispatch_priority

src/codeflare_sdk/utils/generate_yaml.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import yaml
2121
import sys
22+
import os
2223
import argparse
2324
import uuid
2425
from kubernetes import client, config
@@ -364,8 +365,14 @@ def disable_raycluster_tls(resources):
364365

365366

366367
def write_user_appwrapper(user_yaml, output_file_name):
368+
# Create the directory if it doesn't exist
369+
directory_path = os.path.dirname(output_file_name)
370+
if not os.path.exists(directory_path):
371+
os.makedirs(directory_path)
372+
367373
with open(output_file_name, "w") as outfile:
368374
yaml.dump(user_yaml, outfile, default_flow_style=False)
375+
369376
print(f"Written to: {output_file_name}")
370377

371378

@@ -433,6 +440,8 @@ def generate_appwrapper(
433440
enable_local_interactive(resources, cluster_name, namespace)
434441
else:
435442
disable_raycluster_tls(resources["resources"])
436-
outfile = appwrapper_name + ".yaml"
443+
directory_path = ".codeflare/appwrapper/"
444+
445+
outfile = os.path.join(directory_path, appwrapper_name + ".yaml")
437446
write_user_appwrapper(user_yaml, outfile)
438447
return outfile

tests/unit_test.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import re
2020

2121
parent = Path(__file__).resolve().parents[1]
22+
aw_dir = ".codeflare/appwrapper/"
2223
sys.path.append(str(parent) + "/src")
2324

2425
from kubernetes import client, config
@@ -241,10 +242,12 @@ def test_config_creation():
241242

242243
def test_cluster_creation():
243244
cluster = createClusterWithConfig()
244-
assert cluster.app_wrapper_yaml == "unit-test-cluster.yaml"
245+
assert cluster.app_wrapper_yaml == f"{aw_dir}unit-test-cluster.yaml"
245246
assert cluster.app_wrapper_name == "unit-test-cluster"
246247
assert filecmp.cmp(
247-
"unit-test-cluster.yaml", f"{parent}/tests/test-case.yaml", shallow=True
248+
f"{aw_dir}unit-test-cluster.yaml",
249+
f"{parent}/tests/test-case.yaml",
250+
shallow=True,
248251
)
249252

250253

@@ -258,10 +261,12 @@ def test_cluster_creation_priority(mocker):
258261
config.name = "prio-test-cluster"
259262
config.dispatch_priority = "default"
260263
cluster = Cluster(config)
261-
assert cluster.app_wrapper_yaml == "prio-test-cluster.yaml"
264+
assert cluster.app_wrapper_yaml == f"{aw_dir}prio-test-cluster.yaml"
262265
assert cluster.app_wrapper_name == "prio-test-cluster"
263266
assert filecmp.cmp(
264-
"prio-test-cluster.yaml", f"{parent}/tests/test-case-prio.yaml", shallow=True
267+
f"{aw_dir}prio-test-cluster.yaml",
268+
f"{parent}/tests/test-case-prio.yaml",
269+
shallow=True,
265270
)
266271

267272

@@ -275,7 +280,7 @@ def test_default_cluster_creation(mocker):
275280
)
276281
cluster = Cluster(default_config)
277282

278-
assert cluster.app_wrapper_yaml == "unit-test-default-cluster.yaml"
283+
assert cluster.app_wrapper_yaml == f"{aw_dir}unit-test-default-cluster.yaml"
279284
assert cluster.app_wrapper_name == "unit-test-default-cluster"
280285
assert cluster.config.namespace == "opendatahub"
281286

@@ -285,7 +290,7 @@ def arg_check_apply_effect(group, version, namespace, plural, body, *args):
285290
assert version == "v1beta1"
286291
assert namespace == "ns"
287292
assert plural == "appwrappers"
288-
with open("unit-test-cluster.yaml") as f:
293+
with open(f"{aw_dir}unit-test-cluster.yaml") as f:
289294
aw = yaml.load(f, Loader=yaml.FullLoader)
290295
assert body == aw
291296
assert args == tuple()
@@ -2147,7 +2152,7 @@ def parse_j(cmd):
21472152

21482153

21492154
def test_AWManager_creation():
2150-
testaw = AWManager("test.yaml")
2155+
testaw = AWManager(f"{aw_dir}test.yaml")
21512156
assert testaw.name == "test"
21522157
assert testaw.namespace == "ns"
21532158
assert testaw.submitted == False
@@ -2171,7 +2176,7 @@ def arg_check_aw_apply_effect(group, version, namespace, plural, body, *args):
21712176
assert version == "v1beta1"
21722177
assert namespace == "ns"
21732178
assert plural == "appwrappers"
2174-
with open("test.yaml") as f:
2179+
with open(f"{aw_dir}test.yaml") as f:
21752180
aw = yaml.load(f, Loader=yaml.FullLoader)
21762181
assert body == aw
21772182
assert args == tuple()
@@ -2187,7 +2192,7 @@ def arg_check_aw_del_effect(group, version, namespace, plural, name, *args):
21872192

21882193

21892194
def test_AWManager_submit_remove(mocker, capsys):
2190-
testaw = AWManager("test.yaml")
2195+
testaw = AWManager(f"{aw_dir}test.yaml")
21912196
testaw.remove()
21922197
captured = capsys.readouterr()
21932198
assert (
@@ -2294,12 +2299,12 @@ def test_export_env():
22942299

22952300
# Make sure to always keep this function last
22962301
def test_cleanup():
2297-
os.remove("unit-test-cluster.yaml")
2298-
os.remove("prio-test-cluster.yaml")
2299-
os.remove("unit-test-default-cluster.yaml")
2300-
os.remove("test.yaml")
2301-
os.remove("raytest2.yaml")
2302-
os.remove("quicktest.yaml")
2302+
os.remove(f"{aw_dir}unit-test-cluster.yaml")
2303+
os.remove(f"{aw_dir}prio-test-cluster.yaml")
2304+
os.remove(f"{aw_dir}unit-test-default-cluster.yaml")
2305+
os.remove(f"{aw_dir}test.yaml")
2306+
os.remove(f"{aw_dir}raytest2.yaml")
2307+
os.remove(f"{aw_dir}quicktest.yaml")
23032308
os.remove("tls-cluster-namespace/ca.crt")
23042309
os.remove("tls-cluster-namespace/tls.crt")
23052310
os.remove("tls-cluster-namespace/tls.key")

0 commit comments

Comments
 (0)