Skip to content

Commit

Permalink
test: check host route when add/del a subnet
Browse files Browse the repository at this point in the history
  • Loading branch information
oilbeater committed Apr 3, 2020
1 parent b553b16 commit 370689e
Show file tree
Hide file tree
Showing 37 changed files with 5,220 additions and 3 deletions.
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ require (
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 // indirect
github.com/kelseyhightower/envconfig v1.4.0 // indirect
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
github.com/kr/pty v1.1.5 // indirect
github.com/moul/http2curl v1.0.0 // indirect
github.com/onsi/ginkgo v1.10.1
github.com/onsi/gomega v1.7.0
Expand All @@ -37,7 +36,6 @@ require (
github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a // indirect
github.com/sparrc/go-ping v0.0.0-20190613174326-4e5b6552494c
github.com/spf13/pflag v1.0.5
github.com/stretchr/objx v0.2.0 // indirect
github.com/vishvananda/netlink v1.0.0
go.uber.org/zap v1.10.0 // indirect
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 // indirect
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgrijalva/jwt-go v0.0.0-20160705203006-01aeca54ebda/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96 h1:cenwrSVm+Z7QLSV/BsnenAOcDXdX4cMv4wP0B/5QbPg=
github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96/go.mod h1:Qh8CwZgvJUkLughtfhJv5dyTYa91l1fOUCrgjqmcifM=
github.com/elazarl/goproxy v0.0.0-20170405201442-c4fc26588b6e/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc=
github.com/elazarl/goproxy v0.0.0-20190630181448-f1e96bc0f4c5 h1:Zp2QJezMfAbYc5fLiDUZ8x3vNroDxnufFCOIJjgL5tY=
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func ValidateSubnet(subnet kubeovnv1.Subnet) error {
if !CIDRContainIP(subnet.Spec.CIDRBlock, subnet.Spec.Gateway){
if !CIDRContainIP(subnet.Spec.CIDRBlock, subnet.Spec.Gateway) {
return fmt.Errorf(" gateway %s is not in cidr %s", subnet.Spec.Gateway, subnet.Spec.CIDRBlock)
}

Expand Down
47 changes: 47 additions & 0 deletions test/e2e/framework/framework.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
package framework

import (
"bytes"
"fmt"
v1 "github.com/alauda/kube-ovn/pkg/apis/kubeovn/v1"
clientset "github.com/alauda/kube-ovn/pkg/client/clientset/versioned"
"io"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/tools/remotecommand"
"strings"
"time"

Expand All @@ -20,6 +25,7 @@ type Framework struct {
KubeOvnNamespace string
KubeClientSet kubernetes.Interface
OvnClientSet clientset.Interface
KubeConfig *rest.Config
}

func NewFramework(baseName, kubeConfig string) *Framework {
Expand All @@ -29,6 +35,7 @@ func NewFramework(baseName, kubeConfig string) *Framework {
if err != nil {
panic(err.Error())
}
f.KubeConfig = cfg

cfg.QPS = 1000
cfg.Burst = 2000
Expand Down Expand Up @@ -167,6 +174,46 @@ func (f *Framework) WaitStatefulsetReady(statefulset, namespace string) error {
}
}

func (f *Framework) ExecToPodThroughAPI(command, containerName, podName, namespace string, stdin io.Reader) (string, string, error) {
req := f.KubeClientSet.CoreV1().RESTClient().Post().
Resource("pods").
Name(podName).
Namespace(namespace).
SubResource("exec")
scheme := runtime.NewScheme()
if err := corev1.AddToScheme(scheme); err != nil {
return "", "", fmt.Errorf("error adding to scheme: %v", err)
}

parameterCodec := runtime.NewParameterCodec(scheme)
req.VersionedParams(&corev1.PodExecOptions{
Command: strings.Fields(command),
Container: containerName,
Stdin: stdin != nil,
Stdout: true,
Stderr: true,
TTY: false,
}, parameterCodec)

exec, err := remotecommand.NewSPDYExecutor(f.KubeConfig, "POST", req.URL())
if err != nil {
return "", "", fmt.Errorf("error while creating Executor: %v", err)
}

var stdout, stderr bytes.Buffer
err = exec.Stream(remotecommand.StreamOptions{
Stdin: stdin,
Stdout: &stdout,
Stderr: &stderr,
Tty: false,
})
if err != nil {
return "", "", fmt.Errorf("error in Stream: %v", err)
}

return stdout.String(), stderr.String(), nil
}

const (
Running = "Running"
Pending = "Pending"
Expand Down
15 changes: 15 additions & 0 deletions test/e2e/subnet/normal.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ var _ = Describe("[Subnet]", func() {
Expect(subnet.Status.ActivateGateway).To(BeEmpty())
Expect(subnet.Status.AvailableIPs).To(Equal(uint64(65535)))
Expect(subnet.Status.UsingIPs).To(BeZero())

pods, err := f.KubeClientSet.CoreV1().Pods("kube-system").List(metav1.ListOptions{LabelSelector: "app=ovs"})
Expect(err).NotTo(HaveOccurred())
for _, pod := range pods.Items {
stdout, _, err := f.ExecToPodThroughAPI(fmt.Sprintf("ip route list root %s", subnet.Spec.CIDRBlock), "openvswitch", pod.Name, pod.Namespace, nil)
Expect(err).NotTo(HaveOccurred())
Expect(stdout).To(ContainSubstring("ovn0"))
}
})

It("centralized gateway", func() {
Expand Down Expand Up @@ -146,6 +154,13 @@ var _ = Describe("[Subnet]", func() {
err = f.OvnClientSet.KubeovnV1().Subnets().Delete(name, &metav1.DeleteOptions{})
Expect(err).NotTo(HaveOccurred())

pods, err := f.KubeClientSet.CoreV1().Pods("kube-system").List(metav1.ListOptions{LabelSelector: "app=ovs"})
Expect(err).NotTo(HaveOccurred())
for _, pod := range pods.Items {
stdout, _, err := f.ExecToPodThroughAPI("ip route", "openvswitch", pod.Name, pod.Namespace, nil)
Expect(err).NotTo(HaveOccurred())
Expect(stdout).NotTo(ContainSubstring(s.Spec.CIDRBlock))
}
})
})

Expand Down
13 changes: 13 additions & 0 deletions vendor/github.com/docker/spdystream/CONTRIBUTING.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

191 changes: 191 additions & 0 deletions vendor/github.com/docker/spdystream/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 370689e

Please sign in to comment.