|
| 1 | +/* |
| 2 | +Copyright 2025 Feast Community. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package e2erhoai |
| 18 | + |
| 19 | +import ( |
| 20 | + "fmt" |
| 21 | + "os" |
| 22 | + "os/exec" |
| 23 | + "strings" |
| 24 | + |
| 25 | + utils "github.com/feast-dev/feast/infra/feast-operator/test/utils" |
| 26 | + . "github.com/onsi/ginkgo/v2" |
| 27 | + . "github.com/onsi/gomega" |
| 28 | +) |
| 29 | + |
| 30 | +var _ = Describe("Feast Jupyter Notebook Testing", Ordered, func() { |
| 31 | + const ( |
| 32 | + namespace = "test-ns-feast-wb" |
| 33 | + configMapName = "feast-wb-cm" |
| 34 | + rolebindingName = "rb-feast-test" |
| 35 | + notebookFile = "test/e2e_rhoai/resources/feast-test.ipynb" |
| 36 | + pvcFile = "test/e2e_rhoai/resources/pvc.yaml" |
| 37 | + notebookPVC = "jupyterhub-nb-kube-3aadmin-pvc" |
| 38 | + testDir = "/test/e2e_rhoai" |
| 39 | + notebookName = "feast-test.ipynb" |
| 40 | + feastMilvusTest = "TestFeastMilvusNotebook" |
| 41 | + ) |
| 42 | + |
| 43 | + BeforeAll(func() { |
| 44 | + By(fmt.Sprintf("Creating test namespace: %s", namespace)) |
| 45 | + Expect(utils.CreateNamespace(namespace, testDir)).To(Succeed()) |
| 46 | + fmt.Printf("Namespace %s created successfully\n", namespace) |
| 47 | + }) |
| 48 | + |
| 49 | + AfterAll(func() { |
| 50 | + By(fmt.Sprintf("Deleting test namespace: %s", namespace)) |
| 51 | + Expect(utils.DeleteNamespace(namespace, testDir)).To(Succeed()) |
| 52 | + fmt.Printf("Namespace %s deleted successfully\n", namespace) |
| 53 | + }) |
| 54 | + |
| 55 | + runNotebookTest := func() { |
| 56 | + env := func(key string) string { |
| 57 | + val, _ := os.LookupEnv(key) |
| 58 | + return val |
| 59 | + } |
| 60 | + |
| 61 | + username := utils.GetOCUser(testDir) |
| 62 | + |
| 63 | + // create config map |
| 64 | + By(fmt.Sprintf("Creating Config map: %s", configMapName)) |
| 65 | + cmd := exec.Command("kubectl", "create", "configmap", configMapName, "-n", namespace, "--from-file="+notebookFile, "--from-file=test/e2e_rhoai/resources/feature_repo") |
| 66 | + output, err := utils.Run(cmd, "/test/e2e_rhoai") |
| 67 | + Expect(err).ToNot(HaveOccurred(), fmt.Sprintf( |
| 68 | + "Failed to create ConfigMap %s.\nError: %v\nOutput: %s\n", |
| 69 | + configMapName, err, output, |
| 70 | + )) |
| 71 | + fmt.Printf("ConfigMap %s created successfully\n", configMapName) |
| 72 | + |
| 73 | + // create pvc |
| 74 | + By("Creating Persistent volume claim: jupyterhub-nb-kube-3aadmin-pvc") |
| 75 | + cmd = exec.Command("kubectl", "apply", "-f", "test/e2e_rhoai/resources/pvc.yaml", "-n", namespace) |
| 76 | + _, err = utils.Run(cmd, "/test/e2e_rhoai") |
| 77 | + ExpectWithOffset(1, err).NotTo(HaveOccurred()) |
| 78 | + fmt.Println("Persistent Volume Claim jupyterhub-nb-kube-3aadmin-pvc created successfully") |
| 79 | + |
| 80 | + // create rolebinding |
| 81 | + By(fmt.Sprintf("Creating rolebinding %s for the user", rolebindingName)) |
| 82 | + cmd = exec.Command("kubectl", "create", "rolebinding", rolebindingName, "-n", namespace, "--role=admin", "--user="+username) |
| 83 | + _, err = utils.Run(cmd, "/test/e2e_rhoai") |
| 84 | + ExpectWithOffset(1, err).NotTo(HaveOccurred()) |
| 85 | + fmt.Printf("Created rolebinding %s successfully\n", rolebindingName) |
| 86 | + |
| 87 | + // configure papermill notebook command execution |
| 88 | + command := []string{ |
| 89 | + "/bin/sh", |
| 90 | + "-c", |
| 91 | + fmt.Sprintf( |
| 92 | + "pip install papermill && "+ |
| 93 | + "mkdir -p /opt/app-root/src/feature_repo && "+ |
| 94 | + "cp -rL /opt/app-root/notebooks/* /opt/app-root/src/feature_repo/ && "+ |
| 95 | + "oc login --token=%s --server=%s --insecure-skip-tls-verify=true && "+ |
| 96 | + "(papermill /opt/app-root/notebooks/%s /opt/app-root/src/output.ipynb --kernel python3 && "+ |
| 97 | + "echo '✅ Notebook executed successfully' || "+ |
| 98 | + "(echo '❌ Notebook execution failed' && "+ |
| 99 | + "cp /opt/app-root/src/output.ipynb /opt/app-root/src/failed_output.ipynb && "+ |
| 100 | + "echo '📄 Copied failed notebook to failed_output.ipynb')) && "+ |
| 101 | + "jupyter nbconvert --to notebook --stdout /opt/app-root/src/output.ipynb || echo '⚠️ nbconvert failed' && "+ |
| 102 | + "sleep 100; exit 0", |
| 103 | + utils.GetOCToken("test/e2e_rhoai"), |
| 104 | + utils.GetOCServer("test/e2e_rhoai"), |
| 105 | + "feast-test.ipynb", |
| 106 | + ), |
| 107 | + } |
| 108 | + |
| 109 | + // Defining notebook parameters |
| 110 | + nbParams := utils.NotebookTemplateParams{ |
| 111 | + Namespace: namespace, |
| 112 | + IngressDomain: utils.GetIngressDomain(testDir), |
| 113 | + OpenDataHubNamespace: env("APPLICATIONS_NAMESPACE"), |
| 114 | + NotebookImage: env("NOTEBOOK_IMAGE"), |
| 115 | + NotebookConfigMapName: configMapName, |
| 116 | + NotebookPVC: notebookPVC, |
| 117 | + Username: username, |
| 118 | + OC_TOKEN: utils.GetOCToken(testDir), |
| 119 | + OC_SERVER: utils.GetOCServer(testDir), |
| 120 | + NotebookFile: notebookName, |
| 121 | + Command: "[\"" + strings.Join(command, "\",\"") + "\"]", |
| 122 | + PipIndexUrl: env("PIP_INDEX_URL"), |
| 123 | + PipTrustedHost: env("PIP_TRUSTED_HOST"), |
| 124 | + FeastVerison: env("FEAST_VERSION"), |
| 125 | + OpenAIAPIKey: env("OPENAI_API_KEY"), |
| 126 | + } |
| 127 | + |
| 128 | + By("Creating Jupyter Notebook") |
| 129 | + Expect(utils.CreateNotebook(nbParams)).To(Succeed(), "Failed to create notebook") |
| 130 | + |
| 131 | + By("Monitoring notebook logs") |
| 132 | + Expect(utils.MonitorNotebookPod(namespace, "jupyter-nb-", notebookName)).To(Succeed(), "Notebook execution failed") |
| 133 | + } |
| 134 | + |
| 135 | + Context("Feast Jupyter Notebook Test", func() { |
| 136 | + It("Should create and run a "+feastMilvusTest+" successfully", runNotebookTest) |
| 137 | + }) |
| 138 | +}) |
0 commit comments