Skip to content

Commit 6be9120

Browse files
committed
Wait for machine creation in ports e2e test
The ports e2e test was checking that a failure condition had not occurred. However, it's possible the failure condition hadn't occurred because the machine used for the test had not been created yet, and the rest of the tests race ahead and do not find the port. This commit ensures that we wait for the machine to be created before listing ports.
1 parent a1ccb52 commit 6be9120

File tree

1 file changed

+16
-33
lines changed

1 file changed

+16
-33
lines changed

test/e2e/suites/e2e/e2e_test.go

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"errors"
2424
"fmt"
2525
"path/filepath"
26-
"reflect"
2726
"strings"
2827
"time"
2928

@@ -145,32 +144,32 @@ var _ = Describe("e2e tests", func() {
145144
customPortOptions := &[]infrav1.PortOpts{
146145
{Description: "primary"},
147146
}
147+
machineDeployment := makeMachineDeployment(namespace.Name, md3Name, clusterName, "", 1)
148148
framework.CreateMachineDeployment(ctx, framework.CreateMachineDeploymentInput{
149149
Creator: e2eCtx.Environment.BootstrapClusterProxy.GetClient(),
150-
MachineDeployment: makeMachineDeployment(namespace.Name, md3Name, clusterName, "", 1),
150+
MachineDeployment: machineDeployment,
151151
BootstrapConfigTemplate: makeJoinBootstrapConfigTemplate(namespace.Name, md3Name),
152152
InfraMachineTemplate: makeOpenStackMachineTemplateWithPortOptions(namespace.Name, clusterName, md3Name, customPortOptions),
153153
})
154154

155-
shared.Byf("Expecting MachineDeployment to be created successfully")
156-
Eventually(func() bool {
157-
eventList := getEvents(namespace.Name)
158-
portError := "Failed to create server with custom port options"
159-
return isErrorEventExists(namespace.Name, md3Name, "FailedCreateServer", portError, eventList)
160-
}, e2eCtx.E2EConfig.GetIntervals(specName, "wait-worker-nodes")...).Should(BeFalse())
155+
cluster := framework.GetClusterByName(ctx, framework.GetClusterByNameInput{
156+
Getter: e2eCtx.Environment.BootstrapClusterProxy.GetClient(),
157+
Name: clusterName,
158+
Namespace: namespace.Name,
159+
})
161160

162-
filterNone := ports.ListOpts{}
163-
plist1, err := shared.DumpOpenStackPorts(e2eCtx, filterNone)
164-
Expect(err).To(BeNil())
165-
Expect(plist1).NotTo(BeNil())
161+
shared.Byf("Waiting for MachineDeployment node to be created")
162+
framework.WaitForMachineDeploymentNodesToExist(ctx, framework.WaitForMachineDeploymentNodesToExistInput{
163+
Lister: e2eCtx.Environment.BootstrapClusterProxy.GetClient(),
164+
Cluster: cluster,
165+
MachineDeployment: machineDeployment,
166+
}, e2eCtx.E2EConfig.GetIntervals(specName, "wait-worker-nodes")...)
166167

167-
filterOne := ports.ListOpts{Description: "primary"}
168-
plist2, err := shared.DumpOpenStackPorts(e2eCtx, filterOne)
168+
shared.Byf("Expecting custom port to be found")
169+
plist, err := shared.DumpOpenStackPorts(e2eCtx, ports.ListOpts{Description: "primary"})
169170
Expect(err).To(BeNil())
170-
count := len(*plist2)
171+
count := len(*plist)
171172
Expect(count).To(Equal(1))
172-
found := portContainsProperty(*plist2, "Description", "primary")
173-
Expect(found).Should(BeTrue())
174173
})
175174
It("It should be creatable and deletable", func() {
176175
shared.Byf("Creating a cluster")
@@ -483,19 +482,3 @@ func isCloudProviderInitialized(taints []corev1.Taint) bool {
483482
}
484483
return true
485484
}
486-
487-
// Verifies that a Port contains a valid property with a correct value.
488-
func portContainsProperty(plist interface{}, property string, value interface{}) bool {
489-
ports := reflect.ValueOf(plist)
490-
portsCount := ports.Len()
491-
for i := 0; i < portsCount; i++ {
492-
currentPort := ports.Index(i)
493-
searchProperty := currentPort.FieldByName(property)
494-
correctValue := searchProperty.Interface() == value
495-
if correctValue {
496-
return true
497-
}
498-
}
499-
// Non-existing property or incorrect value
500-
return false
501-
}

0 commit comments

Comments
 (0)