Skip to content

Commit 291fc83

Browse files
Add test coverage for custom ray image
1 parent 16ec9a0 commit 291fc83

File tree

5 files changed

+97
-8
lines changed

5 files changed

+97
-8
lines changed

tests/odh/mnist_ray_test.go

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ package odh
1919
import (
2020
"bytes"
2121
"fmt"
22+
"log"
23+
"os/exec"
2224
"testing"
2325
"time"
2426

@@ -33,19 +35,50 @@ import (
3335
)
3436

3537
func TestMnistRayCpu(t *testing.T) {
36-
mnistRay(t, 0)
38+
mnistDefaultRayImage(t, 0)
3739
}
3840

3941
func TestMnistRayGpu(t *testing.T) {
40-
mnistRay(t, 1)
42+
mnistDefaultRayImage(t, 1)
4143
}
4244

43-
func mnistRay(t *testing.T, numGpus int) {
45+
func TestMnistCustomRayImageCpu(t *testing.T) {
46+
mnistCustomRayImage(t, 0)
47+
}
48+
49+
func TestMnistCustomRayImageGpu(t *testing.T) {
50+
mnistCustomRayImage(t, 1)
51+
}
52+
53+
func mnistDefaultRayImage(t *testing.T, numGpus int) {
4454
test := With(t)
4555

4656
// Create a namespace
4757
namespace := test.NewTestNamespace()
4858

59+
// Get ray image
60+
rayImage := GetRayImage()
61+
62+
mnistRay(test, numGpus, namespace, rayImage)
63+
}
64+
65+
func mnistCustomRayImage(t *testing.T, numGpus int) {
66+
test := With(t)
67+
68+
// Create a namespace
69+
namespace := test.NewTestNamespace()
70+
71+
// Build and Push custom ray image
72+
image := "ray-torch"
73+
buildAndPushRayImage(test, namespace.Name, image)
74+
75+
// Get custom ray image
76+
rayImage := getCustomRayImage(test, namespace.Name, image)
77+
78+
mnistRay(test, numGpus, namespace, rayImage)
79+
}
80+
81+
func mnistRay(test Test, numGpus int, namespace *corev1.Namespace, rayImage string) {
4982
// Create Kueue resources
5083
resourceFlavor := CreateKueueResourceFlavor(test, v1beta1.ResourceFlavorSpec{})
5184
defer test.Client().Kueue().KueueV1beta1().ResourceFlavors().Delete(test.Ctx(), resourceFlavor.Name, metav1.DeleteOptions{})
@@ -103,7 +136,7 @@ func mnistRay(t *testing.T, numGpus int) {
103136
CreateUserRoleBindingWithClusterRole(test, userName, namespace.Name, "admin")
104137

105138
// Create Notebook CR
106-
createNotebook(test, namespace, userToken, config.Name, jupyterNotebookConfigMapFileName, numGpus)
139+
createNotebook(test, namespace, userToken, rayImage, config.Name, jupyterNotebookConfigMapFileName, numGpus)
107140

108141
// Gracefully cleanup Notebook
109142
defer func() {
@@ -221,3 +254,25 @@ func readMnistScriptTemplate(test Test, filePath string) []byte {
221254

222255
return ParseTemplate(test, template, props)
223256
}
257+
258+
func buildAndPushRayImage(test Test, namespace string, image string) {
259+
cmd := exec.Command("resources/custom_image.sh", namespace, image, "-c", "echo stdout; echo 1>&2 stderr")
260+
261+
stdoutStderr, err := cmd.CombinedOutput()
262+
if err != nil {
263+
log.Fatal("Error executing custom_image script :", err)
264+
}
265+
test.Expect(err).NotTo(HaveOccurred())
266+
267+
fmt.Printf("Logs of build and custom ray image . . .\n %s", stdoutStderr)
268+
}
269+
270+
func getCustomRayImage(test Test, namespace string, image string) string {
271+
tag := "latest"
272+
name := image + ":" + tag
273+
274+
imageStreamTag := GetImageStreamTag(test, namespace, name)
275+
imageReference := imageStreamTag.Image.DockerImageReference
276+
277+
return imageReference
278+
}

tests/odh/mnist_raytune_hpo_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,11 @@ func mnistRayTuneHpo(t *testing.T, numGpus int) {
103103
// Create role binding with Namespace specific admin cluster role
104104
CreateUserRoleBindingWithClusterRole(test, userName, namespace.Name, "admin")
105105

106+
// Get ray image
107+
rayImage := GetRayImage()
108+
106109
// Create Notebook CR
107-
createNotebook(test, namespace, userToken, config.Name, jupyterNotebookConfigMapFileName, numGpus)
110+
createNotebook(test, namespace, userToken, rayImage, config.Name, jupyterNotebookConfigMapFileName, numGpus)
108111

109112
// Gracefully cleanup Notebook
110113
defer func() {

tests/odh/notebook.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ type NotebookProps struct {
5151
S3DefaultRegion string
5252
}
5353

54-
func createNotebook(test Test, namespace *corev1.Namespace, notebookUserToken, jupyterNotebookConfigMapName, jupyterNotebookConfigMapFileName string, numGpus int) {
54+
func createNotebook(test Test, namespace *corev1.Namespace, notebookUserToken, rayImage string, jupyterNotebookConfigMapName, jupyterNotebookConfigMapFileName string, numGpus int) {
5555
// Create PVC for Notebook
5656
notebookPVC := CreatePersistentVolumeClaim(test, namespace.Name, "10Gi", corev1.ReadWriteOnce)
5757
s3BucketName, s3BucketNameExists := GetStorageBucketName()
@@ -73,7 +73,7 @@ func createNotebook(test Test, namespace *corev1.Namespace, notebookUserToken, j
7373
KubernetesUserBearerToken: notebookUserToken,
7474
Namespace: namespace.Name,
7575
OpenDataHubNamespace: GetOpenDataHubNamespace(test),
76-
RayImage: GetRayImage(),
76+
RayImage: rayImage,
7777
NotebookImage: GetNotebookImage(test),
7878
NotebookConfigMapName: jupyterNotebookConfigMapName,
7979
NotebookConfigMapFileName: jupyterNotebookConfigMapFileName,

tests/odh/ray_finetune_llm_deepspeed_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,11 @@ func rayFinetuneLlmDeepspeed(t *testing.T, numGpus int, modelName string, modelC
9999

100100
config := CreateConfigMap(test, namespace.Name, configMap)
101101

102+
// Get ray image
103+
rayImage := GetRayImage()
104+
102105
// Create Notebook CR
103-
createNotebook(test, namespace, userToken, config.Name, jupyterNotebookConfigMapFileName, numGpus)
106+
createNotebook(test, namespace, userToken, rayImage, config.Name, jupyterNotebookConfigMapFileName, numGpus)
104107

105108
// Gracefully cleanup Notebook
106109
defer func() {

tests/odh/resources/custom_image.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
3+
namespace=$1
4+
image=$2
5+
6+
echo "switch to current project . . ."
7+
oc project $namespace
8+
9+
echo "Build custom container image using podman . . ."
10+
cd ./../../images/runtime/examples
11+
cd $image
12+
podman build -t $image -f Dockerfile
13+
14+
echo "Expose the integrated container registry . . ."
15+
oc patch configs.imageregistry.operator.openshift.io/cluster --patch '{"spec":{"defaultRoute":true}}' --type=merge
16+
17+
echo "Wait for the route to the container registry to be admitted . . ."
18+
oc wait -n openshift-image-registry route/default-route --for=jsonpath='{.status.ingress[0].conditions[0].status}'=True
19+
20+
echo "Login to the container registry . . ."
21+
podman login -u $(oc whoami) -p $(oc whoami -t) $(oc registry info)
22+
23+
echo "Push the image to the integrated container registry . . ."
24+
podman tag $image $(oc registry info)/$namespace/$image
25+
podman push $(oc registry info)/$namespace/$image
26+
27+
echo "Custom Ray Image is . . . "
28+
oc get is $image -o jsonpath='{.status.tags[?(@.tag=="latest")].items[0].dockerImageReference}'

0 commit comments

Comments
 (0)