Skip to content

Commit c343953

Browse files
committed
Add coverage to cluster.py
1 parent c0fbe76 commit c343953

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

src/codeflare_sdk/common/utils/unit_test_support.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
aw_dir = os.path.expanduser("~/.codeflare/resources/")
2727

2828

29-
def create_cluster_config(num_workers=2):
29+
def create_cluster_config(num_workers=2, write_to_file=False):
3030
config = ClusterConfiguration(
3131
name="unit-test-cluster",
3232
namespace="ns",
@@ -36,13 +36,13 @@ def create_cluster_config(num_workers=2):
3636
worker_memory_requests=5,
3737
worker_memory_limits=6,
3838
appwrapper=True,
39-
write_to_file=False,
39+
write_to_file=write_to_file,
4040
)
4141
return config
4242

4343

44-
def create_cluster(mocker, num_workers=2):
45-
cluster = Cluster(create_cluster_config(num_workers))
44+
def create_cluster(mocker, num_workers=2, write_to_file=False):
45+
cluster = Cluster(create_cluster_config(num_workers, write_to_file))
4646
return cluster
4747

4848

src/codeflare_sdk/ray/cluster/test_cluster.py

+30
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,36 @@ def test_cluster_apply_scale_up_scale_down(mocker):
118118
cluster.down()
119119

120120

121+
def test_cluster_apply_with_file(mocker):
122+
mocker.patch("kubernetes.client.ApisApi.get_api_versions")
123+
mocker.patch("kubernetes.config.load_kube_config", return_value="ignore")
124+
mock_dynamic_client = mocker.Mock()
125+
mocker.patch("codeflare_sdk.ray.cluster.cluster.Cluster._throw_for_no_raycluster")
126+
mocker.patch(
127+
"kubernetes.dynamic.DynamicClient.resources", new_callable=mocker.PropertyMock
128+
)
129+
mocker.patch(
130+
"codeflare_sdk.ray.cluster.cluster.Cluster.create_resource",
131+
return_value="./tests/test_cluster_yamls/ray/default-ray-cluster.yaml",
132+
)
133+
mocker.patch("kubernetes.config.load_kube_config", return_value="ignore")
134+
mocker.patch(
135+
"kubernetes.client.CustomObjectsApi.get_cluster_custom_object",
136+
return_value={"spec": {"domain": "apps.cluster.awsroute.org"}},
137+
)
138+
139+
# Step 1: Create cluster with initial workers
140+
cluster = create_cluster(mocker, 1, write_to_file=True)
141+
patch_cluster_with_dynamic_client(mocker, cluster, mock_dynamic_client)
142+
mocker.patch(
143+
"kubernetes.client.CustomObjectsApi.list_namespaced_custom_object",
144+
return_value=get_obj_none("ray.io", "v1", "ns", "rayclusters"),
145+
)
146+
cluster.apply()
147+
# Tear down
148+
cluster.down()
149+
150+
121151
def test_cluster_up_down_no_mcad(mocker):
122152
mocker.patch("codeflare_sdk.ray.cluster.cluster.Cluster._throw_for_no_raycluster")
123153
mocker.patch("kubernetes.config.load_kube_config", return_value="ignore")

0 commit comments

Comments
 (0)