From 5fd849ac6d4f7a90623e6471b25090a91ca65fa5 Mon Sep 17 00:00:00 2001 From: Michael Cambria Date: Mon, 8 Oct 2018 11:31:03 -0400 Subject: [PATCH] Use tempDir in socket path for ginkgo parallelization --- plugins/ipam/dhcp/dhcp_test.go | 36 +++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/plugins/ipam/dhcp/dhcp_test.go b/plugins/ipam/dhcp/dhcp_test.go index 101726e0..2f7d3cec 100644 --- a/plugins/ipam/dhcp/dhcp_test.go +++ b/plugins/ipam/dhcp/dhcp_test.go @@ -16,9 +16,11 @@ package main import ( "fmt" + "io/ioutil" "net" "os" "os/exec" + "path/filepath" "sync" "time" @@ -38,6 +40,15 @@ import ( . "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) { // Add the expected IP to the pool lp := memorypool.MemoryPool{} @@ -99,6 +110,10 @@ const ( pidfilePath string = "/var/run/cni/dhcp-client.pid" ) +var socketPath string +var tmpDir string +var err error + var _ = BeforeSuite(func() { os.Remove(socketPath) os.Remove(pidfilePath) @@ -107,6 +122,7 @@ var _ = BeforeSuite(func() { var _ = AfterSuite(func() { os.Remove(socketPath) os.Remove(pidfilePath) + defer os.RemoveAll(tmpDir) }) var _ = Describe("DHCP Operations", func() { @@ -118,6 +134,10 @@ var _ = Describe("DHCP Operations", func() { BeforeEach(func() { 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 var err error originalNS, err = testutils.NewNS() @@ -187,7 +207,7 @@ var _ = Describe("DHCP Operations", func() { os.MkdirAll(pidfilePath, 0755) dhcpPluginPath, err := exec.LookPath("dhcp") Expect(err).NotTo(HaveOccurred()) - clientCmd = exec.Command(dhcpPluginPath, "daemon") + clientCmd = exec.Command(dhcpPluginPath, "daemon", "-socketpath", socketPath) err = clientCmd.Start() Expect(err).NotTo(HaveOccurred()) Expect(clientCmd.Process).NotTo(BeNil()) @@ -212,14 +232,15 @@ var _ = Describe("DHCP Operations", func() { }) It("configures and deconfigures a link with ADD/DEL", func() { - conf := `{ + conf := fmt.Sprintf(`{ "cniVersion": "0.3.1", "name": "mynet", "type": "ipvlan", "ipam": { - "type": "dhcp" + "type": "dhcp", + "daemonSocketPath": "%s" } -}` +}`, socketPath) args := &skel.CmdArgs{ ContainerID: "dummy", @@ -254,14 +275,15 @@ var _ = Describe("DHCP Operations", func() { }) It("correctly handles multiple DELs for the same container", func() { - conf := `{ + conf := fmt.Sprintf(`{ "cniVersion": "0.3.1", "name": "mynet", "type": "ipvlan", "ipam": { - "type": "dhcp" + "type": "dhcp", + "daemonSocketPath": "%s" } -}` +}`, socketPath) args := &skel.CmdArgs{ ContainerID: "dummy",