diff --git a/.github/workflows/master-e2e.yaml b/.github/workflows/master-e2e.yaml index f32e14252..a31be7653 100644 --- a/.github/workflows/master-e2e.yaml +++ b/.github/workflows/master-e2e.yaml @@ -470,6 +470,9 @@ jobs: - name: Install a simple application if: inputs.test_type == 'cli' && contains(inputs.upstream_cluster_version, 'k3s') run: cd tests && make e2e-install-app && make e2e-check-app + - name: Reset a node in the cluster + if: inputs.test_type == 'cli' + run: cd tests && make e2e-reset - name: Upgrade Elemental Operator if: inputs.test_type == 'cli' && inputs.operator_upgrade != '' id: operator_upgrade diff --git a/tests/Makefile b/tests/Makefile index 9d07fa4b2..bdd6ac10b 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -73,6 +73,8 @@ e2e-check-app: deps ginkgo --label-filter check-app -r -v ./e2e e2e-configure-rancher: deps ginkgo --label-filter configure -r -v ./e2e +e2e-reset: deps + ginkgo --label-filter reset -r -v ./e2e e2e-get-logs: deps ginkgo --label-filter logs -r -v ./e2e e2e-install-rancher: deps diff --git a/tests/assets/machineRegistration.yaml b/tests/assets/machineRegistration.yaml index 10ba2ec32..f0763ee24 100644 --- a/tests/assets/machineRegistration.yaml +++ b/tests/assets/machineRegistration.yaml @@ -24,4 +24,11 @@ spec: poweroff: true device: /dev/sda debug: true + reset: + debug: true + enabled: true + reset-persistent: true + reset-oem: true + poweroff: false + reboot: true machineName: %VM_NAME%-${System Information/UUID} diff --git a/tests/assets/reset_machine_inventory.yaml b/tests/assets/reset_machine_inventory.yaml new file mode 100644 index 000000000..7ebddaa2e --- /dev/null +++ b/tests/assets/reset_machine_inventory.yaml @@ -0,0 +1,3 @@ +metadata: + annotations: + elemental.cattle.io/resettable: "true" diff --git a/tests/e2e/reset_test.go b/tests/e2e/reset_test.go new file mode 100644 index 000000000..1a73ce9d0 --- /dev/null +++ b/tests/e2e/reset_test.go @@ -0,0 +1,64 @@ +/* +Copyright © 2022 - 2023 SUSE LLC + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package e2e_test + +import ( + "os/exec" + "strings" + "time" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + "github.com/rancher-sandbox/ele-testhelpers/kubectl" + "github.com/rancher-sandbox/ele-testhelpers/tools" +) + +var _ = Describe("E2E - Test the reset feature", Label("reset"), func() { + It("Reset one node in the cluster", func() { + // Get the machine inventory name list + machineInventory, err := kubectl.Run("get", "machineinventory", "-A", "-o", "jsonpath='{.items[*].metadata.name}'") + Expect(err).To(Not(HaveOccurred())) + firstMachineInventory := strings.Split(machineInventory, " ")[1] + + By("Configuring reset at machine inventory level", func() { + // Patch the first machine inventory to enable reset + _, err = kubectl.Run("patch", "machineinventory", firstMachineInventory, "--namespace", clusterNS, "--type", "merge", "--patch-file", resetMachineInv) + Expect(err).To(Not(HaveOccurred())) + }) + + By("Deleting and removing the node from the cluster", func() { + out, err := exec.Command("bash", "-c", "kubectl get machines -A | awk '/"+firstMachineInventory+"/ {print $2}'").CombinedOutput() + Expect(err).To(Not(HaveOccurred())) + machineToRemove := strings.Trim(string(out), "\n") + _, err = kubectl.Run("delete", "machines", machineToRemove, "-n", "fleet-default") + Expect(err).To(Not(HaveOccurred())) + }) + + By("Checking machine inventory", func() { + Eventually(func() string { + out, _ := kubectl.Run("get", "MachineInventory", + firstMachineInventory, + "--namespace", clusterNS, + "-o", "jsonpath={.items[*].metadata.name}") + return out + }, tools.SetTimeout(5*time.Minute), 5*time.Second).ShouldNot(Equal(firstMachineInventory)) + + }) + + By("Adding the node back into the cluster", func() { + + }) + }) +}) diff --git a/tests/e2e/suite_test.go b/tests/e2e/suite_test.go index e3f892a57..81ef20213 100644 --- a/tests/e2e/suite_test.go +++ b/tests/e2e/suite_test.go @@ -46,6 +46,7 @@ const ( numberOfNodesMax = 30 osListYaml = "../assets/managedOSVersionChannel.yaml" registrationYaml = "../assets/machineRegistration.yaml" + resetMachineInv = "../assets/reset_machine_inventory.yaml" restoreYaml = "../assets/restore.yaml" seedimageYaml = "../assets/seedImage.yaml" selectorYaml = "../assets/selector.yaml"