Skip to content

Commit

Permalink
e2e: add underlay-veth test
Browse files Browse the repository at this point in the history
Signed-off-by: forrestchen <forrestchen@tencent.com>
  • Loading branch information
ChenLingPeng committed Apr 24, 2020
1 parent 8dda2bc commit b14d6bf
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 1 deletion.
15 changes: 15 additions & 0 deletions e2e/helper/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
13 changes: 13 additions & 0 deletions e2e/underlay/veth/veth_suite_test.go
Original file line number Diff line number Diff line change
@@ -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")
}
50 changes: 50 additions & 0 deletions e2e/underlay/veth/veth_test.go
Original file line number Diff line number Diff line change
@@ -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()
Expect(helper.SetupDummyDev("dummy0", ifaceCidr)).NotTo(HaveOccurred())
Expect(helper.SetupVlanDev("dummy0.2", "dummy0", vlanCidr, 2)).NotTo(HaveOccurred())

AfterEach(func() {
helper.CleanupNetNS()
helper.CleanupIFace("dummy0.2")
helper.CleanupDummy()
})
It("vlan", func() {
netConf := []byte(`{
"name": "myvlan",
"type": "galaxy-underlay-veth",
"device": "dummy0"
}`)
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)
})
})
2 changes: 1 addition & 1 deletion hack/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit b14d6bf

Please sign in to comment.