From d2ece795c338454cdb90b8ef552ddef2cc7fb47f Mon Sep 17 00:00:00 2001 From: bzsuni Date: Tue, 1 Aug 2023 18:35:15 +0800 Subject: [PATCH] add retry in func UpdateEgressGateway Signed-off-by: bzsuni --- test/e2e/common/egressgateway.go | 17 +++++++++++++++-- test/e2e/egressgateway/egressgateway_test.go | 12 ++++-------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/test/e2e/common/egressgateway.go b/test/e2e/common/egressgateway.go index cb71087a4..47bd86ed9 100644 --- a/test/e2e/common/egressgateway.go +++ b/test/e2e/common/egressgateway.go @@ -48,8 +48,21 @@ func DeleteEgressGateway(f *framework.Framework, gateway *egressv1beta1.EgressGa return f.DeleteResource(gateway, opts...) } -func UpdateEgressGateway(f *framework.Framework, gateway *egressv1beta1.EgressGateway, opts ...client.UpdateOption) error { - return f.UpdateResource(gateway, opts...) +func UpdateEgressGateway(f *framework.Framework, gateway *egressv1beta1.EgressGateway, retry int, opts ...client.UpdateOption) error { + eg := new(egressv1beta1.EgressGateway) + for i := 0; i < retry; i++ { + err := GetEgressGateway(f, gateway.Name, eg) + if err != nil { + return err + } + gateway.ResourceVersion = eg.ResourceVersion + err = f.UpdateResource(gateway, opts...) + if err == nil { + return nil + } + time.Sleep(time.Second) + } + return ERR_TIMEOUT } // DeleteEgressGatewayIfExists delete egressGateway if its exists diff --git a/test/e2e/egressgateway/egressgateway_test.go b/test/e2e/egressgateway/egressgateway_test.go index 3588bae7e..3c3dac659 100644 --- a/test/e2e/egressgateway/egressgateway_test.go +++ b/test/e2e/egressgateway/egressgateway_test.go @@ -178,40 +178,36 @@ var _ = Describe("Operate egressGateway", Label("egressGateway"), func() { } }, Entry("Failed when add invalid `IP` to `Ippools`", Label("G00009"), false, func() error { - Expect(common.GetEgressGateway(f, name, eg)).NotTo(HaveOccurred()) if enableV4 { eg.Spec.Ippools.IPv4 = append(eg.Spec.Ippools.IPv4, invalidIPv4) } if enableV6 { eg.Spec.Ippools.IPv6 = append(eg.Spec.Ippools.IPv6, invalidIPv6) } - return common.UpdateEgressGateway(f, eg) + return common.UpdateEgressGateway(f, eg, 3) }), Entry("Succeeded when add valid `IP` to `Ippools`", Label("G00012", "G00013"), true, func() error { - Expect(common.GetEgressGateway(f, name, eg)).NotTo(HaveOccurred()) if enableV4 { eg.Spec.Ippools.IPv4 = append(eg.Spec.Ippools.IPv4, singleIpv4Pool...) } if enableV6 { eg.Spec.Ippools.IPv6 = append(eg.Spec.Ippools.IPv6, singleIpv6Pool...) } - return common.UpdateEgressGateway(f, eg) + return common.UpdateEgressGateway(f, eg, 3) }), Entry("Failed when delete `IP` that being used", Label("G00010"), false, func() error { - Expect(common.GetEgressGateway(f, name, eg)).NotTo(HaveOccurred()) if enableV4 { eg.Spec.Ippools.IPv4 = tools.RemoveValueFromSlice(eg.Spec.Ippools.IPv4, v4DefaultEip) } if enableV6 { eg.Spec.Ippools.IPv6 = tools.RemoveValueFromSlice(eg.Spec.Ippools.IPv6, v6DefaultEip) } - return common.UpdateEgressGateway(f, eg) + return common.UpdateEgressGateway(f, eg, 3) }), Entry("Failed when add different number of ip to `Ippools.IPv4` and `Ippools.IPv6`", Label("G00011"), false, func() error { - Expect(common.GetEgressGateway(f, name, eg)).NotTo(HaveOccurred()) if enableV4 && enableV6 { eg.Spec.Ippools.IPv4 = append(eg.Spec.Ippools.IPv4, singleIpv4Pool...) - return common.UpdateEgressGateway(f, eg) + return common.UpdateEgressGateway(f, eg, 3) } return ErrNotNeed }),