From 2793dd11cb5c3d826bd90458063257a8092a4141 Mon Sep 17 00:00:00 2001 From: Gabe Rosenhouse Date: Wed, 28 Feb 2018 08:59:04 -0800 Subject: [PATCH] top-level integration test coverage for ptp + bandwidth --- .travis.yml | 1 + integration/integration_linux_test.go | 88 +++++++++++++++++++ integration/integration_suite_test.go | 32 +++++++ integration/testdata/basic-ptp.json | 11 +++ .../testdata/chained-ptp-bandwidth.conflist | 22 +++++ 5 files changed, 154 insertions(+) create mode 100644 integration/integration_linux_test.go create mode 100644 integration/integration_suite_test.go create mode 100644 integration/testdata/basic-ptp.json create mode 100644 integration/testdata/chained-ptp-bandwidth.conflist diff --git a/.travis.yml b/.travis.yml index 525a9847..e6ab0e99 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,6 +21,7 @@ matrix: install: - go get github.com/onsi/ginkgo/ginkgo + - go get github.com/containernetworking/cni/cnitool script: - | diff --git a/integration/integration_linux_test.go b/integration/integration_linux_test.go new file mode 100644 index 00000000..7a8ea451 --- /dev/null +++ b/integration/integration_linux_test.go @@ -0,0 +1,88 @@ +// Copyright 2018 CNI authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package integration_test + +import ( + "fmt" + "math/rand" + "os" + "os/exec" + "path/filepath" + + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + "github.com/onsi/gomega/gexec" +) + +var _ = Describe("Basic PTP using cnitool", func() { + var ( + env TestEnv + nsShortName string + nsLongName string + cnitoolBin string + ) + + BeforeEach(func() { + cniPath, err := filepath.Abs("../bin") + Expect(err).NotTo(HaveOccurred()) + netConfPath, err := filepath.Abs("./testdata") + Expect(err).NotTo(HaveOccurred()) + cnitoolBin, err = exec.LookPath("cnitool") + Expect(err).NotTo(HaveOccurred(), "expected to find cnitool in your PATH") + + env = TestEnv([]string{ + "CNI_PATH=" + cniPath, + "NETCONFPATH=" + netConfPath, + "PATH=" + os.Getenv("PATH"), + }) + + nsShortName = fmt.Sprintf("cni-test-%x", rand.Int31()) + nsLongName = fmt.Sprintf("/var/run/netns/" + nsShortName) + }) + + It("supports basic network add and del operations", func() { + env.run("ip", "netns", "add", nsShortName) + defer env.run("ip", "netns", "del", nsShortName) + + env.run(cnitoolBin, "add", "basic-ptp", nsLongName) + + addrOutput := env.run("ip", "netns", "exec", nsShortName, "ip", "addr") + Expect(addrOutput).To(ContainSubstring("10.1.2.")) + + env.run(cnitoolBin, "del", "basic-ptp", nsLongName) + }) + + It("supports add and del with chained plugins", func() { + env.run("ip", "netns", "add", nsShortName) + defer env.run("ip", "netns", "del", nsShortName) + + env.run(cnitoolBin, "add", "chained-ptp-bandwidth", nsLongName) + + addrOutput := env.run("ip", "netns", "exec", nsShortName, "ip", "addr") + Expect(addrOutput).To(ContainSubstring("10.9.2.")) + + env.run(cnitoolBin, "del", "chained-ptp-bandwidth", nsLongName) + }) +}) + +type TestEnv []string + +func (e TestEnv) run(bin string, args ...string) string { + cmd := exec.Command(bin, args...) + cmd.Env = e + session, err := gexec.Start(cmd, GinkgoWriter, GinkgoWriter) + Expect(err).NotTo(HaveOccurred()) + Eventually(session, "5s").Should(gexec.Exit(0)) + return string(session.Out.Contents()) +} diff --git a/integration/integration_suite_test.go b/integration/integration_suite_test.go new file mode 100644 index 00000000..740b9fdb --- /dev/null +++ b/integration/integration_suite_test.go @@ -0,0 +1,32 @@ +// Copyright 2018 CNI authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package integration_test + +import ( + "math/rand" + "testing" + + . "github.com/onsi/ginkgo" + "github.com/onsi/ginkgo/config" + . "github.com/onsi/gomega" +) + +func TestIntegration(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "Integration Suite") +} + +var _ = BeforeSuite(func() { + rand.Seed(config.GinkgoConfig.RandomSeed + int64(GinkgoParallelNode())) +}) diff --git a/integration/testdata/basic-ptp.json b/integration/testdata/basic-ptp.json new file mode 100644 index 00000000..11dc3aa6 --- /dev/null +++ b/integration/testdata/basic-ptp.json @@ -0,0 +1,11 @@ +{ + "cniVersion": "0.3.0", + "name": "basic-ptp", + "type": "ptp", + "ipMasq": true, + "mtu": 512, + "ipam": { + "type": "host-local", + "subnet": "10.1.2.0/24" + } +} diff --git a/integration/testdata/chained-ptp-bandwidth.conflist b/integration/testdata/chained-ptp-bandwidth.conflist new file mode 100644 index 00000000..3919da0f --- /dev/null +++ b/integration/testdata/chained-ptp-bandwidth.conflist @@ -0,0 +1,22 @@ +{ + "cniVersion": "0.3.1", + "name": "chained-ptp-bandwidth", + "plugins": [ + { + "type": "ptp", + "ipMasq": true, + "mtu": 512, + "ipam": { + "type": "host-local", + "subnet": "10.9.2.0/24" + } + }, + { + "type": "bandwidth", + "ingressRate": 800, + "ingressBurst": 200, + "egressRate": 800, + "egressBurst": 200 + } + ] +}