Browse Source

Merge pull request #12 from crosbymichael/core-driver-test-failures

Core driver test failures
Michael Crosby 11 years ago
parent
commit
f30c660f6f
8 changed files with 70 additions and 20 deletions
  1. 4 1
      aufs/aufs.go
  2. 40 0
      aufs/aufs_test.go
  3. 12 7
      container.go
  4. 2 2
      container_test.go
  5. 0 4
      devmapper/driver.go
  6. 4 1
      graphdriver/driver.go
  7. 5 5
      graphdriver/dummy/driver.go
  8. 3 0
      runtime.go

+ 4 - 1
aufs/aufs.go

@@ -158,7 +158,10 @@ func (a *AufsDriver) Remove(id string) error {
 
 	// Remove the dirs atomically
 	for _, p := range tmpDirs {
-		tmp := path.Join(os.TempDir(), p, id)
+		// We need to use a temp dir in the same dir as the driver so Rename
+		// does not fall back to the slow copy if /tmp and the driver dir
+		// are on different devices
+		tmp := path.Join(a.rootPath(), "tmp", p, id)
 		if err := os.MkdirAll(tmp, 0755); err != nil {
 			return err
 		}

+ 40 - 0
aufs/aufs_test.go

@@ -384,6 +384,46 @@ func TestChanges(t *testing.T) {
 	if change.Kind != archive.ChangeAdd {
 		t.Fatalf("Change kind should be ChangeAdd got %s", change.Kind)
 	}
+
+	if err := d.Create("3", "2"); err != nil {
+		t.Fatal(err)
+	}
+	mntPoint, err = d.Get("3")
+	if err != nil {
+		t.Fatal(err)
+	}
+
+	// Create a file to save in the mountpoint
+	f, err = os.Create(path.Join(mntPoint, "test2.txt"))
+	if err != nil {
+		t.Fatal(err)
+	}
+
+	if _, err := f.WriteString("testline"); err != nil {
+		t.Fatal(err)
+	}
+	if err := f.Close(); err != nil {
+		t.Fatal(err)
+	}
+
+	changes, err = d.Changes("3")
+	if err != nil {
+		t.Fatal(err)
+	}
+
+	if len(changes) != 1 {
+		t.Fatalf("Dir 2 should have one change from parent got %d", len(changes))
+	}
+	change = changes[0]
+
+	expectedPath = "/test2.txt"
+	if change.Path != expectedPath {
+		t.Fatalf("Expected path %s got %s", expectedPath, change.Path)
+	}
+
+	if change.Kind != archive.ChangeAdd {
+		t.Fatalf("Change kind should be ChangeAdd got %s", change.Kind)
+	}
 }
 
 /* FIXME: How to properly test this?

+ 12 - 7
container.go

@@ -396,7 +396,8 @@ func (container *Container) Inject(file io.Reader, pth string) error {
 	}
 
 	// Return error if path exists
-	if _, err := os.Stat(path.Join(container.RootfsPath(), pth)); err == nil {
+	destPath := path.Join(container.RootfsPath(), pth)
+	if _, err := os.Stat(destPath); err == nil {
 		// Since err is nil, the path could be stat'd and it exists
 		return fmt.Errorf("%s exists", pth)
 	} else if !os.IsNotExist(err) {
@@ -405,10 +406,18 @@ func (container *Container) Inject(file io.Reader, pth string) error {
 
 		return err
 	}
-	dest, err := os.Create(path.Join(container.RootfsPath(), pth))
+
+	// Make sure the directory exists
+	if err := os.MkdirAll(path.Join(container.RootfsPath(), path.Dir(pth)), 0755); err != nil {
+		return err
+	}
+
+	dest, err := os.Create(destPath)
 	if err != nil {
 		return err
 	}
+	defer dest.Close()
+
 	if _, err := io.Copy(dest, file); err != nil {
 		return err
 	}
@@ -1369,11 +1378,7 @@ func (container *Container) ExportRw() (archive.Archive, error) {
 	if container.runtime == nil {
 		return nil, fmt.Errorf("Can't load storage driver for unregistered container %s", container.ID)
 	}
-	imgDir, err := container.runtime.driver.Get(container.Image)
-	if err != nil {
-		return nil, err
-	}
-	return archive.ExportChanges(container.RootfsPath(), imgDir)
+	return container.runtime.driver.Diff(container.ID)
 }
 
 func (container *Container) Export() (archive.Archive, error) {

+ 2 - 2
container_test.go

@@ -170,11 +170,11 @@ func TestDiff(t *testing.T) {
 	// Commit the container
 	rwTar, err := container1.ExportRw()
 	if err != nil {
-		t.Error(err)
+		t.Fatal(err)
 	}
 	img, err := runtime.graph.Create(rwTar, container1, "unit test commited image - diff", "", nil)
 	if err != nil {
-		t.Error(err)
+		t.Fatal(err)
 	}
 
 	// Create a new container from the commited image

+ 0 - 4
devmapper/driver.go

@@ -65,10 +65,6 @@ func (d *Driver) DiffSize(id string) (int64, error) {
 	return -1, fmt.Errorf("Not implemented")
 }
 
-func (d *Driver) Changes(id string) ([]archive.Change, error) {
-	return nil, fmt.Errorf("Not implemented")
-}
-
 func (d *Driver) mount(id, mp string) error {
 	// Create the target directories if they don't exist
 	if err := os.MkdirAll(mp, 0755); err != nil && !os.IsExist(err) {

+ 4 - 1
graphdriver/driver.go

@@ -18,11 +18,14 @@ type Driver interface {
 
 	Diff(id string) (archive.Archive, error)
 	DiffSize(id string) (bytes int64, err error)
-	Changes(id string) ([]archive.Change, error)
 
 	Cleanup() error
 }
 
+type Changer interface {
+	Changes(id string) ([]archive.Change, error)
+}
+
 var (
 	// All registred drivers
 	drivers map[string]InitFunc

+ 5 - 5
graphdriver/dummy/driver.go

@@ -74,13 +74,13 @@ func (d *Driver) Get(id string) (string, error) {
 }
 
 func (d *Driver) Diff(id string) (archive.Archive, error) {
-	return nil, fmt.Errorf("Not implemented")
+	p, err := d.Get(id)
+	if err != nil {
+		return nil, err
+	}
+	return archive.Tar(p, archive.Uncompressed)
 }
 
 func (d *Driver) DiffSize(id string) (int64, error) {
 	return -1, fmt.Errorf("Not implemented")
 }
-
-func (d *Driver) Changes(id string) ([]archive.Change, error) {
-	return nil, fmt.Errorf("Not implemented")
-}

+ 3 - 0
runtime.go

@@ -733,6 +733,9 @@ func (runtime *Runtime) Unmount(container *Container) error {
 }
 
 func (runtime *Runtime) Changes(container *Container) ([]archive.Change, error) {
+	if changer, ok := runtime.driver.(graphdriver.Changer); ok {
+		return changer.Changes(container.ID)
+	}
 	cDir, err := runtime.driver.Get(container.ID)
 	if err != nil {
 		return nil, fmt.Errorf("Error getting container rootfs %s from driver %s: %s", container.ID, container.runtime.driver, err)