Skip to content

Commit 94620ca

Browse files
committed
Wait for ports 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 port to be created before testing properties of it.
1 parent a1ccb52 commit 94620ca

File tree

1 file changed

+14
-36
lines changed

1 file changed

+14
-36
lines changed

test/e2e/suites/e2e/e2e_test.go

Lines changed: 14 additions & 36 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,27 @@ var _ = Describe("e2e tests", func() {
145144
customPortOptions := &[]infrav1.PortOpts{
146145
{Description: "primary"},
147146
}
147+
148+
// Note that as the bootstrap config does not have cloud.conf, the node will not be added to the cluster.
149+
// We still expect the port for the machine to be created.
148150
framework.CreateMachineDeployment(ctx, framework.CreateMachineDeploymentInput{
149151
Creator: e2eCtx.Environment.BootstrapClusterProxy.GetClient(),
150152
MachineDeployment: makeMachineDeployment(namespace.Name, md3Name, clusterName, "", 1),
151153
BootstrapConfigTemplate: makeJoinBootstrapConfigTemplate(namespace.Name, md3Name),
152154
InfraMachineTemplate: makeOpenStackMachineTemplateWithPortOptions(namespace.Name, clusterName, md3Name, customPortOptions),
153155
})
154156

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())
161-
162-
filterNone := ports.ListOpts{}
163-
plist1, err := shared.DumpOpenStackPorts(e2eCtx, filterNone)
164-
Expect(err).To(BeNil())
165-
Expect(plist1).NotTo(BeNil())
166-
167-
filterOne := ports.ListOpts{Description: "primary"}
168-
plist2, err := shared.DumpOpenStackPorts(e2eCtx, filterOne)
169-
Expect(err).To(BeNil())
170-
count := len(*plist2)
171-
Expect(count).To(Equal(1))
172-
found := portContainsProperty(*plist2, "Description", "primary")
173-
Expect(found).Should(BeTrue())
157+
shared.Byf("Waiting for custom port to be created")
158+
var plist *[]ports.Port
159+
var err error
160+
Eventually(func() int {
161+
plist, err = shared.DumpOpenStackPorts(e2eCtx, ports.ListOpts{Description: "primary"})
162+
Expect(err).To(BeNil())
163+
return len(*plist)
164+
}, e2eCtx.E2EConfig.GetIntervals(specName, "wait-worker-nodes")...).Should(Equal(1))
165+
166+
port := (*plist)[0]
167+
Expect(port.Description).To(Equal("primary"))
174168
})
175169
It("It should be creatable and deletable", func() {
176170
shared.Byf("Creating a cluster")
@@ -483,19 +477,3 @@ func isCloudProviderInitialized(taints []corev1.Taint) bool {
483477
}
484478
return true
485479
}
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)