nsPath := filepath.Join(tempDir, "namespace")
			nsFile, err := os.Create(nsPath)
			Expect(err).NotTo(HaveOccurred())
			nsFile.Close()

			ns = namespace.NewNamespace(nsPath)
		})

		AfterEach(func() {
			os.RemoveAll(tempDir)
		})

		It("returns an open file representing the namesapce", func() {
			f, err := ns.Open()
			Expect(err).NotTo(HaveOccurred())
			Expect(f.Name()).To(Equal(ns.Path()))
			f.Close()
		})

		Context("when open fails", func() {
			BeforeEach(func() {
				err := os.Remove(ns.Path())
				Expect(err).NotTo(HaveOccurred())
			})

			It("returns the error from open", func() {
				_, err := ns.Open()
				Expect(err).To(HaveOccurred())
			})
		})
	})
Esempio n. 2
0
	var execCNI = func(operation string, netConfig Config, containerNS namespace.Namespace,
		containerID, sandboxRepoDir string) {

		sandboxNS = namespace.NewNamespace(filepath.Join(sandboxRepoDir, fmt.Sprintf("vni-%d", vni)))

		input, err := json.Marshal(netConfig)
		Expect(err).NotTo(HaveOccurred())

		cmd := exec.Command(pathToVxlan)
		cmd.Stdin = bytes.NewReader(input)
		cmd.Env = append(
			os.Environ(),
			fmt.Sprintf("CNI_COMMAND=%s", operation),
			fmt.Sprintf("CNI_CONTAINERID=%s", containerID),
			fmt.Sprintf("CNI_PATH=%s", cniPath),
			fmt.Sprintf("CNI_NETNS=%s", containerNS.Path()),
			fmt.Sprintf("CNI_IFNAME=%s", "vx-eth0"),
			fmt.Sprintf("DUCATI_OS_SANDBOX_REPO=%s", sandboxRepoDir),
		)

		session, err = gexec.Start(cmd, GinkgoWriter, GinkgoWriter)
		Expect(err).NotTo(HaveOccurred())
	}

	AfterEach(func() {
		containerNS.Destroy()
		sandboxNS.Destroy()
		os.RemoveAll(repoDir)
	})

	Describe("ADD", func() {