Skip to content

Commit 4129fa4

Browse files
author
Shilpa Chugh
committed
Add unit tests for RHOAI ray image
1 parent 9c1e65d commit 4129fa4

File tree

2 files changed

+55
-9
lines changed

2 files changed

+55
-9
lines changed

tests/unit_test.py

+55-8
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,6 @@ def test_config_creation():
262262
assert config.worker_cpu_requests == 3 and config.worker_cpu_limits == 4
263263
assert config.worker_memory_requests == "5G" and config.worker_memory_limits == "6G"
264264
assert config.worker_extended_resource_requests == {"nvidia.com/gpu": 7}
265-
assert config.image == "quay.io/rhoai/ray:2.23.0-py39-cu121"
266265
assert config.template == f"{parent}/src/codeflare_sdk/templates/base-template.yaml"
267266
assert config.machine_types == ["cpu.small", "gpu.large"]
268267
assert config.image_pull_secrets == ["unit-test-pull-secret"]
@@ -415,7 +414,6 @@ def test_cluster_creation_no_mcad_local_queue(mocker):
415414
worker_extended_resource_requests={"nvidia.com/gpu": 7},
416415
machine_types=["cpu.small", "gpu.large"],
417416
image_pull_secrets=["unit-test-pull-secret"],
418-
image="quay.io/rhoai/ray:2.23.0-py39-cu121",
419417
write_to_file=True,
420418
appwrapper=False,
421419
local_queue="local-queue-default",
@@ -443,7 +441,6 @@ def test_default_cluster_creation(mocker):
443441
)
444442
default_config = ClusterConfiguration(
445443
name="unit-test-default-cluster",
446-
image="quay.io/rhoai/ray:2.23.0-py39-cu121",
447444
appwrapper=True,
448445
)
449446
cluster = Cluster(default_config)
@@ -459,6 +456,61 @@ def test_default_cluster_creation(mocker):
459456
assert cluster.config.namespace == "opendatahub"
460457

461458

459+
def test_cluster_creation_with_custom_image(mocker):
460+
# With written resources
461+
# Create Ray Cluster with local queue specified
462+
mocker.patch("kubernetes.client.ApisApi.get_api_versions")
463+
mocker.patch(
464+
"kubernetes.client.CustomObjectsApi.get_cluster_custom_object",
465+
return_value={"spec": {"domain": "apps.cluster.awsroute.org"}},
466+
)
467+
mocker.patch(
468+
"kubernetes.client.CustomObjectsApi.list_namespaced_custom_object",
469+
return_value=get_local_queue("kueue.x-k8s.io", "v1beta1", "ns", "localqueues"),
470+
)
471+
mocker.patch("os.environ.get", return_value="test-prefix")
472+
config = createClusterConfig()
473+
config.name = "unit-test-cluster-custom-image"
474+
config.appwrapper = False
475+
config.image = "quay.io/project-codeflare/ray:2.20.0-py39-cu118"
476+
config.local_queue = "local-queue-default"
477+
config.labels = {"testlabel": "test", "testlabel2": "test"}
478+
cluster = Cluster(config)
479+
assert cluster.app_wrapper_yaml == f"{aw_dir}unit-test-cluster-custom-image.yaml"
480+
assert cluster.app_wrapper_name == "unit-test-cluster-custom-image"
481+
assert filecmp.cmp(
482+
f"{aw_dir}unit-test-cluster-custom-image.yaml",
483+
f"{parent}/tests/test-case-custom-image.yaml",
484+
shallow=True,
485+
)
486+
# With resources loaded in memory
487+
config = ClusterConfiguration(
488+
name="unit-test-cluster-custom-image",
489+
namespace="ns",
490+
num_workers=2,
491+
worker_cpu_requests=3,
492+
worker_cpu_limits=4,
493+
worker_memory_requests=5,
494+
worker_memory_limits=6,
495+
worker_extended_resource_requests={"nvidia.com/gpu": 7},
496+
machine_types=["cpu.small", "gpu.large"],
497+
image_pull_secrets=["unit-test-pull-secret"],
498+
image="quay.io/project-codeflare/ray:2.20.0-py39-cu118",
499+
write_to_file=True,
500+
appwrapper=False,
501+
local_queue="local-queue-default",
502+
labels={"testlabel": "test", "testlabel2": "test"},
503+
)
504+
cluster = Cluster(config)
505+
assert cluster.app_wrapper_yaml == f"{aw_dir}unit-test-cluster-custom-image.yaml"
506+
assert cluster.app_wrapper_name == "unit-test-cluster-custom-image"
507+
assert filecmp.cmp(
508+
f"{aw_dir}unit-test-cluster-custom-image.yaml",
509+
f"{parent}/tests/test-case-custom-image.yaml",
510+
shallow=True,
511+
)
512+
513+
462514
def test_gen_names_with_name(mocker):
463515
mocker.patch.object(
464516
uuid, "uuid4", return_value=uuid.UUID("00000000-0000-0000-0000-000000000001")
@@ -792,7 +844,6 @@ def test_ray_job_wrapping(mocker):
792844
return_value=get_local_queue("kueue.x-k8s.io", "v1beta1", "ns", "localqueues"),
793845
)
794846
cluster = cluster = createClusterWithConfig(mocker)
795-
cluster.config.image = "quay.io/rhoai/ray:2.23.0-py39-cu121"
796847
mocker.patch(
797848
"ray.job_submission.JobSubmissionClient._check_connection_and_version_with_url",
798849
return_value="None",
@@ -910,7 +961,6 @@ def test_ray_details(mocker, capsys):
910961
ClusterConfiguration(
911962
name="raytest2",
912963
namespace="ns",
913-
image="quay.io/rhoai/ray:2.23.0-py39-cu121",
914964
write_to_file=True,
915965
appwrapper=True,
916966
local_queue="local_default_queue",
@@ -2313,7 +2363,6 @@ def test_cluster_status(mocker):
23132363
ClusterConfiguration(
23142364
name="test",
23152365
namespace="ns",
2316-
image="quay.io/rhoai/ray:2.23.0-py39-cu121",
23172366
write_to_file=True,
23182367
appwrapper=True,
23192368
local_queue="local_default_queue",
@@ -2408,7 +2457,6 @@ def test_wait_ready(mocker, capsys):
24082457
ClusterConfiguration(
24092458
name="test",
24102459
namespace="ns",
2411-
image="quay.io/rhoai/ray:2.23.0-py39-cu121",
24122460
write_to_file=True,
24132461
appwrapper=True,
24142462
local_queue="local-queue-default",
@@ -2635,7 +2683,6 @@ def throw_if_getting_raycluster(group, version, namespace, plural):
26352683
cluster = Cluster(
26362684
ClusterConfiguration(
26372685
"test_cluster",
2638-
image="quay.io/rhoai/ray:2.23.0-py39-cu121",
26392686
write_to_file=False,
26402687
)
26412688
)

tests/unit_test_support.py

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ def createClusterConfig():
1717
appwrapper=True,
1818
machine_types=["cpu.small", "gpu.large"],
1919
image_pull_secrets=["unit-test-pull-secret"],
20-
image="quay.io/rhoai/ray:2.23.0-py39-cu121",
2120
write_to_file=True,
2221
)
2322
return config

0 commit comments

Comments
 (0)