Skip to content

Commit

Permalink
fix e2e testing
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangzujian committed Sep 10, 2021
1 parent 6505e2e commit a5791a0
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 72 deletions.
4 changes: 3 additions & 1 deletion test/e2e-vlan-single-nic/e2e_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

"github.com/kubeovn/kube-ovn/test/e2e/framework"

// tests to run
_ "github.com/kubeovn/kube-ovn/test/e2e-vlan-single-nic/kubectl-ko"
_ "github.com/kubeovn/kube-ovn/test/e2e-vlan-single-nic/node"
"github.com/kubeovn/kube-ovn/test/e2e/framework"
)

func TestE2e(t *testing.T) {
Expand Down
45 changes: 25 additions & 20 deletions test/e2e-vlan-single-nic/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type nodeNetwork struct {
MacAddress string
}

var _ = Describe("[Vlan Node]", func() {
var _ = Describe("[Underlay Node]", func() {
f := framework.NewFramework("node", fmt.Sprintf("%s/.kube/config", os.Getenv("HOME")))

var network *nodeNetwork
Expand All @@ -49,30 +49,33 @@ var _ = Describe("[Vlan Node]", func() {
Expect(nodes).NotTo(BeNil())
Expect(len(nodes.Items)).NotTo(BeZero())

nodeIPs := make([]string, 0, len(nodes.Items))
nodeRoutes := make([]string, 0, len(nodes.Items))
nodeIPs := make([]string, 0, len(nodes.Items)*2)
nodeRoutes := make([]string, 0, len(nodes.Items)*4)
if network != nil {
if network.IPAddress != "" {
nodeIPs = append(nodeIPs, fmt.Sprintf("%s/%d", network.IPAddress, network.IPPrefixLen))
addr := fmt.Sprintf("%s/%d", network.IPAddress, network.IPPrefixLen)
nodeIPs = append(nodeIPs, addr)
_, ipnet, err := net.ParseCIDR(addr)
Expect(err).NotTo(HaveOccurred())
nodeRoutes = append(nodeRoutes, fmt.Sprintf("%s ", ipnet.String()))
}
if network.GlobalIPv6Address != "" {
nodeIPs = append(nodeIPs, fmt.Sprintf("%s/%d", network.GlobalIPv6Address, network.GlobalIPv6PrefixLen))
addr := fmt.Sprintf("%s/%d", network.GlobalIPv6Address, network.GlobalIPv6PrefixLen)
nodeIPs = append(nodeIPs, addr)
_, ipnet, err := net.ParseCIDR(addr)
Expect(err).NotTo(HaveOccurred())
nodeRoutes = append(nodeRoutes, fmt.Sprintf("%s ", ipnet.String()))
}
if network.Gateway != "" {
nodeRoutes = append(nodeRoutes, fmt.Sprintf("default via %s ", network.Gateway))
}
if network.IPv6Gateway != "" {
nodeRoutes = append(nodeRoutes, fmt.Sprintf("default via %s ", network.Gateway))
nodeRoutes = append(nodeRoutes, fmt.Sprintf("default via %s ", network.IPv6Gateway))
}
} else {
for _, node := range nodes.Items {
if node.Name == "kube-ovn-control-plane" {
for _, addr := range node.Status.Addresses {
if addr.Type == corev1.NodeInternalIP {
nodeIPs = append(nodeIPs, addr.Address+"/")
break
}
}
nodeIPs = append(nodeIPs, util.GetNodeInternalIP(node)+"/")
break
}
}
Expand Down Expand Up @@ -100,31 +103,33 @@ var _ = Describe("[Vlan Node]", func() {
stdout, _, err := f.ExecToPodThroughAPI("ovs-vsctl list-ports "+vlanBr, "openvswitch", ovsPod.Name, ovsPod.Namespace, nil)
Expect(err).NotTo(HaveOccurred())

var portFound bool
var found bool
for _, port := range strings.Split(stdout, "\n") {
if port == vlanNic {
portFound = true
found = true
break
}
}
Expect(portFound).To(BeTrue())
Expect(found).To(BeTrue())

stdout, _, err = f.ExecToPodThroughAPI("ip addr show "+vlanBr, "openvswitch", ovsPod.Name, ovsPod.Namespace, nil)
Expect(err).NotTo(HaveOccurred())
Expect(stdout).NotTo(BeEmpty())

var isUp bool
ipFound := make([]bool, len(nodeIPs))
for i, s := range strings.Split(stdout, "\n") {
if i == 0 {
var linkUp bool
idx1, idx2 := strings.IndexRune(s, '<'), strings.IndexRune(s, '>')
if idx1 > 0 && idx2 > idx1+1 {
for _, state := range strings.Split(s[idx1+1:idx2], ",") {
if state == "UP" {
isUp = true
linkUp = true
break
}
}
}
Expect(linkUp).To(BeTrue())
continue
}
if i == 1 && network != nil && network.MacAddress != "" {
Expand All @@ -140,13 +145,13 @@ var _ = Describe("[Vlan Node]", func() {
}
}
}
Expect(isUp).To(BeTrue())
for _, found := range ipFound {
Expect(found).To(BeTrue())
}

stdout, _, err = f.ExecToPodThroughAPI("ip addr show "+vlanNic, "openvswitch", ovsPod.Name, ovsPod.Namespace, nil)
Expect(err).NotTo(HaveOccurred())
Expect(stdout).NotTo(BeEmpty())

var hasAddr bool
for _, s := range strings.Split(stdout, "\n") {
Expand All @@ -164,7 +169,7 @@ var _ = Describe("[Vlan Node]", func() {
}
Expect(hasAddr).To(BeFalse())

stdout, _, err = f.ExecToPodThroughAPI("ip route show dev "+vlanBr, "openvswitch", ovsPod.Name, ovsPod.Namespace, nil)
stdout, _, err = f.ExecToPodThroughAPI("ip -4 route show dev "+vlanBr, "openvswitch", ovsPod.Name, ovsPod.Namespace, nil)
Expect(err).NotTo(HaveOccurred())
routes := strings.Split(stdout, "\n")

Expand All @@ -185,7 +190,7 @@ var _ = Describe("[Vlan Node]", func() {
Expect(found).To(BeTrue())
}

stdout, _, err = f.ExecToPodThroughAPI("ip route show dev "+vlanNic, "openvswitch", ovsPod.Name, ovsPod.Namespace, nil)
stdout, _, err = f.ExecToPodThroughAPI("ip -4 route show dev "+vlanNic, "openvswitch", ovsPod.Name, ovsPod.Namespace, nil)
Expect(err).NotTo(HaveOccurred())
Expect(strings.TrimSpace(stdout)).To(BeEmpty())

Expand Down
6 changes: 3 additions & 3 deletions test/e2e/e2e_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"os"
"testing"
"time"

kubeovn "github.com/kubeovn/kube-ovn/pkg/apis/kubeovn/v1"
"github.com/kubeovn/kube-ovn/test/e2e/framework"
Expand Down Expand Up @@ -202,6 +203,8 @@ var _ = SynchronizedBeforeSuite(func() []byte {
if err = f.WaitProviderNetworkReady(pn.Name); err != nil {
Fail("provider network failed: " + err.Error())
}
// FIXME: wait 3 seconds to ensure node conditions are up to date
time.Sleep(3 * time.Second)
if pn, err = f.OvnClientSet.KubeovnV1().ProviderNetworks().Get(context.Background(), pn.Name, metav1.GetOptions{}); err != nil {
Fail("failed to get provider network: " + err.Error())
}
Expand All @@ -225,9 +228,6 @@ var _ = SynchronizedBeforeSuite(func() []byte {
if _, err = f.OvnClientSet.KubeovnV1().Vlans().Create(context.Background(), &vlan, metav1.CreateOptions{}); err != nil {
Fail("failed to create vlan: " + err.Error())
}
if err = f.WaitProviderNetworkReady(pn.Name); err != nil {
Fail("provider network failed: " + err.Error())
}

// create subnet
subnet := kubeovn.Subnet{
Expand Down
7 changes: 4 additions & 3 deletions test/e2e/framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/tools/remotecommand"
"k8s.io/klog"

. "github.com/onsi/ginkgo"

Expand Down Expand Up @@ -112,7 +113,7 @@ func (f *Framework) WaitPodReady(pod, namespace string) (*corev1.Pod, error) {
case Initing, Pending, PodInitializing, ContainerCreating, Terminating:
continue
default:
fmt.Printf("%v", p.String())
klog.Info(p.String())
return nil, fmt.Errorf("pod status failed")
}
}
Expand Down Expand Up @@ -161,7 +162,7 @@ func (f *Framework) WaitDeploymentReady(deployment, namespace string) error {
case Initing, Pending, PodInitializing, ContainerCreating, Terminating:
ready = false
default:
fmt.Printf("%v", pod.String())
klog.Info(pod.String())
return fmt.Errorf("pod status failed")
}
}
Expand Down Expand Up @@ -197,7 +198,7 @@ func (f *Framework) WaitStatefulsetReady(statefulset, namespace string) error {
case Initing, Pending, PodInitializing, ContainerCreating, Terminating:
ready = false
default:
fmt.Printf("%v", pod.String())
klog.Info(pod.String())
return fmt.Errorf("pod status failed")
}
}
Expand Down

0 comments on commit a5791a0

Please sign in to comment.