diff --git a/test/e2e/annotation/annotation_test.go b/test/e2e/annotation/annotation_test.go index 23fc97601e..f61125bc3e 100644 --- a/test/e2e/annotation/annotation_test.go +++ b/test/e2e/annotation/annotation_test.go @@ -6,6 +6,7 @@ import ( "context" "encoding/json" "fmt" + "net" "strings" "time" @@ -642,9 +643,10 @@ var _ = Describe("test annotation", Label("annotation"), func() { if frame.Info.IpV6Enabled { // The ipv6 address on the network interface will be abbreviated. For example fd00:0c3d::2 becomes fd00:c3d::2. // Abbreviate the expected ipv6 address and use it in subsequent assertions. - ipv6Dst = strings.Replace(ipv6Dst, ":0", ":", -1) - ipv6Gw = strings.Replace(ipv6Gw, ":0", ":", -1) - command := fmt.Sprintf("ip -6 r | grep '%s via %s'", ipv6Dst, ipv6Gw) + _, ipv6Dst, err := net.ParseCIDR(ipv6Dst) + Expect(err).NotTo(HaveOccurred()) + ipv6Gw := net.ParseIP(ipv6Gw) + command := fmt.Sprintf("ip -6 r | grep '%s via %s'", ipv6Dst.String(), ipv6Gw.String()) ctx, cancel := context.WithTimeout(context.Background(), common.ExecCommandTimeout) defer cancel() out, err := frame.ExecCommandInPod(podName, nsName, command, ctx) @@ -754,8 +756,8 @@ var _ = Describe("test annotation", Label("annotation"), func() { if frame.Info.IpV6Enabled { // The ipv6 address on the network interface will be abbreviated. For example fd00:0c3d::2 becomes fd00:c3d::2. // Abbreviate the expected ipv6 address and use it in subsequent assertions. - ipv6Addr := strings.Replace(v6Pool.Spec.IPs[0], ":0", ":", -1) - command := fmt.Sprintf("ip -6 a show '%s' | grep '%s'", common.NIC2, ipv6Addr) + ipv6Addr := net.ParseIP(v6Pool.Spec.IPs[0]) + command := fmt.Sprintf("ip -6 a show '%s' | grep '%s'", common.NIC2, ipv6Addr.String()) ctx, cancel := context.WithTimeout(context.Background(), common.ExecCommandTimeout) defer cancel() errOut, err := frame.ExecCommandInPod(podName, nsName, command, ctx) diff --git a/test/e2e/common/spiderpool.go b/test/e2e/common/spiderpool.go index 2131ef3b34..e4f5a80817 100644 --- a/test/e2e/common/spiderpool.go +++ b/test/e2e/common/spiderpool.go @@ -435,7 +435,7 @@ func GenerateExampleIpv4poolObject(ipNum int) (string, *v1.SpiderIPPool) { } var v4Ipversion = new(types.IPVersion) *v4Ipversion = constant.IPv4 - var v4PoolName string = "v4pool-" + tools.RandomName() + var v4PoolName string = "v4pool-" + GenerateString(15, true) var randomNumber1 string = GenerateRandomNumber(255) var randomNumber2 string = GenerateRandomNumber(255) @@ -473,7 +473,7 @@ func GenerateExampleIpv6poolObject(ipNum int) (string, *v1.SpiderIPPool) { var v6Ipversion = new(types.IPVersion) *v6Ipversion = constant.IPv6 - var v6PoolName string = "v6pool-" + tools.RandomName() + var v6PoolName string = "v6pool-" + GenerateString(15, true) var randomNumber string = GenerateString(4, true) iPv6PoolObj := &v1.SpiderIPPool{ diff --git a/test/e2e/common/spidersubnet.go b/test/e2e/common/spidersubnet.go index 0a715e88ba..0c200d21b0 100644 --- a/test/e2e/common/spidersubnet.go +++ b/test/e2e/common/spidersubnet.go @@ -37,7 +37,7 @@ func GenerateExampleV4SubnetObject(ipNum int) (string, *spiderpool.SpiderSubnet) GinkgoWriter.Println("the IP range should be between 1 and 65533") Fail("the IP range should be between 1 and 65533") } - subnetName := "v4-ss-" + tools.RandomName() + subnetName := "v4-ss-" + GenerateString(15, true) randNum1 := GenerateRandomNumber(255) randNum2 := GenerateRandomNumber(255) @@ -76,7 +76,7 @@ func GenerateExampleV6SubnetObject(ipNum int) (string, *spiderpool.SpiderSubnet) Fail("the IP range should be between 1 and 65533") } - subnetName := "v6-ss-" + tools.RandomName() + subnetName := "v6-ss-" + GenerateString(15, true) randNum := GenerateString(4, true) subnetObj := &spiderpool.SpiderSubnet{ ObjectMeta: metav1.ObjectMeta{