From f66aa0839319b44083f8caa108e4b652a0fbad9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sima=CC=83o=20Reis?= Date: Mon, 1 Jul 2019 17:44:09 +0000 Subject: [PATCH] tests: Cleanup ingress even if test fails MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Simão Reis --- test/e2e/framework/pool.go | 13 +++++++++---- test/e2e/ingress_test.go | 10 ++++++---- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/test/e2e/framework/pool.go b/test/e2e/framework/pool.go index f8c4dc1..67f16e0 100644 --- a/test/e2e/framework/pool.go +++ b/test/e2e/framework/pool.go @@ -17,10 +17,15 @@ func (f *Framework) DeleteEdgeLBPool(pool *models.V2Pool) { defer fn() err := f.EdgeLBManager.DeletePool(ctx, pool.Name) Expect(err).NotTo(HaveOccurred(), "failed to delete edgelb pool %q", pool.Name) - // Wait for the EdgeLB API server to stop reporting the EdgeLB pool as existing. - err = retry.WithTimeout(DefaultRetryTimeout, DefaultRetryInterval, func() (b bool, e error) { - ctx, fn := context.WithTimeout(context.Background(), DefaultEdgeLBOperationTimeout) - defer fn() + f.WaitEdgeLBPoolDelete(pool) +} + +// WaitEdgeLBPoolDelete waits for the EdgeLB API server to stop reporting the +// EdgeLB pool as existing. +func (f *Framework) WaitEdgeLBPoolDelete(pool *models.V2Pool) { + err := retry.WithTimeout(DefaultRetryTimeout, DefaultRetryInterval, func() (b bool, e error) { + ctx, cancel := context.WithTimeout(context.Background(), DefaultEdgeLBOperationTimeout) + defer cancel() _, err := f.EdgeLBManager.GetPool(ctx, pool.Name) return dklberrors.IsNotFound(err), nil }) diff --git a/test/e2e/ingress_test.go b/test/e2e/ingress_test.go index 97113c0..3ac3177 100644 --- a/test/e2e/ingress_test.go +++ b/test/e2e/ingress_test.go @@ -1189,6 +1189,12 @@ hBHIkVstxMO9c4ZCA60QbQ== } }) Expect(err).NotTo(HaveOccurred(), "failed to create ingress") + // Manually delete the Ingress resource regardless of test result. + defer func() { + err = f.KubeClient.ExtensionsV1beta1().Ingresses(ingress.Namespace).Delete(ingress.Name, metav1.NewDeleteOptions(0)) + Expect(err).NotTo(HaveOccurred(), "failed to delete ingress %q", kubernetes.Key(ingress)) + f.WaitEdgeLBPoolDelete(pool) + }() // Wait for EdgeLB to acknowledge the EdgeLB pool's creation. err = retry.WithTimeout(framework.DefaultRetryTimeout, framework.DefaultRetryInterval, func() (bool, error) { @@ -1246,10 +1252,6 @@ hBHIkVstxMO9c4ZCA60QbQ== return r.StatusCode == 200, nil }) Expect(err).NotTo(HaveOccurred(), "timed out while waiting for the ingress to be reachable") - - // Manually delete the Ingress resource now so that the target EdgeLB pool isn't left dangling after namespace deletion. - err = f.KubeClient.ExtensionsV1beta1().Ingresses(ingress.Namespace).Delete(ingress.Name, metav1.NewDeleteOptions(0)) - Expect(err).NotTo(HaveOccurred(), "failed to delete ingress %q", kubernetes.Key(ingress)) }) }) })