Skip to content

Commit

Permalink
ci: use new helpers
Browse files Browse the repository at this point in the history
Signed-off-by: Loic Devulder <[email protected]>
  • Loading branch information
ldevulder committed Jul 21, 2023
1 parent 45cc887 commit 95e3eed
Show file tree
Hide file tree
Showing 14 changed files with 341 additions and 735 deletions.
9 changes: 5 additions & 4 deletions tests/e2e/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/rancher-sandbox/ele-testhelpers/kubectl"
"github.com/rancher/elemental/tests/e2e/helpers/misc"
"github.com/rancher-sandbox/ele-testhelpers/rancher"
"github.com/rancher-sandbox/ele-testhelpers/tools"
)

var _ = Describe("E2E - Install a simple application", Label("install-app"), func() {
It("Install HelloWorld application", func() {
kubeConfig, err := misc.SetClientKubeConfig(clusterNS, clusterName)
kubeConfig, err := rancher.SetClientKubeConfig(clusterNS, clusterName)
defer os.Remove(kubeConfig)
Expect(err).To(Not(HaveOccurred()))

Expand All @@ -44,7 +45,7 @@ var _ = Describe("E2E - Checking a simple application", Label("check-app"), func
appName := "hello-world"

// File where to host client cluster kubeconfig
kubeConfig, err := misc.SetClientKubeConfig(clusterNS, clusterName)
kubeConfig, err := rancher.SetClientKubeConfig(clusterNS, clusterName)
defer os.Remove(kubeConfig)
Expect(err).To(Not(HaveOccurred()))

Expand Down Expand Up @@ -72,7 +73,7 @@ var _ = Describe("E2E - Checking a simple application", Label("check-app"), func
Eventually(func() error {
htmlPage, err = exec.Command("curl", "http://"+ip+":8080").CombinedOutput()
return err
}, misc.SetTimeout(2*time.Minute), 5*time.Second).Should(Not(HaveOccurred()))
}, tools.SetTimeout(2*time.Minute), 5*time.Second).Should(Not(HaveOccurred()))

// Check HTML page content
Expect(string(htmlPage)).To(And(
Expand Down
13 changes: 7 additions & 6 deletions tests/e2e/backup-restore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/rancher-sandbox/ele-testhelpers/kubectl"
"github.com/rancher-sandbox/ele-testhelpers/rancher"
"github.com/rancher-sandbox/ele-testhelpers/tools"
"github.com/rancher/elemental/tests/e2e/helpers/misc"
)

var _ = Describe("E2E - Install Backup/Restore Operator", Label("install-backup-restore"), func() {
// Create kubectl context
// Default timeout is too small, so New() cannot be used
k := &kubectl.Kubectl{
Namespace: "",
PollTimeout: misc.SetTimeout(300 * time.Second),
PollTimeout: tools.SetTimeout(300 * time.Second),
PollInterval: 500 * time.Millisecond,
}

Expand Down Expand Up @@ -82,7 +82,8 @@ var _ = Describe("E2E - Install Backup/Restore Operator", Label("install-backup-

By("Waiting for rancher-backup-operator pod", func() {
// Wait for pod to be started
misc.CheckPod(k, [][]string{{"cattle-resources-system", "app.kubernetes.io/name=rancher-backup"}})
err := rancher.CheckPod(k, [][]string{{"cattle-resources-system", "app.kubernetes.io/name=rancher-backup"}})
Expect(err).To(Not(HaveOccurred()))
})
})
})
Expand Down Expand Up @@ -110,7 +111,7 @@ var _ = Describe("E2E - Test Backup/Restore", Label("test-backup-restore"), func
"--tail=-1", "--since=5m",
"--namespace", "cattle-resources-system")
return out
}, misc.SetTimeout(5*time.Minute), 10*time.Second).Should(ContainSubstring("Done with backup"))
}, tools.SetTimeout(5*time.Minute), 10*time.Second).Should(ContainSubstring("Done with backup"))
})
})

Expand Down Expand Up @@ -151,15 +152,15 @@ var _ = Describe("E2E - Test Backup/Restore", Label("test-backup-restore"), func
out, _ := kubectl.Run("get", "restore", restoreResourceName,
"-o", "jsonpath={.metadata.name}")
return out
}, misc.SetTimeout(5*time.Minute), 10*time.Second).Should(ContainSubstring(restoreResourceName))
}, tools.SetTimeout(5*time.Minute), 10*time.Second).Should(ContainSubstring(restoreResourceName))

// Check operator logs
Eventually(func() string {
out, _ := kubectl.Run("logs", "-l app.kubernetes.io/name=rancher-backup",
"--tail=-1", "--since=5m",
"--namespace", "cattle-resources-system")
return out
}, misc.SetTimeout(5*time.Minute), 10*time.Second).Should(ContainSubstring("Done restoring"))
}, tools.SetTimeout(5*time.Minute), 10*time.Second).Should(ContainSubstring("Done restoring"))
})

By("Checking cluster state after restore", func() {
Expand Down
58 changes: 30 additions & 28 deletions tests/e2e/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,18 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/rancher-sandbox/ele-testhelpers/kubectl"
"github.com/rancher-sandbox/ele-testhelpers/rancher"
"github.com/rancher-sandbox/ele-testhelpers/tools"
"github.com/rancher/elemental/tests/e2e/helpers/misc"
"github.com/rancher/elemental/tests/e2e/helpers/elemental"
"github.com/rancher/elemental/tests/e2e/helpers/network"
)

func checkClusterAgent(client *tools.Client) {
// cluster-agent is the pod that communicates to Rancher, wait for it before continuing
Eventually(func() string {
out, _ := client.RunSSH("kubectl get pod -n cattle-system -l app=cattle-cluster-agent")
return out
}, misc.SetTimeout(3*time.Duration(usedNodes)*time.Minute), 10*time.Second).Should(ContainSubstring("Running"))
}, tools.SetTimeout(3*time.Duration(usedNodes)*time.Minute), 10*time.Second).Should(ContainSubstring("Running"))
}

func getClusterState(ns, cluster, condition string) string {
Expand Down Expand Up @@ -108,12 +110,12 @@ var _ = Describe("E2E - Bootstrapping node", Label("bootstrap"), func() {

By("Setting emulated TPM to "+strconv.FormatBool(emulateTPM), func() {
// Set temporary file
emulatedTmp, err := misc.CreateTemp("emulatedTPM")
emulatedTmp, err := tools.CreateTemp("emulatedTPM")
Expect(err).To(Not(HaveOccurred()))
defer os.Remove(emulatedTmp)

// Save original file as it can be modified multiple time
misc.CopyFile(emulateTPMYaml, emulatedTmp)
tools.CopyFile(emulateTPMYaml, emulatedTmp)

// Patch the yaml file
err = tools.Sed("%EMULATE_TPM%", strconv.FormatBool(emulateTPM), emulatedTmp)
Expand Down Expand Up @@ -141,7 +143,7 @@ var _ = Describe("E2E - Bootstrapping node", Label("bootstrap"), func() {
if isoBoot == "true" {
By("Adding SeedImage", func() {
// Set temporary file
seedimageTmp, err := misc.CreateTemp("seedimage")
seedimageTmp, err := tools.CreateTemp("seedimage")
Expect(err).To(Not(HaveOccurred()))
defer os.Remove(seedimageTmp)

Expand All @@ -154,7 +156,7 @@ var _ = Describe("E2E - Bootstrapping node", Label("bootstrap"), func() {
}

// Save original file as it will have to be modified twice
misc.CopyFile(seedimageYaml, seedimageTmp)
tools.CopyFile(seedimageYaml, seedimageTmp)

// Create Yaml file
for _, p := range patterns {
Expand All @@ -173,7 +175,7 @@ var _ = Describe("E2E - Bootstrapping node", Label("bootstrap"), func() {
seedImageName,
"-o", "jsonpath={.status}")
return out
}, misc.SetTimeout(3*time.Minute), 5*time.Second).Should(ContainSubstring("downloadURL"))
}, tools.SetTimeout(3*time.Minute), 5*time.Second).Should(ContainSubstring("downloadURL"))
})

By("Downloading ISO built by SeedImage", func() {
Expand All @@ -190,7 +192,7 @@ var _ = Describe("E2E - Bootstrapping node", Label("bootstrap"), func() {

if isoBoot != "true" {
By("Configuring iPXE boot script for network installation", func() {
numberOfFile, err := misc.ConfigureiPXE()
numberOfFile, err := network.ConfigureiPXE(httpSrv)
Expect(err).To(Not(HaveOccurred()))
Expect(numberOfFile).To(BeNumerically(">=", 1))
})
Expand All @@ -201,11 +203,11 @@ var _ = Describe("E2E - Bootstrapping node", Label("bootstrap"), func() {
bootstrappedNodes = 0
for index := vmIndex; index <= numberOfVMs; index++ {
// Set node hostname
hostName := misc.SetHostname(vmNameRoot, index)
hostName := elemental.SetHostname(vmNameRoot, index)
Expect(hostName).To(Not(BeNil()))

// Add node in network configuration
err := misc.AddNode(netDefaultFileName, hostName, index)
err := rancher.AddNode(netDefaultFileName, hostName, index)
Expect(err).To(Not(HaveOccurred()))

// Get generated MAC address
Expand Down Expand Up @@ -238,7 +240,7 @@ var _ = Describe("E2E - Bootstrapping node", Label("bootstrap"), func() {
// Only for master pool
if poolType == "master" && isoBoot == "true" {
for index := vmIndex; index <= numberOfVMs; index++ {
hostName := misc.SetHostname(vmNameRoot, index)
hostName := elemental.SetHostname(vmNameRoot, index)
Expect(hostName).To(Not(BeNil()))

client, _ := GetNodeInfo(hostName)
Expand All @@ -256,7 +258,7 @@ var _ = Describe("E2E - Bootstrapping node", Label("bootstrap"), func() {
out, _ := cl.RunSSH("echo SSH_OK")
out = strings.Trim(out, "\n")
return out
}, misc.SetTimeout(10*time.Minute), 5*time.Second).Should(Equal("SSH_OK"))
}, tools.SetTimeout(10*time.Minute), 5*time.Second).Should(Equal("SSH_OK"))

// Check that the cloud-config is correctly applied by checking the presence of a file
_, err := cl.RunSSH("ls /etc/elemental-test")
Expand All @@ -266,7 +268,7 @@ var _ = Describe("E2E - Bootstrapping node", Label("bootstrap"), func() {
Eventually(func() error {
_, err := cl.RunSSH("journalctl -u elemental-register.service --no-pager | grep -i 'elemental installation completed'")
return err
}, misc.SetTimeout(8*time.Minute), 10*time.Second).Should(Not(HaveOccurred()))
}, tools.SetTimeout(8*time.Minute), 10*time.Second).Should(Not(HaveOccurred()))

// Halt the VM
_, err = cl.RunSSH("setsid -f init 0")
Expand All @@ -281,7 +283,7 @@ var _ = Describe("E2E - Bootstrapping node", Label("bootstrap"), func() {
It("Add the nodes in Rancher Manager", func() {
for index := vmIndex; index <= numberOfVMs; index++ {
// Set node hostname
hostName := misc.SetHostname(vmNameRoot, index)
hostName := elemental.SetHostname(vmNameRoot, index)
Expect(hostName).To(Not(BeNil()))

// Execute node deployment in parallel
Expand All @@ -292,9 +294,9 @@ var _ = Describe("E2E - Bootstrapping node", Label("bootstrap"), func() {

By("Checking that node "+h+" is available in Rancher", func() {
Eventually(func() string {
id, _ := misc.GetServerId(c, i)
id, _ := elemental.GetServerId(c, i)
return id
}, misc.SetTimeout(1*time.Minute), 5*time.Second).Should(Not(BeEmpty()))
}, tools.SetTimeout(1*time.Minute), 5*time.Second).Should(Not(BeEmpty()))
})
}(clusterNS, hostName, index)
}
Expand All @@ -310,7 +312,7 @@ var _ = Describe("E2E - Bootstrapping node", Label("bootstrap"), func() {

By("Incrementing number of nodes in "+poolType+" pool", func() {
// Increase 'quantity' field
value, err := misc.IncreaseQuantity(clusterNS,
value, err := rancher.SetNodeQuantity(clusterNS,
clusterName,
"pool-"+poolType+"-"+clusterName, usedNodes)
Expect(err).To(Not(HaveOccurred()))
Expand All @@ -322,7 +324,7 @@ var _ = Describe("E2E - Bootstrapping node", Label("bootstrap"), func() {
"--namespace", clusterNS,
"-o", "jsonpath={.items[*].metadata.name}")
return out
}, misc.SetTimeout(3*time.Minute), 5*time.Second).Should(ContainSubstring("selector-" + poolType + "-" + clusterName))
}, tools.SetTimeout(3*time.Minute), 5*time.Second).Should(ContainSubstring("selector-" + poolType + "-" + clusterName))
})

By("Waiting for known cluster state before adding the node(s)", func() {
Expand All @@ -337,13 +339,13 @@ var _ = Describe("E2E - Bootstrapping node", Label("bootstrap"), func() {
}

return clusterMsg
}, misc.SetTimeout(5*time.Duration(usedNodes)*time.Minute), 10*time.Second).Should(MatchRegexp(msg))
}, tools.SetTimeout(5*time.Duration(usedNodes)*time.Minute), 10*time.Second).Should(MatchRegexp(msg))
})

bootstrappedNodes = 0
for index := vmIndex; index <= numberOfVMs; index++ {
// Set node hostname
hostName := misc.SetHostname(vmNameRoot, index)
hostName := elemental.SetHostname(vmNameRoot, index)
Expect(hostName).To(Not(BeNil()))

// Get node information
Expand Down Expand Up @@ -371,7 +373,7 @@ var _ = Describe("E2E - Bootstrapping node", Label("bootstrap"), func() {
out, _ := cl.RunSSH("echo SSH_OK")
out = strings.Trim(out, "\n")
return out
}, misc.SetTimeout(10*time.Minute), 5*time.Second).Should(Equal("SSH_OK"))
}, tools.SetTimeout(10*time.Minute), 5*time.Second).Should(Equal("SSH_OK"))
})

By("Checking that TPM is correctly configured on "+h, func() {
Expand All @@ -382,7 +384,7 @@ var _ = Describe("E2E - Bootstrapping node", Label("bootstrap"), func() {
Eventually(func() error {
_, err := cl.RunSSH("[[ " + testValue + " /dev/tpm0 ]]")
return err
}, misc.SetTimeout(1*time.Minute), 5*time.Second).Should(Not(HaveOccurred()))
}, tools.SetTimeout(1*time.Minute), 5*time.Second).Should(Not(HaveOccurred()))
})

By("Checking OS version on "+h, func() {
Expand All @@ -402,7 +404,7 @@ var _ = Describe("E2E - Bootstrapping node", Label("bootstrap"), func() {
if poolType != "worker" {
for index := vmIndex; index <= numberOfVMs; index++ {
// Set node hostname
hostName := misc.SetHostname(vmNameRoot, index)
hostName := elemental.SetHostname(vmNameRoot, index)
Expect(hostName).To(Not(BeNil()))

// Get node information
Expand All @@ -425,7 +427,7 @@ var _ = Describe("E2E - Bootstrapping node", Label("bootstrap"), func() {
Eventually(func() error {
_, err := cl.RunSSH("[[ -d " + dir + " ]]")
return err
}, misc.SetTimeout(3*time.Minute), 5*time.Second).Should(Not(HaveOccurred()))
}, tools.SetTimeout(3*time.Minute), 5*time.Second).Should(Not(HaveOccurred()))

// Configure kubectl
_, err := cl.RunSSH("I=" + dir + "/kubectl; if [[ -x ${I} ]]; then ln -s ${I} bin/; echo " + kubeCfg + " >> .bashrc; fi")
Expand All @@ -438,7 +440,7 @@ var _ = Describe("E2E - Bootstrapping node", Label("bootstrap"), func() {
Eventually(func() string {
out, _ := cl.RunSSH("kubectl version 2>/dev/null | grep 'Server Version:'")
return out
}, misc.SetTimeout(5*time.Minute), 5*time.Second).Should(ContainSubstring(k8sVersion))
}, tools.SetTimeout(5*time.Minute), 5*time.Second).Should(ContainSubstring(k8sVersion))
})

By("Checking cluster agent on "+h, func() {
Expand All @@ -458,7 +460,7 @@ var _ = Describe("E2E - Bootstrapping node", Label("bootstrap"), func() {
if poolType != "worker" {
for index := vmIndex; index <= numberOfVMs; index++ {
// Set node hostname
hostName := misc.SetHostname(vmNameRoot, index)
hostName := elemental.SetHostname(vmNameRoot, index)
Expect(hostName).To(Not(BeNil()))

// Get node information
Expand All @@ -479,7 +481,7 @@ var _ = Describe("E2E - Bootstrapping node", Label("bootstrap"), func() {
GinkgoWriter.Printf("K8s version on %s:\n%s\n", h, k8sVer)
}
return err
}, misc.SetTimeout(1*time.Minute), 5*time.Second).Should(Not(HaveOccurred()))
}, tools.SetTimeout(1*time.Minute), 5*time.Second).Should(Not(HaveOccurred()))
})
}(hostName, client)
}
Expand All @@ -491,7 +493,7 @@ var _ = Describe("E2E - Bootstrapping node", Label("bootstrap"), func() {
bootstrappedNodes = 0
for index := vmIndex; index <= numberOfVMs; index++ {
// Set node hostname
hostName := misc.SetHostname(vmNameRoot, index)
hostName := elemental.SetHostname(vmNameRoot, index)
Expect(hostName).To(Not(BeNil()))

// Get node information
Expand Down
Loading

0 comments on commit 95e3eed

Please sign in to comment.