25
25
arg_check_apply_effect ,
26
26
get_local_queue ,
27
27
createClusterConfig ,
28
- route_list_retrieval ,
29
28
get_ray_obj ,
30
- get_aw_obj ,
31
- get_named_aw ,
32
29
get_obj_none ,
33
30
get_ray_obj_with_status ,
34
31
get_aw_obj_with_status ,
35
32
)
36
- from codeflare_sdk .ray .cluster .generate_yaml import (
37
- is_openshift_cluster ,
38
- is_kind_cluster ,
39
- )
33
+ from codeflare_sdk .ray .cluster .cluster import _is_openshift_cluster
40
34
from pathlib import Path
41
35
from unittest .mock import MagicMock
42
36
from kubernetes import client
37
+ import yaml
38
+ import filecmp
43
39
import os
44
40
45
41
parent = Path (__file__ ).resolve ().parents [4 ] # project directory
@@ -205,7 +201,7 @@ def test_local_client_url(mocker):
205
201
return_value = "rayclient-unit-test-cluster-localinter-ns.apps.cluster.awsroute.org" ,
206
202
)
207
203
mocker .patch (
208
- "codeflare_sdk.ray.cluster.cluster.Cluster.create_app_wrapper " ,
204
+ "codeflare_sdk.ray.cluster.cluster.Cluster.create_resource " ,
209
205
return_value = "unit-test-cluster-localinter.yaml" ,
210
206
)
211
207
@@ -225,120 +221,51 @@ def test_local_client_url(mocker):
225
221
"""
226
222
227
223
228
- def test_get_cluster_openshift (mocker ):
224
+ def test_get_cluster_no_appwrapper (mocker ):
225
+ """
226
+ This test uses the "test all params" unit test file as a comparison
227
+ """
228
+ mocker .patch ("kubernetes.client.ApisApi.get_api_versions" )
229
229
mocker .patch ("kubernetes.config.load_kube_config" , return_value = "ignore" )
230
- # Mock the client.ApisApi function to return a mock object
231
- mock_api = MagicMock ()
232
- mock_api .get_api_versions .return_value .groups = [
233
- MagicMock (versions = [MagicMock (group_version = "route.openshift.io/v1" )])
234
- ]
235
- mocker .patch ("kubernetes.client.ApisApi" , return_value = mock_api )
236
230
mocker .patch (
237
- "codeflare_sdk.common.kueue.kueue.local_queue_exists " ,
238
- return_value = "true" ,
231
+ "codeflare_sdk.ray.cluster.cluster._check_aw_exists " ,
232
+ return_value = False ,
239
233
)
240
234
241
- assert is_openshift_cluster ()
242
-
243
- def custom_side_effect (group , version , namespace , plural , ** kwargs ):
244
- if plural == "routes" :
245
- return route_list_retrieval ("route.openshift.io" , "v1" , "ns" , "routes" )
246
- elif plural == "rayclusters" :
247
- return get_ray_obj ("ray.io" , "v1" , "ns" , "rayclusters" )
248
- elif plural == "appwrappers" :
249
- return get_aw_obj ("workload.codeflare.dev" , "v1beta2" , "ns" , "appwrappers" )
250
- elif plural == "localqueues" :
251
- return get_local_queue ("kueue.x-k8s.io" , "v1beta1" , "ns" , "localqueues" )
252
-
253
- mocker .patch (
254
- "kubernetes.client.CustomObjectsApi.list_namespaced_custom_object" , get_aw_obj
255
- )
256
-
257
- mocker .patch (
258
- "kubernetes.client.CustomObjectsApi.list_namespaced_custom_object" ,
259
- side_effect = custom_side_effect ,
260
- )
261
- mocker .patch (
262
- "kubernetes.client.CustomObjectsApi.get_namespaced_custom_object" ,
263
- return_value = get_named_aw ,
264
- )
265
- mocker .patch (
266
- "kubernetes.client.CustomObjectsApi.get_namespaced_custom_object" ,
267
- side_effect = route_list_retrieval ("route.openshift.io" , "v1" , "ns" , "routes" )[
268
- "items"
269
- ],
270
- )
271
- mocker .patch (
272
- "codeflare_sdk.common.kueue.kueue.local_queue_exists" ,
273
- return_value = "true" ,
274
- )
275
-
276
- cluster = get_cluster (
277
- "test-cluster-a" , "ns"
278
- ) # see tests/test_cluster_yamls/support_clusters
279
- cluster_config = cluster .config
280
-
281
- assert cluster_config .name == "test-cluster-a" and cluster_config .namespace == "ns"
282
- assert cluster_config .head_cpu_requests == 2 and cluster_config .head_cpu_limits == 2
283
- assert (
284
- cluster_config .head_memory_requests == "8G"
285
- and cluster_config .head_memory_limits == "8G"
286
- )
287
- assert (
288
- cluster_config .worker_cpu_requests == 1
289
- and cluster_config .worker_cpu_limits == 1
290
- )
291
- assert (
292
- cluster_config .worker_memory_requests == "2G"
293
- and cluster_config .worker_memory_limits == "2G"
294
- )
295
- assert cluster_config .num_workers == 1
296
- assert cluster_config .write_to_file == False
297
- assert cluster_config .local_queue == "local_default_queue"
235
+ with open (f"{ expected_clusters_dir } /ray/unit-test-all-params.yaml" ) as f :
236
+ expected_rc = yaml .load (f , Loader = yaml .FullLoader )
237
+ mocker .patch (
238
+ "kubernetes.client.CustomObjectsApi.get_namespaced_custom_object" ,
239
+ return_value = expected_rc ,
240
+ )
241
+ get_cluster ("test-all-params" , "ns" , write_to_file = True )
242
+ assert filecmp .cmp (
243
+ f"{ aw_dir } test-all-params.yaml" ,
244
+ f"{ expected_clusters_dir } /ray/unit-test-all-params.yaml" ,
245
+ shallow = True ,
246
+ )
298
247
299
248
300
- def test_get_cluster (mocker ):
301
- # test get_cluster for Kind Clusters
249
+ def test_get_cluster_with_appwrapper (mocker ):
302
250
mocker .patch ("kubernetes.client.ApisApi.get_api_versions" )
303
251
mocker .patch ("kubernetes.config.load_kube_config" , return_value = "ignore" )
304
252
mocker .patch (
305
- "kubernetes.client.CustomObjectsApi.list_namespaced_custom_object" ,
306
- side_effect = get_ray_obj ,
307
- )
308
- mocker .patch (
309
- "kubernetes.client.CustomObjectsApi.get_namespaced_custom_object" ,
310
- side_effect = get_named_aw ,
311
- )
312
- mocker .patch (
313
- "kubernetes.client.NetworkingV1Api.list_namespaced_ingress" ,
314
- return_value = ingress_retrieval (cluster_name = "quicktest" , client_ing = True ),
315
- )
316
- mocker .patch (
317
- "codeflare_sdk.common.kueue.kueue.local_queue_exists" ,
318
- return_value = "true" ,
253
+ "codeflare_sdk.ray.cluster.cluster._check_aw_exists" ,
254
+ return_value = True ,
319
255
)
320
- cluster = get_cluster (
321
- "test-cluster-a"
322
- ) # see tests/test_cluster_yamls/support_clusters
323
- cluster_config = cluster .config
324
256
325
- assert cluster_config .name == "test-cluster-a" and cluster_config .namespace == "ns"
326
- assert cluster_config .head_cpu_requests == 2 and cluster_config .head_cpu_limits == 2
327
- assert (
328
- cluster_config .head_memory_requests == "8G"
329
- and cluster_config .head_memory_limits == "8G"
330
- )
331
- assert (
332
- cluster_config .worker_cpu_requests == 1
333
- and cluster_config .worker_cpu_limits == 1
334
- )
335
- assert (
336
- cluster_config .worker_memory_requests == "2G"
337
- and cluster_config .worker_memory_limits == "2G"
338
- )
339
- assert cluster_config .num_workers == 1
340
- assert cluster_config .write_to_file == False
341
- assert cluster_config .local_queue == "local_default_queue"
257
+ with open (f"{ expected_clusters_dir } /appwrapper/unit-test-all-params.yaml" ) as f :
258
+ expected_aw = yaml .load (f , Loader = yaml .FullLoader )
259
+ mocker .patch (
260
+ "kubernetes.client.CustomObjectsApi.get_namespaced_custom_object" ,
261
+ return_value = expected_aw ,
262
+ )
263
+ get_cluster ("aw-all-params" , "ns" , write_to_file = True )
264
+ assert filecmp .cmp (
265
+ f"{ aw_dir } aw-all-params.yaml" ,
266
+ f"{ expected_clusters_dir } /appwrapper/unit-test-all-params.yaml" ,
267
+ shallow = True ,
268
+ )
342
269
343
270
344
271
def test_wait_ready (mocker , capsys ):
@@ -356,10 +283,6 @@ def test_wait_ready(mocker, capsys):
356
283
mocker .patch (
357
284
"codeflare_sdk.ray.cluster.cluster._ray_cluster_status" , return_value = None
358
285
)
359
- mocker .patch (
360
- "codeflare_sdk.common.kueue.kueue.local_queue_exists" ,
361
- return_value = "true" ,
362
- )
363
286
mocker .patch .object (
364
287
client .CustomObjectsApi ,
365
288
"list_namespaced_custom_object" ,
@@ -381,7 +304,6 @@ def test_wait_ready(mocker, capsys):
381
304
namespace = "ns" ,
382
305
write_to_file = False ,
383
306
appwrapper = True ,
384
- local_queue = "local-queue-default" ,
385
307
)
386
308
)
387
309
try :
@@ -460,7 +382,7 @@ def test_list_queue_rayclusters(mocker, capsys):
460
382
]
461
383
mocker .patch ("kubernetes.client.ApisApi" , return_value = mock_api )
462
384
463
- assert is_openshift_cluster () == True
385
+ assert _is_openshift_cluster () == True
464
386
mocker .patch (
465
387
"kubernetes.client.CustomObjectsApi.list_namespaced_custom_object" ,
466
388
return_value = get_obj_none ("ray.io" , "v1" , "ns" , "rayclusters" ),
@@ -566,7 +488,7 @@ def test_map_to_ray_cluster(mocker):
566
488
mocker .patch ("kubernetes.config.load_kube_config" )
567
489
568
490
mocker .patch (
569
- "codeflare_sdk.ray.cluster.cluster.is_openshift_cluster " , return_value = True
491
+ "codeflare_sdk.ray.cluster.cluster._is_openshift_cluster " , return_value = True
570
492
)
571
493
572
494
mock_api_client = mocker .MagicMock (spec = client .ApiClient )
@@ -608,3 +530,9 @@ def custom_side_effect(group, version, namespace, plural, **kwargs):
608
530
609
531
assert result is not None
610
532
assert result .dashboard == rc_dashboard
533
+
534
+
535
+ # Make sure to always keep this function last
536
+ def test_cleanup ():
537
+ os .remove (f"{ aw_dir } test-all-params.yaml" )
538
+ os .remove (f"{ aw_dir } aw-all-params.yaml" )
0 commit comments