コード例 #1
0
ファイル: rootfs_test.go プロジェクト: cloudfoundry/guardian
	AfterEach(func() {
		if container != nil {
			Expect(client.Destroy(container.Handle())).To(Succeed())
		}
	})

	Context("without a default rootfs", func() {
		BeforeEach(func() {
			supplyDefaultRootfs = false
		})

		It("fails if a rootfs is not supplied in container spec", func() {
			var err error

			container, err = client.Create(garden.ContainerSpec{RootFSPath: ""})
			Expect(err).To(HaveOccurred())
			Expect(err).To(MatchError(ContainSubstring("RootFSPath: is a required parameter, since no default rootfs was provided to the server.")))
		})

		It("creates successfully if a rootfs is supplied in container spec", func() {
			var err error

			container, err = client.Create(garden.ContainerSpec{RootFSPath: os.Getenv("GARDEN_TEST_ROOTFS")})
			Expect(err).NotTo(HaveOccurred())
		})
	})

	Context("with a default rootfs", func() {
		BeforeEach(func() {
			args = append(args, "--default-rootfs", os.Getenv("GARDEN_TEST_ROOTFS"))
コード例 #2
0
		container     garden.Container
		props         garden.Properties
		propertiesDir string
	)

	BeforeEach(func() {
		var err error
		propertiesDir, err = ioutil.TempDir("", "props")
		Expect(err).NotTo(HaveOccurred())
		args = append(args, "--properties-path", path.Join(propertiesDir, "props.json"))

		client = startGarden(args...)
		props = garden.Properties{"somename": "somevalue"}

		container, err = client.Create(garden.ContainerSpec{
			Properties: props,
		})
		Expect(err).NotTo(HaveOccurred())
	})

	AfterEach(func() {
		Expect(client.DestroyAndStop()).To(Succeed())
		Expect(os.RemoveAll(propertiesDir)).To(Succeed())
	})

	It("can get properties", func() {
		properties, err := container.Properties()
		Expect(err).NotTo(HaveOccurred())
		Expect(properties).To(HaveKeyWithValue("somename", "somevalue"))
	})
コード例 #3
0
ファイル: restart_test.go プロジェクト: cloudfoundry/guardian
			var err error
			propertiesDir, err = ioutil.TempDir("", "props")
			Expect(err).NotTo(HaveOccurred())
			args = append(args, "--properties-path", path.Join(propertiesDir, "props.json"))

			containerSpec = garden.ContainerSpec{
				Network: "177.100.10.30/30",
			}

			restartArgs = []string{}
			gracefulShutdown = true
		})

		JustBeforeEach(func() {
			var err error
			container, err = client.Create(containerSpec)
			Expect(err).NotTo(HaveOccurred())

			hostNetInPort, _, err = container.NetIn(hostNetInPort, 8080)
			Expect(err).NotTo(HaveOccurred())

			container.NetOut(garden.NetOutRule{
				Networks: []garden.IPRange{
					garden.IPRangeFromIP(net.ParseIP("8.8.8.8")),
				},
			})

			info, err := container.Info()
			Expect(err).NotTo(HaveOccurred())
			externalIP = info.ExternalIP
			interfacePrefix = info.Properties["kawasaki.iptable-prefix"]
コード例 #4
0
ファイル: run_test.go プロジェクト: cloudfoundry/guardian
	"github.com/onsi/gomega/gbytes"
	"github.com/onsi/gomega/gexec"
	"github.com/onsi/gomega/types"
)

var _ = Describe("Run", func() {
	var client *runner.RunningGarden

	AfterEach(func() {
		Expect(client.DestroyAndStop()).To(Succeed())
	})

	DescribeTable("running a process",
		func(spec garden.ProcessSpec, matchers ...func(actual interface{})) {
			client = startGarden()
			container, err := client.Create(garden.ContainerSpec{})
			Expect(err).NotTo(HaveOccurred())

			out := gbytes.NewBuffer()
			proc, err := container.Run(
				spec,
				garden.ProcessIO{
					Stdout: io.MultiWriter(GinkgoWriter, out),
					Stderr: io.MultiWriter(GinkgoWriter, out),
				})
			Expect(err).NotTo(HaveOccurred())

			exitCode, err := proc.Wait()
			Expect(err).NotTo(HaveOccurred())

			for _, m := range matchers {
コード例 #5
0
		JustBeforeEach(func() {
			var err error
			portPoolStart = GinkgoParallelNode() * 10000
			propsPoolDir, err = ioutil.TempDir("", "portpool")
			Expect(err).NotTo(HaveOccurred())
			args = []string{
				"--port-pool-size", strconv.Itoa(numContainers),
				"--port-pool-properties-path", filepath.Join(propsPoolDir, "props.json"),
				"--port-pool-start", strconv.Itoa(portPoolStart),
			}
			containers = []garden.Container{}
			client = startGarden(args...)

			// Create containers and NetIn
			for i := 0; i < numContainers; i++ {
				container, err := client.Create(garden.ContainerSpec{})
				Expect(err).NotTo(HaveOccurred())

				hostPort, _, err := container.NetIn(0, 0)
				if i == numContainers-1 {
					expectedPort = hostPort
				}
				Expect(err).NotTo(HaveOccurred())

				containers = append(containers, container)
			}

		})

		AfterEach(func() {
			Expect(client.DestroyAndStop()).To(Succeed())
コード例 #6
0
ファイル: graph_test.go プロジェクト: cloudfoundry/guardian
		layerFiles, err := ioutil.ReadDir(layersPath)
		Expect(err).ToNot(HaveOccurred())
		diffFiles, err := ioutil.ReadDir(diffPath)
		Expect(err).ToNot(HaveOccurred())
		mntFiles, err := ioutil.ReadDir(mntPath)
		Expect(err).ToNot(HaveOccurred())

		numLayerFiles := len(layerFiles)
		Expect(numLayerFiles).To(Equal(len(diffFiles)))
		Expect(numLayerFiles).To(Equal(len(mntFiles)))
		return numLayerFiles
	}

	expectLayerCountAfterGraphCleanupToBe := func(layerCount int) {
		nonPersistantRootfsContainer, err := client.Create(garden.ContainerSpec{
			RootFSPath: nonDefaultRootfsPath,
		})
		Expect(err).ToNot(HaveOccurred())
		Expect(client.Destroy(nonPersistantRootfsContainer.Handle())).To(Succeed())
		Expect(numLayersInGraph()).To(Equal(layerCount + 2)) // +2 for the layers created for the nondefaultrootfs container
	}

	BeforeEach(func() {
		var err error
		nonDefaultRootfsPath, err = ioutil.TempDir("", "tmpRootfs")
		Expect(err).ToNot(HaveOccurred())
		// temporary workaround as runc expects a /tmp dir to exist in the container rootfs
		err = os.Mkdir(filepath.Join(nonDefaultRootfsPath, "tmp"), 0700)
		Expect(err).ToNot(HaveOccurred())
	})
コード例 #7
0
ファイル: info_test.go プロジェクト: cloudfoundry/guardian
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Info", func() {
	var (
		client    *runner.RunningGarden
		container garden.Container
	)

	BeforeEach(func() {
		var err error
		client = startGarden()
		container, err = client.Create(garden.ContainerSpec{
			Network: "10.252.0.2",
			Properties: garden.Properties{
				"foo": "bar",
			},
		})
		Expect(err).NotTo(HaveOccurred())
	})

	AfterEach(func() {
		Expect(client.DestroyAndStop()).To(Succeed())
	})

	It("can return the state", func() {
		info, err := container.Info()
		Expect(err).NotTo(HaveOccurred())
		Expect(info.State).To(Equal("active"))
	})
コード例 #8
0
	JustBeforeEach(func() {
		client = startGarden(args...)
	})

	AfterEach(func() {
		Expect(client.DestroyAndStop()).To(Succeed())
	})

	Describe("Apparmor", func() {
		Context("when the --apparmor flag is pointing to a loaded policy", func() {
			BeforeEach(func() {
				args = append(args, "--apparmor", "garden-default")
			})

			It("should enforce the policy when running processes in unprivileged containers", func() {
				container, err := client.Create(garden.ContainerSpec{})
				Expect(err).NotTo(HaveOccurred())

				buffer := gbytes.NewBuffer()

				_, err = container.Run(garden.ProcessSpec{
					Path: "cat",
					Args: []string{"/proc/self/attr/current"},
				}, garden.ProcessIO{
					Stdout: io.MultiWriter(GinkgoWriter, buffer),
					Stderr: GinkgoWriter,
				})
				Expect(err).NotTo(HaveOccurred())

				Eventually(buffer).Should(gbytes.Say("garden-default"))
			})
コード例 #9
0
ファイル: destroy_test.go プロジェクト: cloudfoundry/guardian
	JustBeforeEach(func() {
		client = startGarden(args...)
	})

	AfterEach(func() {
		Expect(client.DestroyAndStop()).To(Succeed())
	})

	It("should not leak goroutines", func() {
		handle := fmt.Sprintf("goroutine-leak-test-%d", GinkgoParallelNode())

		numGoroutinesBefore, err := client.NumGoroutines()
		Expect(err).NotTo(HaveOccurred())

		_, err = client.Create(garden.ContainerSpec{
			Handle: handle,
		})
		Expect(err).NotTo(HaveOccurred())

		client.Destroy(handle)

		Eventually(func() int {
			numGoroutinesAfter, err := client.NumGoroutines()
			Expect(err).NotTo(HaveOccurred())
			return numGoroutinesAfter
		}).Should(Equal(numGoroutinesBefore))
	})

	It("should destroy the container's rootfs", func() {
		container, err := client.Create(garden.ContainerSpec{})
		Expect(err).NotTo(HaveOccurred())
コード例 #10
0
ファイル: create_test.go プロジェクト: cloudfoundry/guardian
		initialSockets = numOpenSockets(client.Pid)
		initialPipes = numPipes(client.Pid)
	})

	AfterEach(func() {
		Expect(client.DestroyAndStop()).To(Succeed())
	})

	Context("when creating fails", func() {
		// cause Create to fail by specifying an invalid network CIDR address
		var containerSpec = garden.ContainerSpec{
			Network: "not-a-valid-network",
		}

		It("returns a nice error rather than timing out", func() {
			_, err := client.Create(containerSpec)
			Expect(err).To(MatchError(ContainSubstring("invalid CIDR address")))
		})

		It("cleans up the depot directory", func() {
			_, err := client.Create(containerSpec)
			Expect(err).To(HaveOccurred())

			Expect(ioutil.ReadDir(client.DepotDir)).To(BeEmpty())
		})

		It("cleans up the graph", func() {
			// pre-warm cache to avoid test pollution
			// i.e. ensure base layers that are never removed are already in the graph
			_, err := client.Create(containerSpec)
			Expect(err).To(HaveOccurred())
コード例 #11
0
ファイル: fuse_test.go プロジェクト: cloudfoundry/guardian
var _ = Describe("Fuse", func() {
	var (
		client    *runner.RunningGarden
		container garden.Container
	)

	BeforeEach(func() {
		fuseRootfs := os.Getenv("GARDEN_FUSE_TEST_ROOTFS")
		if fuseRootfs == "" {
			Skip("GARDEN_FUSE_TEST_ROOTFS not defined, skipping")
		}

		var err error
		client = startGarden()
		container, err = client.Create(garden.ContainerSpec{
			RootFSPath: fuseRootfs,
			Privileged: true,
		})
		Expect(err).NotTo(HaveOccurred())
	})

	AfterEach(func() {
		Expect(client.DestroyAndStop()).To(Succeed())
	})

	It("can mount fuse in the container", func() {
		stdout := gbytes.NewBuffer()
		sess, err := container.Run(garden.ProcessSpec{
			Path: "sh",
			Args: []string{
				"-c", `mkdir -p /tmp/fusetest && /usr/bin/hellofs /tmp/fusetest; cat /tmp/fusetest/hello`,
			},
コード例 #12
0
		testFileName = ""

		srcPath, testFileName = createTestHostDirAndTestFile()
		bindMountOrigin = garden.BindMountOriginHost
	})

	JustBeforeEach(func() {
		client = startGarden()

		var err error
		container, err = client.Create(
			garden.ContainerSpec{
				Privileged: privilegedContainer,
				BindMounts: []garden.BindMount{{
					SrcPath: srcPath,
					DstPath: dstPath,
					Mode:    bindMountMode,
					Origin:  bindMountOrigin,
				}},
				Network: fmt.Sprintf("10.0.%d.0/24", GinkgoParallelNode()),
			})
		Expect(err).NotTo(HaveOccurred())
	})

	AfterEach(func() {
		err := os.RemoveAll(srcPath)
		Expect(err).ToNot(HaveOccurred())

		if container != nil {
			err := client.Destroy(container.Handle())
			Expect(err).ToNot(HaveOccurred())
コード例 #13
0
ファイル: net_test.go プロジェクト: cloudfoundry/guardian
		Eventually(func() error {
			var err error
			ips, err = net.LookupIP("www.example.com")
			return err
		}, "60s", "2s").Should(Succeed())

		exampleDotCom = ips[0]
	})

	JustBeforeEach(func() {
		var err error

		client = startGarden(args...)

		container, err = client.Create(garden.ContainerSpec{
			Network:    containerNetwork,
			Properties: extraProperties,
		})
		Expect(err).NotTo(HaveOccurred())
	})

	AfterEach(func() {
		Expect(client.DestroyAndStop()).To(Succeed())
	})

	It("should have a loopback interface", func() {
		buffer := gbytes.NewBuffer()
		proc, err := container.Run(
			garden.ProcessSpec{
				Path: "ifconfig",
				User: "******",
			}, garden.ProcessIO{Stdout: io.MultiWriter(GinkgoWriter, buffer), Stderr: GinkgoWriter},