Expect(info.IsDir()).To(BeTrue())
			})
		})
	})

	Describe("Create", func() {
		var repo namespace.Repository

		BeforeEach(func() {
			var err error
			repo, err = namespace.NewRepository(repoDir)
			Expect(err).NotTo(HaveOccurred())
		})

		It("creates a namespace in the repository", func() {
			ns, err := repo.Create("test-ns")
			Expect(err).NotTo(HaveOccurred())
			Expect(ns.Name()).To(Equal("test-ns"))

			nsPath := filepath.Join(repoDir, "test-ns")
			defer unix.Unmount(nsPath, unix.MNT_DETACH)

			var repoStat unix.Stat_t
			err = unix.Stat(nsPath, &repoStat)
			Expect(err).NotTo(HaveOccurred())

			var namespaceInode string
			callback := func(_ *os.File) error {
				// Stat of "/proc/self/ns/net" seemed to be flakey
				output, err := exec.Command("stat", "-L", "-c", "%i", "/proc/self/ns/net").CombinedOutput()
				namespaceInode = strings.TrimSpace(string(output))
Ejemplo n.º 2
0
		containerNS   namespace.Namespace
		sandboxNS     namespace.Namespace
		namespaceRepo namespace.Repository

		sandboxRepoDir string
	)

	BeforeEach(func() {
		var err error
		repoDir, err = ioutil.TempDir("", "vxlan")
		Expect(err).NotTo(HaveOccurred())

		namespaceRepo, err = namespace.NewRepository(repoDir)
		Expect(err).NotTo(HaveOccurred())

		containerNS, err = namespaceRepo.Create("container-ns")
		Expect(err).NotTo(HaveOccurred())

		sandboxRepoDir, err = ioutil.TempDir("", "sandbox")
		Expect(err).NotTo(HaveOccurred())

		containerID = "guid-1"

		netConfig = Config{
			Name:        "test-network",
			Type:        "vxlan",
			Network:     "192.168.1.0/24",
			HostNetwork: "10.99.0.0/24",
			IPAM: IPAM{
				Type:   "host-local",
				Subnet: "192.168.1.0/24",