Skip to content

Commit 6c9cf0e

Browse files
Merge pull request #2541 from dtantsur/e2e-detach
🌱 e2e: wait for detachment to actually happen
2 parents 46d1b7f + 8832d0c commit 6c9cf0e

File tree

4 files changed

+45
-5
lines changed

4 files changed

+45
-5
lines changed

test/e2e/common.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"os"
1919
"path"
2020
"path/filepath"
21+
"slices"
2122
"strings"
2223

2324
metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1"
@@ -71,6 +72,13 @@ type WaitForBmhInProvisioningStateInput struct {
7172
UndesiredStates []metal3api.ProvisioningState
7273
}
7374

75+
type WaitForBmhInOperationalStatusInput struct {
76+
Client client.Client
77+
Bmh metal3api.BareMetalHost
78+
State metal3api.OperationalStatus
79+
UndesiredStates []metal3api.OperationalStatus
80+
}
81+
7482
func WaitForBmhInProvisioningState(ctx context.Context, input WaitForBmhInProvisioningStateInput, intervals ...interface{}) {
7583
Eventually(func(g Gomega) {
7684
bmh := metal3api.BareMetalHost{}
@@ -88,6 +96,23 @@ func WaitForBmhInProvisioningState(ctx context.Context, input WaitForBmhInProvis
8896
}, intervals...).Should(Succeed())
8997
}
9098

99+
func WaitForBmhInOperationalStatus(ctx context.Context, input WaitForBmhInOperationalStatusInput, intervals ...interface{}) {
100+
Eventually(func(g Gomega) {
101+
bmh := metal3api.BareMetalHost{}
102+
key := types.NamespacedName{Namespace: input.Bmh.Namespace, Name: input.Bmh.Name}
103+
g.Expect(input.Client.Get(ctx, key, &bmh)).To(Succeed())
104+
105+
currentStatus := bmh.Status.OperationalStatus
106+
107+
// Check if the current state matches any of the undesired states
108+
if slices.Contains(input.UndesiredStates, currentStatus) {
109+
StopTrying(fmt.Sprintf("BMH is in an unexpected state: %s", currentStatus)).Now()
110+
}
111+
112+
g.Expect(currentStatus).To(Equal(input.State))
113+
}, intervals...).Should(Succeed())
114+
}
115+
91116
// DeleteBmhsInNamespace deletes all BMHs in the given namespace.
92117
func DeleteBmhsInNamespace(ctx context.Context, deleter client.Client, namespace string) {
93118
bmh := metal3api.BareMetalHost{}

test/e2e/config/fixture.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ intervals:
5353
default/wait-available: ["5m", "1s"]
5454
default/wait-deleting: ["5s", "10ms"]
5555
default/wait-deleted: ["5s", "10ms"]
56+
default/wait-detached: ["1s", "10ms"]
5657
default/wait-secret-deletion: ["5s", "10ms"]
5758
default/wait-power-state: ["5s", "10ms"]
5859
default/wait-externally-provisioned: ["1m", "10ms"]

test/e2e/config/ironic.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ intervals:
6565
default/wait-provisioned: ["10m", "1s"]
6666
default/wait-deprovisioning: ["1m", "10ms"]
6767
default/wait-deleted: ["20s", "10ms"]
68+
default/wait-detached: ["20s", "10ms"]
6869
default/wait-secret-deletion: ["1m", "1s"]
6970
default/wait-connect-ssh: ["2m", "10s"]
7071
default/wait-externally-provisioned: ["1m", "10ms"]

test/e2e/provisioning_and_annotation_test.go

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"encoding/json"
99
"fmt"
1010
"path"
11-
"time"
1211

1312
metal3api "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1"
1413
. "github.com/onsi/ginkgo/v2"
@@ -140,16 +139,30 @@ var _ = Describe("Provision, detach, recreate from status and deprovision", Labe
140139

141140
Expect(helper.Patch(ctx, &bmh)).To(Succeed())
142141

142+
By("Waiting for the BMH to be detached")
143+
WaitForBmhInOperationalStatus(ctx, WaitForBmhInOperationalStatusInput{
144+
Client: clusterProxy.GetClient(),
145+
Bmh: bmh,
146+
State: metal3api.OperationalStatusDetached,
147+
UndesiredStates: []metal3api.OperationalStatus{
148+
metal3api.OperationalStatusError,
149+
},
150+
}, e2eConfig.GetIntervals(specName, "wait-detached")...)
151+
152+
// Save the status with the current operationalStatus
153+
By("Retrieving the latest BMH object")
154+
err = clusterProxy.GetClient().Get(ctx, types.NamespacedName{
155+
Name: bmh.Name,
156+
Namespace: bmh.Namespace,
157+
}, &bmh)
158+
Expect(err).NotTo(HaveOccurred())
159+
143160
By("Saving the status to a JSON string")
144161
savedStatus := bmh.Status
145162
statusJSON, err := json.Marshal(savedStatus)
146163
Expect(err).NotTo(HaveOccurred())
147164

148165
By("Deleting the BMH")
149-
// Wait for 2 seconds to allow time to confirm annotation is set
150-
// TODO: fix this so we do not need the sleep
151-
time.Sleep(2 * time.Second)
152-
153166
err = clusterProxy.GetClient().Delete(ctx, &bmh)
154167
Expect(err).NotTo(HaveOccurred())
155168

0 commit comments

Comments
 (0)