Skip to content

Commit 41b95ba

Browse files
committed
Added unit test for unmanaged Ray Cluster
1 parent 55d9856 commit 41b95ba

File tree

2 files changed

+176
-0
lines changed

2 files changed

+176
-0
lines changed

tests/test-case-no-kueue-no-aw.yaml

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

tests/unit_test.py

+23
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,28 @@ def test_cluster_creation(mocker):
285285
)
286286

287287

288+
def test_cluster_no_kueue_no_aw(mocker):
289+
mocker.patch("kubernetes.client.ApisApi.get_api_versions")
290+
mocker.patch(
291+
"kubernetes.client.CustomObjectsApi.get_cluster_custom_object",
292+
return_value={"spec": {"domain": "apps.cluster.awsroute.org"}},
293+
)
294+
mocker.patch("kubernetes.client.CustomObjectsApi.list_namespaced_custom_object")
295+
mocker.patch("os.environ.get", return_value="test-prefix")
296+
config = createClusterConfig()
297+
config.appwrapper = False
298+
config.name = "unit-test-no-kueue"
299+
config.write_to_file = True
300+
cluster = Cluster(config)
301+
assert cluster.app_wrapper_yaml == f"{aw_dir}unit-test-no-kueue.yaml"
302+
assert cluster.config.local_queue == None
303+
assert filecmp.cmp(
304+
f"{aw_dir}unit-test-no-kueue.yaml",
305+
f"{parent}/tests/test-case-no-kueue-no-aw.yaml",
306+
shallow=True,
307+
)
308+
309+
288310
def test_create_app_wrapper_raises_error_with_no_image():
289311
config = createClusterConfig()
290312
config.image = "" # Clear the image to test error handling
@@ -2799,6 +2821,7 @@ def test_rjc_list_jobs(ray_job_client, mocker):
27992821

28002822
# Make sure to always keep this function last
28012823
def test_cleanup():
2824+
os.remove(f"{aw_dir}unit-test-no-kueue.yaml")
28022825
os.remove(f"{aw_dir}unit-test-cluster.yaml")
28032826
os.remove(f"{aw_dir}test.yaml")
28042827
os.remove(f"{aw_dir}raytest2.yaml")

0 commit comments

Comments
 (0)