Skip to content

Commit

Permalink
Add ironic and bmo cleanup for upgrade BMO E2E tests
Browse files Browse the repository at this point in the history
Signed-off-by: Huy Mai <huy.mai@est.tech>
  • Loading branch information
mquhuy committed Feb 13, 2024
1 parent 778a8e4 commit 044dac6
Showing 1 changed file with 26 additions and 17 deletions.
43 changes: 26 additions & 17 deletions test/e2e/upgrade_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package e2e

import (
"context"
"fmt"
"os"
"path/filepath"
Expand Down Expand Up @@ -172,16 +173,16 @@ const hardwareDetailsRelease04 = `

var _ = Describe("BMO Upgrade", func() {
var (
specName = "upgrade"
secretName = "bmc-credentials"
namespace *corev1.Namespace
bmoIronicNamespace string
upgradeClusterProvider bootstrap.ClusterProvider
upgradeClusterProxy framework.ClusterProxy
bmh metal3api.BareMetalHost
specName = "upgrade"
secretName = "bmc-credentials"
namespace *corev1.Namespace
bmoIronicNamespace *corev1.Namespace
upgradeClusterProvider bootstrap.ClusterProvider
upgradeClusterProxy framework.ClusterProxy
bmh metal3api.BareMetalHost
_, bmoIronicCancelWatches = context.WithCancel(ctx)
)
BeforeEach(func() {
bmoIronicNamespace = "baremetal-operator-system"
var kubeconfigPath string

if useExistingCluster {
Expand All @@ -203,6 +204,14 @@ var _ = Describe("BMO Upgrade", func() {
framework.TryAddDefaultSchemes(scheme)
metal3api.AddToScheme(scheme)
upgradeClusterProxy = framework.NewClusterProxy("bmo-e2e-upgrade", kubeconfigPath, scheme)

bmoIronicNamespace, bmoIronicCancelWatches = framework.CreateNamespaceAndWatchEvents(ctx, framework.CreateNamespaceAndWatchEventsInput{
Creator: upgradeClusterProxy.GetClient(),
ClientSet: upgradeClusterProxy.GetClientSet(),
Name: "baremetal-operator-system",
LogFolder: artifactFolder,
})

if e2eConfig.GetVariable("UPGRADE_DEPLOY_CERT_MANAGER") != "false" {
By("Installing cert-manager on the upgrade cluster")
cmVersion := e2eConfig.GetVariable("CERT_MANAGER_VERSION")
Expand All @@ -215,7 +224,9 @@ var _ = Describe("BMO Upgrade", func() {
err = checkCertManagerAPI(upgradeClusterProxy)
Expect(err).NotTo(HaveOccurred())
}
})

It("Should upgrade BMO to latest version", func() {
if e2eConfig.GetVariable("UPGRADE_DEPLOY_IRONIC") != "false" {
// Install Ironic
By("Installing Ironic on the upgrade cluster")
Expand All @@ -225,7 +236,7 @@ var _ = Describe("BMO Upgrade", func() {
WaitForDeployment: true,
WatchDeploymentLogs: true,
DeploymentName: "ironic",
DeploymentNamespace: bmoIronicNamespace,
DeploymentNamespace: bmoIronicNamespace.Name,
LogPath: filepath.Join(artifactFolder, "logs", fmt.Sprintf("%s-%s", bmoIronicNamespace, specName)),
WaitIntervals: e2eConfig.GetIntervals("default", "wait-deployment"),
})
Expand All @@ -242,7 +253,7 @@ var _ = Describe("BMO Upgrade", func() {
WaitForDeployment: true,
WatchDeploymentLogs: true,
DeploymentName: "baremetal-operator-controller-manager",
DeploymentNamespace: bmoIronicNamespace,
DeploymentNamespace: bmoIronicNamespace.Name,
LogPath: filepath.Join(artifactFolder, "logs", fmt.Sprintf("%s-%s", bmoIronicNamespace, specName), fmt.Sprintf("bmo-%s", bmoKustomizationName)),
WaitIntervals: e2eConfig.GetIntervals("default", "wait-deployment"),
})
Expand All @@ -255,9 +266,6 @@ var _ = Describe("BMO Upgrade", func() {
Name: fmt.Sprintf("%s-%s", specName, util.RandomString(6)),
LogFolder: artifactFolder,
})
})

It("Should upgrade BMO to latest version", func() {
By("Creating a secret with BMH credentials")
bmcCredentialsData := map[string]string{
"username": bmc.User,
Expand Down Expand Up @@ -300,7 +308,7 @@ var _ = Describe("BMO Upgrade", func() {
By("Upgrading BMO deployment")
clientSet := upgradeClusterProxy.GetClientSet()
bmoDeployName := "baremetal-operator-controller-manager"
deploy, err := clientSet.AppsV1().Deployments(bmoIronicNamespace).Get(ctx, bmoDeployName, metav1.GetOptions{})
deploy, err := clientSet.AppsV1().Deployments(bmoIronicNamespace.Name).Get(ctx, bmoDeployName, metav1.GetOptions{})
Expect(err).NotTo(HaveOccurred())
bmoKustomization := e2eConfig.GetVariable("BMO_KUSTOMIZATION")
bmoKustomizationName := filepath.Base(bmoKustomization)
Expand All @@ -310,14 +318,14 @@ var _ = Describe("BMO Upgrade", func() {
WaitForDeployment: false,
WatchDeploymentLogs: true,
DeploymentName: "baremetal-operator-controller-manager",
DeploymentNamespace: bmoIronicNamespace,
LogPath: filepath.Join(artifactFolder, "logs", fmt.Sprintf("%s-%s", bmoIronicNamespace, specName), fmt.Sprintf("bmo-%s", bmoKustomizationName)),
DeploymentNamespace: bmoIronicNamespace.Name,
LogPath: filepath.Join(artifactFolder, "logs", fmt.Sprintf("%s-%s", bmoIronicNamespace.Name, specName), fmt.Sprintf("bmo-%s", bmoKustomizationName)),
WaitIntervals: e2eConfig.GetIntervals("default", "wait-deployment"),
})
Expect(err).NotTo(HaveOccurred())
By("Waiting for BMO update to rollout")
Eventually(func() bool {
return DeploymentRolledOut(ctx, upgradeClusterProxy, bmoDeployName, bmoIronicNamespace, deploy.Status.ObservedGeneration+1)
return DeploymentRolledOut(ctx, upgradeClusterProxy, bmoDeployName, bmoIronicNamespace.Name, deploy.Status.ObservedGeneration+1)
},
e2eConfig.GetIntervals("default", "wait-deployment")...,
).Should(BeTrue())
Expand All @@ -344,6 +352,7 @@ var _ = Describe("BMO Upgrade", func() {

AfterEach(func() {
cleanup(ctx, upgradeClusterProxy, namespace, cancelWatches, e2eConfig.GetIntervals("default", "wait-namespace-deleted")...)
cleanup(ctx, upgradeClusterProxy, bmoIronicNamespace, bmoIronicCancelWatches, e2eConfig.GetIntervals("default", "wait-namespace-deleted")...)
if !skipCleanup {
if upgradeClusterProxy != nil {
upgradeClusterProxy.Dispose(ctx)
Expand Down

0 comments on commit 044dac6

Please sign in to comment.