github.com/rancher/elemental/tests@v0.0.0-20240517125144-ae048c615b3f/e2e/seedImage_test.go (about) 1 /* 2 Copyright © 2022 - 2024 SUSE LLC 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 http://www.apache.org/licenses/LICENSE-2.0 8 Unless required by applicable law or agreed to in writing, software 9 distributed under the License is distributed on an "AS IS" BASIS, 10 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 See the License for the specific language governing permissions and 12 limitations under the License. 13 */ 14 15 package e2e_test 16 17 import ( 18 "os" 19 "os/exec" 20 "strconv" 21 22 . "github.com/onsi/ginkgo/v2" 23 . "github.com/onsi/gomega" 24 "github.com/rancher-sandbox/ele-testhelpers/kubectl" 25 "github.com/rancher-sandbox/ele-testhelpers/tools" 26 "github.com/rancher/elemental/tests/e2e/helpers/elemental" 27 ) 28 29 var _ = Describe("E2E - Creating ISO image", Label("iso-image"), func() { 30 var ( 31 machineRegName string 32 seedImageName string 33 ) 34 35 BeforeEach(func() { 36 machineRegName = "machine-registration-" + poolType + "-" + clusterName 37 seedImageName = "seed-image-" + poolType + "-" + clusterName 38 }) 39 40 It("Configure and create ISO image", func() { 41 // Report to Qase 42 testCaseID = 38 43 44 By("Adding SeedImage", func() { 45 // Wait for list of OS versions to be populated 46 WaitForOSVersion(clusterNS) 47 48 // Get OSVersion name 49 OSVersion, err := exec.Command(getOSScript, os2Test, "true").Output() 50 Expect(err).To(Not(HaveOccurred())) 51 Expect(OSVersion).To(Not(BeEmpty())) 52 53 // Extract container image URL 54 baseImageURL, err := elemental.GetImageURI(clusterNS, string(OSVersion)) 55 Expect(err).To(Not(HaveOccurred())) 56 Expect(baseImageURL).To(Not(BeEmpty())) 57 58 // Set poweroff to false for master pool to have time to check SeedImage cloud-config 59 if poolType == "master" && isoBoot { 60 _, err := kubectl.RunWithoutErr("patch", "MachineRegistration", 61 "--namespace", clusterNS, machineRegName, 62 "--type", "merge", "--patch", 63 "{\"spec\":{\"config\":{\"elemental\":{\"install\":{\"poweroff\":false}}}}}") 64 Expect(err).To(Not(HaveOccurred())) 65 } 66 67 By("Setting emulated TPM to "+strconv.FormatBool(emulateTPM), func() { 68 // Set temporary file 69 emulatedTmp, err := tools.CreateTemp("emulatedTPM") 70 Expect(err).To(Not(HaveOccurred())) 71 defer os.Remove(emulatedTmp) 72 73 // Save original file as it can be modified multiple time 74 err = tools.CopyFile(emulateTPMYaml, emulatedTmp) 75 Expect(err).To(Not(HaveOccurred())) 76 77 // Patch the yaml file 78 err = tools.Sed("%EMULATE_TPM%", strconv.FormatBool(emulateTPM), emulatedTmp) 79 Expect(err).To(Not(HaveOccurred())) 80 81 // And apply it 82 _, err = kubectl.RunWithoutErr("patch", "MachineRegistration", 83 "--namespace", clusterNS, machineRegName, 84 "--type", "merge", "--patch-file", emulatedTmp, 85 ) 86 Expect(err).To(Not(HaveOccurred())) 87 }) 88 89 // Patterns to replace 90 patterns := []YamlPattern{ 91 { 92 key: "%CLUSTER_NAME%", 93 value: clusterName, 94 }, 95 { 96 key: "%BASE_IMAGE%", 97 value: baseImageURL, 98 }, 99 { 100 key: "%POOL_TYPE%", 101 value: poolType, 102 }, 103 } 104 105 // Set temporary file 106 seedImageTmp, err := tools.CreateTemp("seedImage") 107 Expect(err).To(Not(HaveOccurred())) 108 defer os.Remove(seedImageTmp) 109 110 // Save original file as it will have to be modified twice 111 err = tools.CopyFile(seedImageYaml, seedImageTmp) 112 Expect(err).To(Not(HaveOccurred())) 113 114 // Create Yaml file 115 for _, p := range patterns { 116 err := tools.Sed(p.key, p.value, seedImageTmp) 117 Expect(err).To(Not(HaveOccurred())) 118 } 119 120 // Apply to k8s 121 err = kubectl.Apply(clusterNS, seedImageTmp) 122 Expect(err).To(Not(HaveOccurred())) 123 }) 124 }) 125 126 It("Download ISO built by SeedImage", func() { 127 // Report to Qase 128 testCaseID = 39 129 130 DownloadBuiltISO(clusterNS, seedImageName, "../../elemental-"+poolType+".iso") 131 }) 132 })