From f898fd4eaaa6393c2d937afbfa88ae51680afc83 Mon Sep 17 00:00:00 2001 From: Huy Mai Date: Tue, 13 Feb 2024 09:09:22 +0000 Subject: [PATCH] Add ironic and bmo cleanup for upgrade BMO E2E tests Signed-off-by: Huy Mai --- test/e2e/upgrade_test.go | 42 ++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/test/e2e/upgrade_test.go b/test/e2e/upgrade_test.go index ef64fb76cf..2866198a8f 100644 --- a/test/e2e/upgrade_test.go +++ b/test/e2e/upgrade_test.go @@ -172,16 +172,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 { @@ -203,6 +203,14 @@ var _ = Describe("BMO Upgrade", func() { framework.TryAddDefaultSchemes(scheme) metal3api.AddToScheme(scheme) upgradeClusterProxy = framework.NewClusterProxy("bmo-e2e-upgrade", kubeconfigPath, scheme) + + bmoIronicNamespace, cancelWatches = 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") @@ -215,7 +223,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") @@ -225,7 +235,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"), }) @@ -242,7 +252,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"), }) @@ -255,9 +265,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, @@ -300,7 +307,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) @@ -310,14 +317,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()) @@ -344,6 +351,7 @@ var _ = Describe("BMO Upgrade", func() { AfterEach(func() { cleanup(ctx, upgradeClusterProxy, namespace, cancelWatches, e2eConfig.GetIntervals("default", "wait-namespace-deleted")...) + cleanup(ctx, upgradeClusterProxy, bmoIronicNamespace, cancelWatches, e2eConfig.GetIntervals("default", "wait-namespace-deleted")...) if !skipCleanup { if upgradeClusterProxy != nil { upgradeClusterProxy.Dispose(ctx)