Use tempDir in socket path for ginkgo parallelization

This commit is contained in:
Michael Cambria 2018-10-08 11:31:03 -04:00
parent 6d3215a256
commit 5fd849ac6d

View File

@ -16,9 +16,11 @@ package main
import ( import (
"fmt" "fmt"
"io/ioutil"
"net" "net"
"os" "os"
"os/exec" "os/exec"
"path/filepath"
"sync" "sync"
"time" "time"
@ -38,6 +40,15 @@ import (
. "github.com/onsi/gomega" . "github.com/onsi/gomega"
) )
func getTmpDir() (string, error) {
tmpDir, err := ioutil.TempDir("/run/cni", "dhcp")
if err == nil {
tmpDir = filepath.ToSlash(tmpDir)
}
return tmpDir, err
}
func dhcpServerStart(netns ns.NetNS, leaseIP, serverIP net.IP, stopCh <-chan bool) (*sync.WaitGroup, error) { func dhcpServerStart(netns ns.NetNS, leaseIP, serverIP net.IP, stopCh <-chan bool) (*sync.WaitGroup, error) {
// Add the expected IP to the pool // Add the expected IP to the pool
lp := memorypool.MemoryPool{} lp := memorypool.MemoryPool{}
@ -99,6 +110,10 @@ const (
pidfilePath string = "/var/run/cni/dhcp-client.pid" pidfilePath string = "/var/run/cni/dhcp-client.pid"
) )
var socketPath string
var tmpDir string
var err error
var _ = BeforeSuite(func() { var _ = BeforeSuite(func() {
os.Remove(socketPath) os.Remove(socketPath)
os.Remove(pidfilePath) os.Remove(pidfilePath)
@ -107,6 +122,7 @@ var _ = BeforeSuite(func() {
var _ = AfterSuite(func() { var _ = AfterSuite(func() {
os.Remove(socketPath) os.Remove(socketPath)
os.Remove(pidfilePath) os.Remove(pidfilePath)
defer os.RemoveAll(tmpDir)
}) })
var _ = Describe("DHCP Operations", func() { var _ = Describe("DHCP Operations", func() {
@ -118,6 +134,10 @@ var _ = Describe("DHCP Operations", func() {
BeforeEach(func() { BeforeEach(func() {
dhcpServerStopCh = make(chan bool) dhcpServerStopCh = make(chan bool)
tmpDir, err = getTmpDir()
Expect(err).NotTo(HaveOccurred())
socketPath = filepath.Join(tmpDir, "dhcp.sock")
// Create a new NetNS so we don't modify the host // Create a new NetNS so we don't modify the host
var err error var err error
originalNS, err = testutils.NewNS() originalNS, err = testutils.NewNS()
@ -187,7 +207,7 @@ var _ = Describe("DHCP Operations", func() {
os.MkdirAll(pidfilePath, 0755) os.MkdirAll(pidfilePath, 0755)
dhcpPluginPath, err := exec.LookPath("dhcp") dhcpPluginPath, err := exec.LookPath("dhcp")
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
clientCmd = exec.Command(dhcpPluginPath, "daemon") clientCmd = exec.Command(dhcpPluginPath, "daemon", "-socketpath", socketPath)
err = clientCmd.Start() err = clientCmd.Start()
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(clientCmd.Process).NotTo(BeNil()) Expect(clientCmd.Process).NotTo(BeNil())
@ -212,14 +232,15 @@ var _ = Describe("DHCP Operations", func() {
}) })
It("configures and deconfigures a link with ADD/DEL", func() { It("configures and deconfigures a link with ADD/DEL", func() {
conf := `{ conf := fmt.Sprintf(`{
"cniVersion": "0.3.1", "cniVersion": "0.3.1",
"name": "mynet", "name": "mynet",
"type": "ipvlan", "type": "ipvlan",
"ipam": { "ipam": {
"type": "dhcp" "type": "dhcp",
"daemonSocketPath": "%s"
} }
}` }`, socketPath)
args := &skel.CmdArgs{ args := &skel.CmdArgs{
ContainerID: "dummy", ContainerID: "dummy",
@ -254,14 +275,15 @@ var _ = Describe("DHCP Operations", func() {
}) })
It("correctly handles multiple DELs for the same container", func() { It("correctly handles multiple DELs for the same container", func() {
conf := `{ conf := fmt.Sprintf(`{
"cniVersion": "0.3.1", "cniVersion": "0.3.1",
"name": "mynet", "name": "mynet",
"type": "ipvlan", "type": "ipvlan",
"ipam": { "ipam": {
"type": "dhcp" "type": "dhcp",
"daemonSocketPath": "%s"
} }
}` }`, socketPath)
args := &skel.CmdArgs{ args := &skel.CmdArgs{
ContainerID: "dummy", ContainerID: "dummy",