Skip to content

Commit c8c863b

Browse files
committed
Created unit tests for persistent_volumes
1 parent 87dd88a commit c8c863b

File tree

2 files changed

+235
-0
lines changed

2 files changed

+235
-0
lines changed

tests/test-case-pvc.yaml

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
---
2+
apiVersion: ray.io/v1
3+
kind: RayCluster
4+
metadata:
5+
labels:
6+
controller-tools.k8s.io: '1.0'
7+
kueue.x-k8s.io/queue-name: local-queue-default
8+
name: unit-test-cluster-pvc
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/project-codeflare/ray:latest-py39-cu118
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+
- mountPath: /home/ray/results
73+
name: test
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+
- name: test
92+
persistentVolumeClaim:
93+
claimName: testClaim
94+
rayVersion: 2.7.0
95+
workerGroupSpecs:
96+
- groupName: small-group-unit-test-cluster-pvc
97+
maxReplicas: 2
98+
minReplicas: 2
99+
rayStartParams:
100+
block: 'true'
101+
num-gpus: '7'
102+
replicas: 2
103+
template:
104+
metadata:
105+
annotations:
106+
key: value
107+
labels:
108+
key: value
109+
spec:
110+
containers:
111+
- image: quay.io/project-codeflare/ray:latest-py39-cu118
112+
lifecycle:
113+
preStop:
114+
exec:
115+
command:
116+
- /bin/sh
117+
- -c
118+
- ray stop
119+
name: machine-learning
120+
resources:
121+
limits:
122+
cpu: 4
123+
memory: 6G
124+
nvidia.com/gpu: 7
125+
requests:
126+
cpu: 3
127+
memory: 5G
128+
nvidia.com/gpu: 7
129+
volumeMounts:
130+
- mountPath: /etc/pki/tls/certs/odh-trusted-ca-bundle.crt
131+
name: odh-trusted-ca-cert
132+
subPath: odh-trusted-ca-bundle.crt
133+
- mountPath: /etc/ssl/certs/odh-trusted-ca-bundle.crt
134+
name: odh-trusted-ca-cert
135+
subPath: odh-trusted-ca-bundle.crt
136+
- mountPath: /etc/pki/tls/certs/odh-ca-bundle.crt
137+
name: odh-ca-cert
138+
subPath: odh-ca-bundle.crt
139+
- mountPath: /etc/ssl/certs/odh-ca-bundle.crt
140+
name: odh-ca-cert
141+
subPath: odh-ca-bundle.crt
142+
- mountPath: /home/ray/results
143+
name: test
144+
imagePullSecrets:
145+
- name: unit-test-pull-secret
146+
volumes:
147+
- configMap:
148+
items:
149+
- key: ca-bundle.crt
150+
path: odh-trusted-ca-bundle.crt
151+
name: odh-trusted-ca-bundle
152+
optional: true
153+
name: odh-trusted-ca-cert
154+
- configMap:
155+
items:
156+
- key: odh-ca-bundle.crt
157+
path: odh-ca-bundle.crt
158+
name: odh-trusted-ca-bundle
159+
optional: true
160+
name: odh-ca-cert
161+
- name: test
162+
persistentVolumeClaim:
163+
claimName: testClaim

tests/unit_test.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
from codeflare_sdk.utils.generate_yaml import (
7474
gen_names,
7575
is_openshift_cluster,
76+
validate_persistent_volumes,
7677
read_template,
7778
write_components,
7879
)
@@ -545,6 +546,77 @@ def test_cluster_up_down(mocker):
545546
cluster.down()
546547

547548

549+
def test_persistent_volumes_validation(mocker):
550+
persistent_volumes = [
551+
{"name": "test", "mountPath": "/home/ray/results", "claimName": "testClaim"}
552+
]
553+
assert validate_persistent_volumes(persistent_volumes) == True
554+
555+
persistent_volumes = "not a list :O"
556+
try:
557+
validate_persistent_volumes(persistent_volumes)
558+
except Exception as e:
559+
assert type(e) == ValueError
560+
assert str(e) == "persistent_volumes must be a list"
561+
562+
persistent_volumes = [
563+
{"name": 21, "mountPath": "/home/ray/results", "claimName": "testClaim"}
564+
]
565+
try:
566+
validate_persistent_volumes(persistent_volumes)
567+
except Exception as e:
568+
assert type(e) == ValueError
569+
assert str(e) == "name must be a string"
570+
571+
persistent_volumes = [{"mountPath": "/home/ray/results", "claimName": "testClaim"}]
572+
try:
573+
validate_persistent_volumes(persistent_volumes)
574+
except Exception as e:
575+
assert type(e) == ValueError
576+
assert str(e) == "Missing keys in persistent volume: {'name'}"
577+
578+
579+
def test_cluster_persistent_volumes(mocker):
580+
mocker.patch("codeflare_sdk.cluster.cluster.Cluster._throw_for_no_raycluster")
581+
mocker.patch("kubernetes.config.load_kube_config", return_value="ignore")
582+
mocker.patch("kubernetes.client.ApisApi.get_api_versions")
583+
mocker.patch(
584+
"kubernetes.client.CustomObjectsApi.list_namespaced_custom_object",
585+
return_value=get_local_queue("kueue.x-k8s.io", "v1beta1", "ns", "localqueues"),
586+
)
587+
mocker.patch(
588+
"kubernetes.client.CustomObjectsApi.create_namespaced_custom_object",
589+
side_effect=arg_check_apply_effect,
590+
)
591+
mocker.patch(
592+
"kubernetes.client.CustomObjectsApi.delete_namespaced_custom_object",
593+
side_effect=arg_check_del_effect,
594+
)
595+
mocker.patch(
596+
"kubernetes.client.CoreV1Api.create_namespaced_secret",
597+
)
598+
mocker.patch(
599+
"kubernetes.client.CoreV1Api.delete_namespaced_secret",
600+
)
601+
mocker.patch(
602+
"kubernetes.client.CustomObjectsApi.list_cluster_custom_object",
603+
return_value={"items": []},
604+
)
605+
config = createClusterConfig()
606+
config.name = "unit-test-cluster-pvc"
607+
config.appwrapper = False
608+
config.persistent_volumes = [
609+
{"name": "test", "mountPath": "/home/ray/results", "claimName": "testClaim"}
610+
]
611+
config.write_to_file = True
612+
cluster = Cluster(config)
613+
614+
assert cluster.config.name == "unit-test-cluster-pvc"
615+
assert cluster.config.persistent_volumes == [
616+
{"name": "test", "mountPath": "/home/ray/results", "claimName": "testClaim"}
617+
]
618+
619+
548620
def test_cluster_up_down_no_mcad(mocker):
549621
mocker.patch("codeflare_sdk.cluster.cluster.Cluster._throw_for_no_raycluster")
550622
mocker.patch("kubernetes.config.load_kube_config", return_value="ignore")

0 commit comments

Comments
 (0)