diff --git a/e2e/helper/util.go b/e2e/helper/util.go index ffb13170..accfe8ba 100644 --- a/e2e/helper/util.go +++ b/e2e/helper/util.go @@ -126,6 +126,21 @@ func SetupDummyDev(ifName, cidr string) error { return nil } +func SetupVlanDev(ifName, parent, cidr string, vlanID int) error { + if out, err := Command("ip", "link", "add", "link",parent, "name", ifName, "type", "vlan", "id", fmt.Sprintf("%d", vlanID)).CombinedOutput(); err != nil { + if !strings.HasPrefix(string(out), "RTNETLINK answers: File exists") { + return fmt.Errorf("failed to add link %s: %v, %s", ifName, err, string(out)) + } + } + if out, err := Command("ip", "address", "add", cidr, "dev", ifName).CombinedOutput(); err != nil { + return fmt.Errorf("failed to add address %s to %s: %v, %s", cidr, ifName, err, out) + } + if out, err := Command("ip", "link", "set", ifName, "up").CombinedOutput(); err != nil { + return fmt.Errorf("failed to set up %s: %v, %s", ifName, err, out) + } + return nil +} + func IPInfo(cidr string, vlan uint16) (string, error) { _, ipNet, err := net.ParseCIDR(cidr) if err != nil { diff --git a/e2e/underlay/veth/veth_suite_test.go b/e2e/underlay/veth/veth_suite_test.go new file mode 100644 index 00000000..a0f11426 --- /dev/null +++ b/e2e/underlay/veth/veth_suite_test.go @@ -0,0 +1,13 @@ +package veth_test + +import ( + "testing" + + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" +) + +func TestUnderlayVeth(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "Underlay-Veth Suite") +} diff --git a/e2e/underlay/veth/veth_test.go b/e2e/underlay/veth/veth_test.go new file mode 100644 index 00000000..d8a05776 --- /dev/null +++ b/e2e/underlay/veth/veth_test.go @@ -0,0 +1,50 @@ +package veth + +import ( + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + "tkestack.io/galaxy/e2e/helper" + "tkestack.io/galaxy/pkg/utils" +) + +var _ = Describe("galaxy-underlay-veth vlan test", func() { + cni := "galaxy-underlay-veth" + ifaceCidr := "192.168.0.66/26" + vlanCidr := "192.168.2.68/26" + containerCidr := "192.168.0.69/26" + containerId := helper.NewContainerId() + + AfterEach(func() { + helper.CleanupNetNS() + helper.CleanupIFace("dummy0.2") + helper.CleanupDummy() + }) + It("vlan", func() { + netConf := []byte(`{ + "name": "myvlan", + "type": "galaxy-underlay-veth", + "device": "dummy0" +}`) + Expect(helper.SetupDummyDev("dummy0", ifaceCidr)).NotTo(HaveOccurred()) + Expect(helper.SetupVlanDev("dummy0.2", "dummy0", vlanCidr, 2)).NotTo(HaveOccurred()) + argsStr, err := helper.IPInfo(containerCidr, 2) + Expect(err).NotTo(HaveOccurred()) + nsPath := helper.CmdAdd(containerId, "", argsStr, cni, + `{"cniVersion":"0.2.0","ip4":{"ip":"192.168.0.69/26","gateway":"192.168.0.65","routes":[{"dst":"0.0.0.0/0"}]},"dns":{}}`, netConf) + _, err = helper.Ping("192.168.0.68") + Expect(err).To(HaveOccurred()) + + err = (&helper.NetworkTopology{ + LeaveDevices: []*helper.LinkDevice{ + helper.NewLinkDevice(nil, utils.HostVethName(containerId, ""), "veth"), + }, + }).Verify() + Expect(err).To(HaveOccurred()) + + // check container iface topology, route, neigh, ip address is expected + helper.CheckContainerTopology(nsPath, containerCidr, "192.168.0.65") + + // test DEL command + helper.CmdDel(containerId, cni, netConf) + }) +}) diff --git a/hack/test.sh b/hack/test.sh index cff88a64..d30bee2a 100755 --- a/hack/test.sh +++ b/hack/test.sh @@ -11,6 +11,6 @@ echo PATH=$PATH export GOOS=linux go test -coverpkg $PKG/pkg/... -coverprofile=coverage.txt -covermode=atomic -v ./tools/... ./cmd/... ./cni/... ./pkg/... # go tool cover -func=coverage.txt -for i in e2e/k8s-vlan e2e/veth e2e/cni-request; do +for i in e2e/k8s-vlan e2e/veth e2e/cni-request e2e/underlay/veth; do ginkgo -v $i done