Create a plugin for up'ing a lo device
- Believe we need sudo to create netns - Use syscall instead of relying on ip netns - Add sudo to .travis.yml - Needs more -E - Revert Godeps GoVersion to 1.4.2 - in travis, test command is run with all necessary env vars - Loopback plugin only works on 'lo' interface - Update README, add loopback plugin config - note script dependency on jq Signed-off-by: Gabe Rosenhouse <grosenhouse@pivotal.io>
This commit is contained in:

committed by
zachgersh

parent
ebd5be8475
commit
2708bdf2f5
58
plugins/main/loopback/loopback_suite_test.go
Normal file
58
plugins/main/loopback/loopback_suite_test.go
Normal file
@ -0,0 +1,58 @@
|
||||
package main_test
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/onsi/gomega/gexec"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
"testing"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
var pathToLoPlugin string
|
||||
|
||||
func TestLoopback(t *testing.T) {
|
||||
RegisterFailHandler(Fail)
|
||||
RunSpecs(t, "Loopback Suite")
|
||||
}
|
||||
|
||||
var _ = BeforeSuite(func() {
|
||||
var err error
|
||||
pathToLoPlugin, err = gexec.Build("github.com/appc/cni/plugins/main/loopback")
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
})
|
||||
|
||||
var _ = AfterSuite(func() {
|
||||
gexec.CleanupBuildArtifacts()
|
||||
})
|
||||
|
||||
func makeNetworkNS(containerID string) string {
|
||||
namespace := "/var/run/netns/" + containerID
|
||||
|
||||
err := os.MkdirAll("/var/run/netns", 0600)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
err = unix.Unshare(unix.CLONE_NEWNET)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
fd, err := os.Create(namespace)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
defer fd.Close()
|
||||
|
||||
err = unix.Mount("/proc/self/ns/net", namespace, "none", unix.MS_BIND, "")
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
Expect(namespace).To(BeAnExistingFile())
|
||||
return namespace
|
||||
}
|
||||
|
||||
func removeNetworkNS(networkNS string) error {
|
||||
err := unix.Unmount(networkNS, unix.MNT_DETACH)
|
||||
|
||||
err = os.RemoveAll(networkNS)
|
||||
return err
|
||||
}
|
Reference in New Issue
Block a user