Skip to content

Commit c7eb9d4

Browse files
committed
Fix envTest topologyRef race condition
Before this patch, the "updates topology" envTest was a single block of instructions, but we actually need to check each of them provided that the reconcile loop moves forward and certain conditions are satisfied. This patch attempts to split the Eventually block so that: - Each assertion gets its own retry logic (based on timeout, interval) - Prevents early assertion failures from masking later issues This approach has been applied already to other operators (e.g. Nova) where there are many controllers trying to apply/remove finalizers to the same resource. Signed-off-by: Francesco Pantano <[email protected]>
1 parent 17d4823 commit c7eb9d4

File tree

1 file changed

+31
-5
lines changed

1 file changed

+31
-5
lines changed

test/functional/neutronapi_controller_test.go

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1633,23 +1633,49 @@ func getNeutronAPIControllerSuite(ml2MechanismDrivers []string) func() {
16331633
Eventually(func(g Gomega) {
16341634
th.SimulateJobSuccess(neutronDBSyncJobName)
16351635

1636+
neutron := GetNeutronAPI(neutronAPIName)
1637+
g.Expect(neutron.Status.LastAppliedTopology).ToNot(BeNil())
1638+
g.Expect(neutron.Status.LastAppliedTopology).To(Equal(topologyRefAlt))
1639+
1640+
}, timeout, interval).Should(Succeed())
1641+
1642+
Eventually(func(g Gomega) {
1643+
1644+
th.ExpectCondition(
1645+
neutronAPIName,
1646+
ConditionGetterFunc(NeutronAPIConditionGetter),
1647+
condition.TopologyReadyCondition,
1648+
corev1.ConditionTrue,
1649+
)
1650+
16361651
tp := infra.GetTopology(types.NamespacedName{
16371652
Name: topologyRefAlt.Name,
16381653
Namespace: topologyRefAlt.Namespace,
16391654
})
16401655
finalizers := tp.GetFinalizers()
16411656
g.Expect(finalizers).To(HaveLen(1))
1642-
neutron := GetNeutronAPI(neutronAPIName)
1643-
g.Expect(neutron.Status.LastAppliedTopology).ToNot(BeNil())
1644-
g.Expect(neutron.Status.LastAppliedTopology).To(Equal(topologyRefAlt))
16451657
g.Expect(finalizers).To(ContainElement(
16461658
fmt.Sprintf("openstack.org/neutronapi-%s", neutronAPIName.Name)))
1659+
}, timeout, interval).Should(Succeed())
1660+
1661+
Eventually(func(g Gomega) {
1662+
1663+
// Simulate deployment being ready with empty network attachments (since this test doesn't use them)
1664+
th.SimulateDeploymentReadyWithPods(neutronDeploymentName, map[string][]string{})
1665+
1666+
// Wait for neutron to be fully ready before checking topology finalizers
1667+
th.ExpectCondition(
1668+
neutronAPIName,
1669+
ConditionGetterFunc(NeutronAPIConditionGetter),
1670+
condition.ReadyCondition,
1671+
corev1.ConditionTrue,
1672+
)
16471673
// Verify the previous referenced topology has no finalizers
1648-
tp = infra.GetTopology(types.NamespacedName{
1674+
prevTopology := infra.GetTopology(types.NamespacedName{
16491675
Name: topologyRef.Name,
16501676
Namespace: topologyRef.Namespace,
16511677
})
1652-
finalizers = tp.GetFinalizers()
1678+
finalizers := prevTopology.GetFinalizers()
16531679
g.Expect(finalizers).To(BeEmpty())
16541680
}, timeout, interval).Should(Succeed())
16551681
})

0 commit comments

Comments
 (0)