Skip to content

Commit 97fc348

Browse files
committed
Improving coverage of cluster.py
1 parent 07700e9 commit 97fc348

File tree

1 file changed

+71
-1
lines changed

1 file changed

+71
-1
lines changed

src/codeflare_sdk/ray/cluster/test_cluster.py

+71-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ def test_cluster_apply_scale_up_scale_down(mocker):
7878
mocker.patch("kubernetes.client.ApisApi.get_api_versions")
7979
mocker.patch("kubernetes.config.load_kube_config", return_value="ignore")
8080
mock_dynamic_client = mocker.Mock()
81-
mocker.patch("codeflare_sdk.ray.cluster.cluster.Cluster._throw_for_no_raycluster")
8281
mocker.patch(
8382
"kubernetes.dynamic.DynamicClient.resources", new_callable=mocker.PropertyMock
8483
)
@@ -149,6 +148,77 @@ def test_cluster_apply_with_file(mocker):
149148
cluster.down()
150149

151150

151+
def test_cluster_apply_with_appwrapper(mocker):
152+
# Mock Kubernetes client and dynamic client methods
153+
mocker.patch("kubernetes.client.ApisApi.get_api_versions")
154+
mocker.patch("kubernetes.config.load_kube_config", return_value="ignore")
155+
mocker.patch(
156+
"codeflare_sdk.ray.cluster.cluster._check_aw_exists",
157+
return_value=True,
158+
)
159+
mock_dynamic_client = mocker.Mock()
160+
mocker.patch("codeflare_sdk.ray.cluster.cluster.Cluster._throw_for_no_raycluster")
161+
mocker.patch(
162+
"kubernetes.dynamic.DynamicClient.resources", new_callable=mocker.PropertyMock
163+
)
164+
mocker.patch(
165+
"codeflare_sdk.ray.cluster.cluster.Cluster.create_resource",
166+
return_value="./tests/test_cluster_yamls/ray/default-ray-cluster.yaml",
167+
)
168+
mocker.patch("kubernetes.config.load_kube_config", return_value="ignore")
169+
170+
# Create a cluster configuration with appwrapper set to False
171+
cluster = create_cluster(mocker, 1, write_to_file=False)
172+
patch_cluster_with_dynamic_client(mocker, cluster, mock_dynamic_client)
173+
174+
# Mock listing RayCluster to simulate it doesn't exist
175+
mocker.patch(
176+
"kubernetes.client.CustomObjectsApi.list_namespaced_custom_object",
177+
return_value=get_obj_none("ray.io", "v1", "ns", "rayclusters"),
178+
)
179+
# Call the apply method
180+
cluster.apply()
181+
182+
# Assertions
183+
print("Cluster applied without AppWrapper.")
184+
185+
186+
def test_cluster_apply_without_appwrapper_write_to_file(mocker):
187+
# Mock Kubernetes client and dynamic client methods
188+
mocker.patch("kubernetes.client.ApisApi.get_api_versions")
189+
mocker.patch("kubernetes.config.load_kube_config", return_value="ignore")
190+
mocker.patch(
191+
"codeflare_sdk.ray.cluster.cluster._check_aw_exists",
192+
return_value=True,
193+
)
194+
mock_dynamic_client = mocker.Mock()
195+
mocker.patch("codeflare_sdk.ray.cluster.cluster.Cluster._throw_for_no_raycluster")
196+
mocker.patch(
197+
"kubernetes.dynamic.DynamicClient.resources", new_callable=mocker.PropertyMock
198+
)
199+
mocker.patch(
200+
"codeflare_sdk.ray.cluster.cluster.Cluster.create_resource",
201+
return_value="./tests/test_cluster_yamls/ray/default-ray-cluster.yaml",
202+
)
203+
mocker.patch("kubernetes.config.load_kube_config", return_value="ignore")
204+
205+
# Create a cluster configuration with appwrapper set to False
206+
cluster = create_cluster(mocker, 1, write_to_file=True)
207+
patch_cluster_with_dynamic_client(mocker, cluster, mock_dynamic_client)
208+
cluster.config.appwrapper = False
209+
210+
# Mock listing RayCluster to simulate it doesn't exist
211+
mocker.patch(
212+
"kubernetes.client.CustomObjectsApi.list_namespaced_custom_object",
213+
return_value=get_obj_none("ray.io", "v1", "ns", "rayclusters"),
214+
)
215+
# Call the apply method
216+
cluster.apply()
217+
218+
# Assertions
219+
print("Cluster applied without AppWrapper.")
220+
221+
152222
def test_cluster_apply_without_appwrapper(mocker):
153223
# Mock Kubernetes client and dynamic client methods
154224
mocker.patch("kubernetes.client.ApisApi.get_api_versions")

0 commit comments

Comments
 (0)