Merge pull request #12 from crosbymichael/core-driver-test-failures
Core driver test failures
This commit is contained in:
commit
f30c660f6f
8 changed files with 70 additions and 20 deletions
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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?
|
||||
|
|
19
container.go
19
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) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue