Skip to content

Commit 95078d5

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

File tree

3 files changed

+211
-9
lines changed

3 files changed

+211
-9
lines changed

tests/test-case-custom-image.yaml

+156
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
apiVersion: ray.io/v1
2+
kind: RayCluster
3+
metadata:
4+
annotations:
5+
app.kubernetes.io/managed-by: test-prefix
6+
labels:
7+
controller-tools.k8s.io: '1.0'
8+
kueue.x-k8s.io/queue-name: local-queue-default
9+
testlabel: test
10+
testlabel2: test
11+
name: unit-test-cluster-custom-image
12+
namespace: ns
13+
spec:
14+
autoscalerOptions:
15+
idleTimeoutSeconds: 60
16+
imagePullPolicy: Always
17+
resources:
18+
limits:
19+
cpu: 500m
20+
memory: 512Mi
21+
requests:
22+
cpu: 500m
23+
memory: 512Mi
24+
upscalingMode: Default
25+
enableInTreeAutoscaling: false
26+
headGroupSpec:
27+
enableIngress: false
28+
rayStartParams:
29+
block: 'true'
30+
dashboard-host: 0.0.0.0
31+
num-gpus: '0'
32+
resources: '"{}"'
33+
serviceType: ClusterIP
34+
template:
35+
spec:
36+
containers:
37+
- image: quay.io/project-codeflare/ray:2.20.0-py39-cu118
38+
imagePullPolicy: Always
39+
lifecycle:
40+
preStop:
41+
exec:
42+
command:
43+
- /bin/sh
44+
- -c
45+
- ray stop
46+
name: ray-head
47+
ports:
48+
- containerPort: 6379
49+
name: gcs
50+
- containerPort: 8265
51+
name: dashboard
52+
- containerPort: 10001
53+
name: client
54+
resources:
55+
limits:
56+
cpu: 2
57+
memory: 8G
58+
requests:
59+
cpu: 2
60+
memory: 8G
61+
volumeMounts:
62+
- mountPath: /etc/pki/tls/certs/odh-trusted-ca-bundle.crt
63+
name: odh-trusted-ca-cert
64+
subPath: odh-trusted-ca-bundle.crt
65+
- mountPath: /etc/ssl/certs/odh-trusted-ca-bundle.crt
66+
name: odh-trusted-ca-cert
67+
subPath: odh-trusted-ca-bundle.crt
68+
- mountPath: /etc/pki/tls/certs/odh-ca-bundle.crt
69+
name: odh-ca-cert
70+
subPath: odh-ca-bundle.crt
71+
- mountPath: /etc/ssl/certs/odh-ca-bundle.crt
72+
name: odh-ca-cert
73+
subPath: odh-ca-bundle.crt
74+
imagePullSecrets:
75+
- name: unit-test-pull-secret
76+
volumes:
77+
- configMap:
78+
items:
79+
- key: ca-bundle.crt
80+
path: odh-trusted-ca-bundle.crt
81+
name: odh-trusted-ca-bundle
82+
optional: true
83+
name: odh-trusted-ca-cert
84+
- configMap:
85+
items:
86+
- key: odh-ca-bundle.crt
87+
path: odh-ca-bundle.crt
88+
name: odh-trusted-ca-bundle
89+
optional: true
90+
name: odh-ca-cert
91+
rayVersion: 2.23.0
92+
workerGroupSpecs:
93+
- groupName: small-group-unit-test-cluster-custom-image
94+
maxReplicas: 2
95+
minReplicas: 2
96+
rayStartParams:
97+
block: 'true'
98+
num-gpus: '7'
99+
resources: '"{}"'
100+
replicas: 2
101+
template:
102+
metadata:
103+
annotations:
104+
key: value
105+
labels:
106+
key: value
107+
spec:
108+
containers:
109+
- image: quay.io/project-codeflare/ray:2.20.0-py39-cu118
110+
lifecycle:
111+
preStop:
112+
exec:
113+
command:
114+
- /bin/sh
115+
- -c
116+
- ray stop
117+
name: machine-learning
118+
resources:
119+
limits:
120+
cpu: 4
121+
memory: 6G
122+
nvidia.com/gpu: 7
123+
requests:
124+
cpu: 3
125+
memory: 5G
126+
nvidia.com/gpu: 7
127+
volumeMounts:
128+
- mountPath: /etc/pki/tls/certs/odh-trusted-ca-bundle.crt
129+
name: odh-trusted-ca-cert
130+
subPath: odh-trusted-ca-bundle.crt
131+
- mountPath: /etc/ssl/certs/odh-trusted-ca-bundle.crt
132+
name: odh-trusted-ca-cert
133+
subPath: odh-trusted-ca-bundle.crt
134+
- mountPath: /etc/pki/tls/certs/odh-ca-bundle.crt
135+
name: odh-ca-cert
136+
subPath: odh-ca-bundle.crt
137+
- mountPath: /etc/ssl/certs/odh-ca-bundle.crt
138+
name: odh-ca-cert
139+
subPath: odh-ca-bundle.crt
140+
imagePullSecrets:
141+
- name: unit-test-pull-secret
142+
volumes:
143+
- configMap:
144+
items:
145+
- key: ca-bundle.crt
146+
path: odh-trusted-ca-bundle.crt
147+
name: odh-trusted-ca-bundle
148+
optional: true
149+
name: odh-trusted-ca-cert
150+
- configMap:
151+
items:
152+
- key: odh-ca-bundle.crt
153+
path: odh-ca-bundle.crt
154+
name: odh-trusted-ca-bundle
155+
optional: true
156+
name: odh-ca-cert

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)