Skip to content

Commit 07700e9

Browse files
committed
Adding coverage for the case of an openshift cluster
1 parent c343953 commit 07700e9

File tree

3 files changed

+88
-1
lines changed

3 files changed

+88
-1
lines changed

.coveragerc

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[run]
2+
omit =
3+
src/**/test_*.py,,src/codeflare_sdk/common/utils/unit_test_support.py
4+
5+
[report]
6+
exclude_lines =
7+
pragma: no cover

src/codeflare_sdk/ray/cluster/cluster.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ def apply(self, force=False):
228228
print(f"AppWrapper: '{self.config.name}' has successfully been created")
229229
else:
230230
api_instance = crds.get(api_version="ray.io/v1", kind="RayCluster")
231-
self._component_resources_apply(namespace, api_instance, force)
231+
self._component_resources_apply(namespace, api_instance)
232232
print(
233233
f"Ray Cluster: '{self.config.name}' has successfully been applied"
234234
)

src/codeflare_sdk/ray/cluster/test_cluster.py

+80
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
get_ray_obj_with_status,
3131
get_aw_obj_with_status,
3232
patch_cluster_with_dynamic_client,
33+
route_list_retrieval,
3334
)
3435
from codeflare_sdk.ray.cluster.cluster import _is_openshift_cluster
3536
from pathlib import Path
@@ -148,6 +149,39 @@ def test_cluster_apply_with_file(mocker):
148149
cluster.down()
149150

150151

152+
def test_cluster_apply_without_appwrapper(mocker):
153+
# Mock Kubernetes client and dynamic client methods
154+
mocker.patch("kubernetes.client.ApisApi.get_api_versions")
155+
mocker.patch("kubernetes.config.load_kube_config", return_value="ignore")
156+
mock_dynamic_client = mocker.Mock()
157+
mocker.patch("codeflare_sdk.ray.cluster.cluster.Cluster._throw_for_no_raycluster")
158+
mocker.patch(
159+
"kubernetes.dynamic.DynamicClient.resources", new_callable=mocker.PropertyMock
160+
)
161+
mocker.patch(
162+
"codeflare_sdk.ray.cluster.cluster.Cluster.create_resource",
163+
return_value="./tests/test_cluster_yamls/ray/default-ray-cluster.yaml",
164+
)
165+
mocker.patch("kubernetes.config.load_kube_config", return_value="ignore")
166+
167+
# Create a cluster configuration with appwrapper set to False
168+
cluster = create_cluster(mocker, 1, write_to_file=False)
169+
cluster.config.appwrapper = None
170+
patch_cluster_with_dynamic_client(mocker, cluster, mock_dynamic_client)
171+
172+
# Mock listing RayCluster to simulate it doesn't exist
173+
mocker.patch(
174+
"kubernetes.client.CustomObjectsApi.list_namespaced_custom_object",
175+
return_value=get_obj_none("ray.io", "v1", "ns", "rayclusters"),
176+
)
177+
178+
# Call the apply method
179+
cluster.apply()
180+
181+
# Assertions
182+
print("Cluster applied without AppWrapper.")
183+
184+
151185
def test_cluster_up_down_no_mcad(mocker):
152186
mocker.patch("codeflare_sdk.ray.cluster.cluster.Cluster._throw_for_no_raycluster")
153187
mocker.patch("kubernetes.config.load_kube_config", return_value="ignore")
@@ -223,6 +257,52 @@ def test_cluster_uris(mocker):
223257
== "Dashboard not available yet, have you run cluster.up()?"
224258
)
225259

260+
mocker.patch(
261+
"codeflare_sdk.ray.cluster.cluster._is_openshift_cluster", return_value=True
262+
)
263+
mocker.patch(
264+
"kubernetes.client.CustomObjectsApi.list_namespaced_custom_object",
265+
return_value={
266+
"items": [
267+
{
268+
"metadata": {
269+
"name": "ray-dashboard-unit-test-cluster",
270+
},
271+
"spec": {
272+
"host": "ray-dashboard-unit-test-cluster-ns.apps.cluster.awsroute.org",
273+
"tls": {}, # Indicating HTTPS
274+
},
275+
}
276+
]
277+
},
278+
)
279+
cluster = create_cluster(mocker)
280+
assert (
281+
cluster.cluster_dashboard_uri()
282+
== "http://ray-dashboard-unit-test-cluster-ns.apps.cluster.awsroute.org"
283+
)
284+
mocker.patch(
285+
"kubernetes.client.CustomObjectsApi.list_namespaced_custom_object",
286+
return_value={
287+
"items": [
288+
{
289+
"metadata": {
290+
"name": "ray-dashboard-unit-test-cluster",
291+
},
292+
"spec": {
293+
"host": "ray-dashboard-unit-test-cluster-ns.apps.cluster.awsroute.org",
294+
"tls": {"termination": "passthrough"}, # Indicating HTTPS
295+
},
296+
}
297+
]
298+
},
299+
)
300+
cluster = create_cluster(mocker)
301+
assert (
302+
cluster.cluster_dashboard_uri()
303+
== "https://ray-dashboard-unit-test-cluster-ns.apps.cluster.awsroute.org"
304+
)
305+
226306

227307
def test_ray_job_wrapping(mocker):
228308
import ray

0 commit comments

Comments
 (0)