Skip to content

Commit 731fbbb

Browse files
Merge pull request #765 from Nordix/Add-cleaning-to-upgrade-test/mohammed
🌱 Add Precleaning hook to upgrade test
2 parents 9d97946 + 2a53dc6 commit 731fbbb

File tree

2 files changed

+39
-14
lines changed

2 files changed

+39
-14
lines changed

test/e2e/pivoting_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ func removeIronicDeployment() {
214214
Expect(err).To(BeNil(), "Failed to delete Ironic from the source cluster")
215215
}
216216

217-
func removeIronicDeploymentOnTarget() {
217+
func removeIronicDeploymentOnTarget(targetCluster framework.ClusterProxy) {
218218
deploymentName := e2eConfig.GetVariable("NAMEPREFIX") + "-ironic"
219219
ironicNamespace := e2eConfig.GetVariable("IRONIC_NAMESPACE")
220220
err := targetCluster.GetClientSet().AppsV1().Deployments(ironicNamespace).Delete(ctx, deploymentName, metav1.DeleteOptions{})
@@ -270,7 +270,7 @@ func labelHDCRDs(targetCluster framework.ClusterProxy) {
270270
func rePivoting() {
271271
Logf("Start the re-pivoting test")
272272
By("Remove Ironic deployment from target cluster")
273-
removeIronicDeploymentOnTarget()
273+
removeIronicDeploymentOnTarget(targetCluster)
274274

275275
By("Reinstate Ironic containers and BMH")
276276
ephemeralCluster := os.Getenv("EPHEMERAL_CLUSTER")

test/e2e/upgrade_management_cluster_test.go

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,19 @@ var _ = Describe("When testing cluster upgrade v1alpha5 > current [upgrade]", fu
2626
})
2727
capi_e2e.ClusterctlUpgradeSpec(ctx, func() capi_e2e.ClusterctlUpgradeSpecInput {
2828
return capi_e2e.ClusterctlUpgradeSpecInput{
29-
E2EConfig: e2eConfig,
30-
ClusterctlConfigPath: clusterctlConfigPath,
31-
BootstrapClusterProxy: bootstrapClusterProxy,
32-
ArtifactFolder: artifactFolder,
33-
SkipCleanup: true, // TODO(mboukhalfa): Parameterize after merging https://github.com/kubernetes-sigs/cluster-api/pull/7373
34-
InitWithProvidersContract: "v1alpha4",
35-
InitWithBinary: e2eConfig.GetVariable("INIT_WITH_BINARY"),
36-
PreInit: preInitFunc,
37-
PreWaitForCluster: preWaitForCluster,
38-
PreUpgrade: preUpgrade,
39-
MgmtFlavor: osType,
40-
WorkloadFlavor: osType,
29+
E2EConfig: e2eConfig,
30+
ClusterctlConfigPath: clusterctlConfigPath,
31+
BootstrapClusterProxy: bootstrapClusterProxy,
32+
ArtifactFolder: artifactFolder,
33+
SkipCleanup: skipCleanup,
34+
InitWithProvidersContract: "v1alpha4",
35+
InitWithBinary: e2eConfig.GetVariable("INIT_WITH_BINARY"),
36+
PreInit: preInitFunc,
37+
PreWaitForCluster: preWaitForCluster,
38+
PreUpgrade: preUpgrade,
39+
PreCleanupManagementCluster: preCleanupManagementCluster,
40+
MgmtFlavor: osType,
41+
WorkloadFlavor: osType,
4142
}
4243
})
4344
})
@@ -152,3 +153,27 @@ func preUpgrade(clusterProxy framework.ClusterProxy) {
152153
upgradeIronic(clusterProxy.GetClientSet())
153154
upgradeBMO(clusterProxy.GetClientSet())
154155
}
156+
157+
// preCleanupManagementCluster hook should be called from ClusterctlUpgradeSpec before cleaning the target management cluster
158+
// it moves back Ironic to the bootstrap cluster.
159+
func preCleanupManagementCluster(clusterProxy framework.ClusterProxy) {
160+
// Reinstall ironic
161+
reInstallIronic := func() {
162+
By("Reinstate Ironic containers and BMH")
163+
ephemeralCluster := os.Getenv("EPHEMERAL_CLUSTER")
164+
if ephemeralCluster == KIND {
165+
By("Install Ironic in the source cluster as containers")
166+
bmoPath := e2eConfig.GetVariable("BMOPATH")
167+
ironicCommand := bmoPath + "/tools/run_local_ironic.sh"
168+
cmd := exec.Command("sh", "-c", "export CONTAINER_RUNTIME=docker; "+ironicCommand)
169+
stdoutStderr, err := cmd.CombinedOutput()
170+
fmt.Printf("%s\n", stdoutStderr)
171+
Expect(err).To(BeNil(), "Cannot run local ironic")
172+
} else {
173+
By("Install Ironic in the source cluster as deployments")
174+
installIronicBMO(bootstrapClusterProxy, "true", "false")
175+
}
176+
}
177+
removeIronicDeploymentOnTarget(clusterProxy)
178+
reInstallIronic()
179+
}

0 commit comments

Comments
 (0)