Skip to content

Commit

Permalink
e2e fix: use api to abbreviate ipv6 addresses and fix subnet creation…
Browse files Browse the repository at this point in the history
… failure due to duplicate names (#2119)

Signed-off-by: ty-dc <[email protected]>
  • Loading branch information
ty-dc authored Aug 4, 2023
1 parent 853f793 commit 6dd4dcd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
12 changes: 7 additions & 5 deletions test/e2e/annotation/annotation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"context"
"encoding/json"
"fmt"
"net"
"strings"
"time"

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/common/spiderpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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{
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/common/spidersubnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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{
Expand Down

0 comments on commit 6dd4dcd

Please sign in to comment.