Skip to content

Commit 1465c20

Browse files
committed
test: add volumes/volume mounts tests
1 parent 625b209 commit 1465c20

File tree

4 files changed

+118
-1
lines changed

4 files changed

+118
-1
lines changed

src/codeflare_sdk/common/utils/unit_test_support.py

+42
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ def create_cluster_all_config_params(mocker, cluster_name, is_appwrapper) -> Clu
389389
"kubernetes.client.CustomObjectsApi.list_namespaced_custom_object",
390390
return_value=get_local_queue("kueue.x-k8s.io", "v1beta1", "ns", "localqueues"),
391391
)
392+
volumes, volume_mounts = get_example_extended_storage_opts()
392393

393394
config = ClusterConfiguration(
394395
name=cluster_name,
@@ -414,5 +415,46 @@ def create_cluster_all_config_params(mocker, cluster_name, is_appwrapper) -> Clu
414415
extended_resource_mapping={"example.com/gpu": "GPU", "intel.com/gpu": "TPU"},
415416
overwrite_default_resource_mapping=True,
416417
local_queue="local-queue-default",
418+
volumes=volumes,
419+
volume_mounts=volume_mounts,
417420
)
418421
return Cluster(config)
422+
423+
424+
def get_example_extended_storage_opts():
425+
from kubernetes.client import (
426+
V1Volume,
427+
V1VolumeMount,
428+
V1EmptyDirVolumeSource,
429+
V1ConfigMapVolumeSource,
430+
V1KeyToPath,
431+
V1SecretVolumeSource,
432+
)
433+
434+
volume_mounts = [
435+
V1VolumeMount(mount_path="/home/ray/test1", name="test"),
436+
V1VolumeMount(
437+
mount_path="/home/ray/test2",
438+
name="test2",
439+
),
440+
V1VolumeMount(
441+
mount_path="/home/ray/test2",
442+
name="test3",
443+
),
444+
]
445+
446+
volumes = [
447+
V1Volume(
448+
name="test",
449+
empty_dir=V1EmptyDirVolumeSource(size_limit="500Gi"),
450+
),
451+
V1Volume(
452+
name="test2",
453+
config_map=V1ConfigMapVolumeSource(
454+
name="config-map-test",
455+
items=[V1KeyToPath(key="test", path="/home/ray/test2/data.txt")],
456+
),
457+
),
458+
V1Volume(name="test3", secret=V1SecretVolumeSource(secret_name="test-secret")),
459+
]
460+
return volumes, volume_mounts

src/codeflare_sdk/ray/cluster/test_config.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
from codeflare_sdk.common.utils.unit_test_support import (
1616
createClusterWrongType,
17-
get_local_queue,
17+
get_example_extended_storage_opts,
1818
create_cluster_all_config_params,
1919
)
2020
from codeflare_sdk.ray.cluster.cluster import ClusterConfiguration, Cluster
@@ -61,6 +61,7 @@ def test_config_creation_all_parameters(mocker):
6161
expected_extended_resource_mapping = DEFAULT_RESOURCE_MAPPING
6262
expected_extended_resource_mapping.update({"example.com/gpu": "GPU"})
6363
expected_extended_resource_mapping["intel.com/gpu"] = "TPU"
64+
volumes, volume_mounts = get_example_extended_storage_opts()
6465

6566
cluster = create_cluster_all_config_params(mocker, "test-all-params", False)
6667
assert cluster.config.name == "test-all-params" and cluster.config.namespace == "ns"
@@ -90,6 +91,8 @@ def test_config_creation_all_parameters(mocker):
9091
)
9192
assert cluster.config.overwrite_default_resource_mapping == True
9293
assert cluster.config.local_queue == "local-queue-default"
94+
assert cluster.config.volumes == volumes
95+
assert cluster.config.volume_mounts == volume_mounts
9396

9497
assert filecmp.cmp(
9598
f"{aw_dir}test-all-params.yaml",

tests/test_cluster_yamls/appwrapper/unit-test-all-params.yaml

+36
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ spec:
7676
memory: 12G
7777
nvidia.com/gpu: 1
7878
volumeMounts:
79+
- mountPath: /home/ray/test1
80+
name: test
81+
- mountPath: /home/ray/test2
82+
name: test2
83+
- mountPath: /home/ray/test2
84+
name: test3
7985
- mountPath: /etc/pki/tls/certs/odh-trusted-ca-bundle.crt
8086
name: odh-trusted-ca-cert
8187
subPath: odh-trusted-ca-bundle.crt
@@ -92,6 +98,18 @@ spec:
9298
- name: secret1
9399
- name: secret2
94100
volumes:
101+
- emptyDir:
102+
sizeLimit: 500Gi
103+
name: test
104+
- configMap:
105+
items:
106+
- key: test
107+
path: /home/ray/test2/data.txt
108+
name: config-map-test
109+
name: test2
110+
- name: test3
111+
secret:
112+
secretName: test-secret
95113
- configMap:
96114
items:
97115
- key: ca-bundle.crt
@@ -144,6 +162,12 @@ spec:
144162
memory: 12G
145163
nvidia.com/gpu: 1
146164
volumeMounts:
165+
- mountPath: /home/ray/test1
166+
name: test
167+
- mountPath: /home/ray/test2
168+
name: test2
169+
- mountPath: /home/ray/test2
170+
name: test3
147171
- mountPath: /etc/pki/tls/certs/odh-trusted-ca-bundle.crt
148172
name: odh-trusted-ca-cert
149173
subPath: odh-trusted-ca-bundle.crt
@@ -160,6 +184,18 @@ spec:
160184
- name: secret1
161185
- name: secret2
162186
volumes:
187+
- emptyDir:
188+
sizeLimit: 500Gi
189+
name: test
190+
- configMap:
191+
items:
192+
- key: test
193+
path: /home/ray/test2/data.txt
194+
name: config-map-test
195+
name: test2
196+
- name: test3
197+
secret:
198+
secretName: test-secret
163199
- configMap:
164200
items:
165201
- key: ca-bundle.crt

tests/test_cluster_yamls/ray/unit-test-all-params.yaml

+36
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ spec:
6767
memory: 12G
6868
nvidia.com/gpu: 1
6969
volumeMounts:
70+
- mountPath: /home/ray/test1
71+
name: test
72+
- mountPath: /home/ray/test2
73+
name: test2
74+
- mountPath: /home/ray/test2
75+
name: test3
7076
- mountPath: /etc/pki/tls/certs/odh-trusted-ca-bundle.crt
7177
name: odh-trusted-ca-cert
7278
subPath: odh-trusted-ca-bundle.crt
@@ -83,6 +89,18 @@ spec:
8389
- name: secret1
8490
- name: secret2
8591
volumes:
92+
- emptyDir:
93+
sizeLimit: 500Gi
94+
name: test
95+
- configMap:
96+
items:
97+
- key: test
98+
path: /home/ray/test2/data.txt
99+
name: config-map-test
100+
name: test2
101+
- name: test3
102+
secret:
103+
secretName: test-secret
86104
- configMap:
87105
items:
88106
- key: ca-bundle.crt
@@ -135,6 +153,12 @@ spec:
135153
memory: 12G
136154
nvidia.com/gpu: 1
137155
volumeMounts:
156+
- mountPath: /home/ray/test1
157+
name: test
158+
- mountPath: /home/ray/test2
159+
name: test2
160+
- mountPath: /home/ray/test2
161+
name: test3
138162
- mountPath: /etc/pki/tls/certs/odh-trusted-ca-bundle.crt
139163
name: odh-trusted-ca-cert
140164
subPath: odh-trusted-ca-bundle.crt
@@ -151,6 +175,18 @@ spec:
151175
- name: secret1
152176
- name: secret2
153177
volumes:
178+
- emptyDir:
179+
sizeLimit: 500Gi
180+
name: test
181+
- configMap:
182+
items:
183+
- key: test
184+
path: /home/ray/test2/data.txt
185+
name: config-map-test
186+
name: test2
187+
- name: test3
188+
secret:
189+
secretName: test-secret
154190
- configMap:
155191
items:
156192
- key: ca-bundle.crt

0 commit comments

Comments
 (0)