示例#1
0
func (c *CakeOrdinator) Destroy(logger lager.Logger, id, rootfs string) error {
	cid := layercake.ContainerID(id)
	if _, err := c.cake.Get(cid); err != nil {
		logger.Info("layer-already-deleted-skipping", lager.Data{"id": id, "graphID": cid, "error": err.Error()})
		return nil
	}

	return c.cake.Remove(cid)
}
示例#2
0
func (provider *ContainerLayerCreator) Create(log lager.Logger, id string, parentImage *repository_fetcher.Image, spec Spec) (string, []string, error) {
	var err error
	var imageID layercake.ID = layercake.DockerImageID(parentImage.ImageID)

	if spec.Namespaced {
		provider.mutex.Lock()
		imageID, err = provider.namespace(log, imageID)
		provider.mutex.Unlock()
		if err != nil {
			return "", nil, err
		}
	}

	containerID := layercake.ContainerID(id)
	if err := provider.graph.Create(containerID, imageID, id); err != nil {
		return "", nil, err
	}

	var rootPath string
	if spec.QuotaSize > 0 && spec.QuotaScope == garden.DiskLimitScopeExclusive {
		rootPath, err = provider.graph.QuotaedPath(containerID, spec.QuotaSize)
	} else if spec.QuotaSize > 0 && spec.QuotaScope == garden.DiskLimitScopeTotal {
		rootPath, err = provider.graph.QuotaedPath(containerID, spec.QuotaSize-parentImage.Size)
	} else {
		rootPath, err = provider.graph.Path(containerID)
	}

	if err != nil {
		return "", nil, err
	}

	for _, v := range parentImage.Volumes {
		if err = provider.volumeCreator.Create(rootPath, v); err != nil {
			return "", nil, err
		}
	}

	return rootPath, parentImage.Env, nil
}
示例#3
0
func (c *CakeOrdinator) Metrics(logger lager.Logger, id, _ string) (garden.ContainerDiskStat, error) {
	cid := layercake.ContainerID(id)
	return c.metrics.Metrics(logger, cid)
}
				Expect(diskQuota).To(BeNumerically("==", 33))
			})
		})
	})

	Describe("Metrics", func() {
		It("delegates metrics retrieval to the metricser", func() {
			fakeMetrics.MetricsReturns(garden.ContainerDiskStat{
				TotalBytesUsed: 12,
			}, nil)

			metrics, err := cakeOrdinator.Metrics(logger, "something", "")
			Expect(err).NotTo(HaveOccurred())

			_, path := fakeMetrics.MetricsArgsForCall(0)
			Expect(path).To(Equal(layercake.ContainerID("something")))

			Expect(metrics).To(Equal(garden.ContainerDiskStat{
				TotalBytesUsed: 12,
			}))
		})

		Context("when it fails to get the metrics", func() {
			BeforeEach(func() {
				fakeMetrics.MetricsReturns(garden.ContainerDiskStat{}, errors.New("rotten banana"))
			})

			It("should return an error", func() {
				_, err := cakeOrdinator.Metrics(logger, "something", "")
				Expect(err).To(MatchError("rotten banana"))
			})
			Driver: driver,
		}
	})

	AfterEach(func() {
		Expect(syscall.Unmount(root, 0)).To(Succeed())
		Expect(os.RemoveAll(root)).To(Succeed())
	})

	Describe("Register", func() {
		Context("after registering a layer", func() {
			var id layercake.ID
			var parent layercake.ID

			BeforeEach(func() {
				id = layercake.ContainerID("")
				parent = layercake.ContainerID("")
			})

			ItCanReadWriteTheLayer := func() {
				It("can read and write files", func() {
					p, err := cake.Path(id)
					Expect(err).NotTo(HaveOccurred())
					Expect(ioutil.WriteFile(path.Join(p, "foo"), []byte("hi"), 0700)).To(Succeed())

					p, err = cake.Path(id)
					Expect(err).NotTo(HaveOccurred())
					Expect(path.Join(p, "foo")).To(BeAnExistingFile())
				})

				It("can get back the image", func() {
					lagertest.NewTestLogger("test"),
					"some-id",
					&repository_fetcher.Image{
						ImageID: "some-image-id",
						Env:     []string{"env1=env1value", "env2=env2value"},
					},
					rootfs_provider.Spec{
						Namespaced: false,
						QuotaSize:  0,
					},
				)
				Expect(err).ToNot(HaveOccurred())

				Expect(fakeCake.CreateCallCount()).To(Equal(1))
				id, parent, containerID := fakeCake.CreateArgsForCall(0)
				Expect(id).To(Equal(layercake.ContainerID("some-id")))
				Expect(parent).To(Equal(layercake.DockerImageID("some-image-id")))
				Expect(containerID).To(Equal("some-id"))

				Expect(mountpoint).To(Equal("/some/graph/driver/mount/point"))
				Expect(envvars).To(Equal(
					[]string{
						"env1=env1value",
						"env2=env2value",
					},
				))
			})
		})

		Context("when the quota is positive", func() {
			It("should return the quotaed mount point path", func() {