Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: test reset feature in cli tests #997

Merged
merged 2 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/cli-obs-manual-workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ on:
type: boolean
iso_to_test:
description: Defines the ISO to test
default: https://download.opensuse.org/repositories/isv:/Rancher:/Elemental:/Dev:/Teal53/media/iso/elemental-teal.x86_64.iso
default: https://download.opensuse.org/repositories/isv:/Rancher:/Elemental:/Dev/containers/iso/elemental-teal.x86_64.iso
type: string
k8s_version:
description: Version of K3s/RKE2 to use (for both upstream and downstream clusters)
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/master-e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,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' && inputs.rancher_upgrade == ''
run: cd tests && make e2e-reset && make e2e-check-app
- name: Upgrade Elemental Operator
if: inputs.test_type == 'cli' && inputs.operator_upgrade != ''
id: operator_upgrade
Expand Down
2 changes: 2 additions & 0 deletions tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions tests/assets/reset_machine_inventory.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
metadata:
annotations:
elemental.cattle.io/resettable: "true"
71 changes: 71 additions & 0 deletions tests/e2e/reset_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
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}'")
juadk marked this conversation as resolved.
Show resolved Hide resolved
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()
ldevulder marked this conversation as resolved.
Show resolved Hide resolved
Expect(err).To(Not(HaveOccurred()))
machineToRemove := strings.Trim(string(out), "\n")
_, err = kubectl.Run("delete", "machines", machineToRemove, "-n", "fleet-default")
juadk marked this conversation as resolved.
Show resolved Hide resolved
Expect(err).To(Not(HaveOccurred()))
})

By("Checking that machine inventory is deleted", func() {
Eventually(func() string {
out, _ := kubectl.Run("get", "MachineInventory",
"--namespace", clusterNS,
"-o", "jsonpath={.items[*].metadata.name}")
return out
}, tools.SetTimeout(5*time.Minute), 5*time.Second).ShouldNot(ContainSubstring(firstMachineInventory))
})

By("Checking that machine inventory is back after the reset", func() {
Eventually(func() string {
out, _ := kubectl.Run("get", "MachineInventory",
"--namespace", clusterNS,
"-o", "jsonpath={.items[*].metadata.name}")
return out
}, tools.SetTimeout(8*time.Minute), 5*time.Second).Should(ContainSubstring(firstMachineInventory))
})

By("Checking cluster state", func() {
CheckClusterState(clusterNS, clusterName)
})
})
juadk marked this conversation as resolved.
Show resolved Hide resolved
})
1 change: 1 addition & 0 deletions tests/e2e/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const (
netDefaultFileName = "../assets/net-default.xml"
numberOfNodesMax = 30
registrationYaml = "../assets/machineRegistration.yaml"
resetMachineInv = "../assets/reset_machine_inventory.yaml"
juadk marked this conversation as resolved.
Show resolved Hide resolved
restoreYaml = "../assets/restore.yaml"
seedimageYaml = "../assets/seedImage.yaml"
selectorYaml = "../assets/selector.yaml"
Expand Down
Loading