github.com/rancher/elemental/tests@v0.0.0-20240517125144-ae048c615b3f/e2e/reset_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 "strings" 19 "time" 20 21 . "github.com/onsi/ginkgo/v2" 22 . "github.com/onsi/gomega" 23 "github.com/rancher-sandbox/ele-testhelpers/kubectl" 24 "github.com/rancher-sandbox/ele-testhelpers/tools" 25 "github.com/rancher/elemental/tests/e2e/helpers/elemental" 26 ) 27 28 var _ = Describe("E2E - Test the reset feature", Label("reset"), func() { 29 It("Reset one node in the cluster", func() { 30 // Report to Qase 31 testCaseID = 54 32 33 // Get the machine inventory name list 34 machineInventory, err := kubectl.RunWithoutErr("get", "MachineInventory", 35 "--namespace", clusterNS, 36 "-o", "jsonpath='{.items[*].metadata.name}'") 37 Expect(err).To(Not(HaveOccurred())) 38 firstMachineInventory := strings.Split(machineInventory, " ")[1] 39 40 By("Configuring reset at MachineInventory level", func() { 41 // Patch the first machine inventory to enable reset 42 _, err = kubectl.RunWithoutErr("patch", "MachineInventory", firstMachineInventory, 43 "--namespace", clusterNS, "--type", "merge", 44 "--patch-file", resetMachineInv) 45 Expect(err).To(Not(HaveOccurred())) 46 }) 47 48 By("Deleting and removing the node from the cluster", func() { 49 machineToRemove, err := elemental.GetInternalMachine(clusterNS, firstMachineInventory) 50 Expect(err).To(Not(HaveOccurred())) 51 _, err = kubectl.RunWithoutErr("delete", "machines", machineToRemove, 52 "--namespace", clusterNS) 53 Expect(err).To(Not(HaveOccurred())) 54 }) 55 56 By("Checking that MachineInventory is deleted", func() { 57 Eventually(func() string { 58 out, _ := kubectl.RunWithoutErr("get", "MachineInventory", 59 "--namespace", clusterNS, 60 "-o", "jsonpath={.items[*].metadata.name}") 61 return out 62 }, tools.SetTimeout(5*time.Minute), 5*time.Second).ShouldNot(ContainSubstring(firstMachineInventory)) 63 }) 64 65 By("Checking that MachineInventory is back after the reset", func() { 66 Eventually(func() string { 67 out, _ := kubectl.RunWithoutErr("get", "MachineInventory", 68 "--namespace", clusterNS, 69 "-o", "jsonpath={.items[*].metadata.name}") 70 return out 71 }, tools.SetTimeout(8*time.Minute), 5*time.Second).Should(ContainSubstring(firstMachineInventory)) 72 }) 73 74 By("Checking cluster state", func() { 75 WaitCluster(clusterNS, clusterName) 76 }) 77 }) 78 })