mirror of https://github.com/docker/docs.git
Merge branch 'shykes-0.6.5-dm-plugin' into refactor_dm
This commit is contained in:
commit
3aaef96e36
|
@ -464,3 +464,54 @@ func TestDiffSize(t *testing.T) {
|
||||||
t.Fatalf("Expected size to be %d got %d", size, diffSize)
|
t.Fatalf("Expected size to be %d got %d", size, diffSize)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestApplyDiff(t *testing.T) {
|
||||||
|
d := newDriver(t)
|
||||||
|
defer os.RemoveAll(tmp)
|
||||||
|
defer d.Cleanup()
|
||||||
|
|
||||||
|
if err := d.Create("1", ""); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
diffPath, err := d.Get("1")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add a file to the diff path with a fixed size
|
||||||
|
size := int64(1024)
|
||||||
|
|
||||||
|
f, err := os.Create(path.Join(diffPath, "test_file"))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
f.Truncate(size)
|
||||||
|
f.Close()
|
||||||
|
|
||||||
|
diff, err := d.Diff("1")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := d.Create("2", ""); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := d.Create("3", "2"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := d.ApplyDiff("3", diff); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure that the file is in the mount point for id 3
|
||||||
|
|
||||||
|
mountPoint, err := d.Get("3")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if _, err := os.Stat(path.Join(mountPoint, "test_file")); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -679,7 +679,7 @@ func (devices *DeviceSet) MountDevice(hash, path string, readOnly bool) error {
|
||||||
count := devices.activeMounts[path]
|
count := devices.activeMounts[path]
|
||||||
devices.activeMounts[path] = count + 1
|
devices.activeMounts[path] = count + 1
|
||||||
|
|
||||||
return nil
|
return devices.setInitialized(hash)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (devices *DeviceSet) UnmountDevice(hash, path string, deactivate bool) error {
|
func (devices *DeviceSet) UnmountDevice(hash, path string, deactivate bool) error {
|
||||||
|
@ -740,10 +740,7 @@ func (devices *DeviceSet) HasActivatedDevice(hash string) bool {
|
||||||
return devinfo != nil && devinfo.Exists != 0
|
return devinfo != nil && devinfo.Exists != 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (devices *DeviceSet) SetInitialized(hash string) error {
|
func (devices *DeviceSet) setInitialized(hash string) error {
|
||||||
devices.Lock()
|
|
||||||
defer devices.Unlock()
|
|
||||||
|
|
||||||
info := devices.Devices[hash]
|
info := devices.Devices[hash]
|
||||||
if info == nil {
|
if info == nil {
|
||||||
return fmt.Errorf("Unknown device %s", hash)
|
return fmt.Errorf("Unknown device %s", hash)
|
||||||
|
|
|
@ -22,7 +22,7 @@ type Driver struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Init(home string) (graphdriver.Driver, error) {
|
func Init(home string) (graphdriver.Driver, error) {
|
||||||
deviceSet, err := NewDeviceSet(home);
|
deviceSet, err := NewDeviceSet(home)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -61,17 +61,17 @@ func (d *Driver) Size(id string) (int64, error) {
|
||||||
return -1, fmt.Errorf("Not implemented")
|
return -1, fmt.Errorf("Not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Driver) mount(id, mp string) error {
|
func (d *Driver) mount(id, mountPoint string) error {
|
||||||
// Create the target directories if they don't exist
|
// Create the target directories if they don't exist
|
||||||
if err := os.MkdirAll(mp, 0755); err != nil && !os.IsExist(err) {
|
if err := os.MkdirAll(mountPoint, 0755); err != nil && !os.IsExist(err) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// If mountpoint is already mounted, do nothing
|
// If mountpoint is already mounted, do nothing
|
||||||
if mounted, err := Mounted(mp); err != nil {
|
if mounted, err := Mounted(mountPoint); err != nil {
|
||||||
return fmt.Errorf("Error checking mountpoint: %s", err)
|
return fmt.Errorf("Error checking mountpoint: %s", err)
|
||||||
} else if mounted {
|
} else if mounted {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
// Mount the device
|
// Mount the device
|
||||||
return d.DeviceSet.MountDevice(id, mp, false)
|
return d.DeviceSet.MountDevice(id, mountPoint, false)
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,9 +3,18 @@ package devmapper
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"path"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
// Reduce the size the the base fs and loopback for the tests
|
||||||
|
DefaultDataLoopbackSize = 300 * 1024 * 1024
|
||||||
|
DefaultMetaDataLoopbackSize = 200 * 1024 * 1024
|
||||||
|
DefaultBaseFsSize = 300 * 1024 * 1024
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func mkTestDirectory(t *testing.T) string {
|
func mkTestDirectory(t *testing.T) string {
|
||||||
dir, err := ioutil.TempDir("", "docker-test-devmapper-")
|
dir, err := ioutil.TempDir("", "docker-test-devmapper-")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -14,6 +23,20 @@ func mkTestDirectory(t *testing.T) string {
|
||||||
return dir
|
return dir
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func newDriver(t *testing.T) *Driver {
|
||||||
|
home := mkTestDirectory(t)
|
||||||
|
d, err := Init(home)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
return d.(*Driver)
|
||||||
|
}
|
||||||
|
|
||||||
|
func cleanup(d *Driver) {
|
||||||
|
d.Cleanup()
|
||||||
|
os.RemoveAll(d.home)
|
||||||
|
}
|
||||||
|
|
||||||
func TestInit(t *testing.T) {
|
func TestInit(t *testing.T) {
|
||||||
home := mkTestDirectory(t)
|
home := mkTestDirectory(t)
|
||||||
defer os.RemoveAll(home)
|
defer os.RemoveAll(home)
|
||||||
|
@ -22,11 +45,11 @@ func TestInit(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
return
|
|
||||||
if err := driver.Cleanup(); err != nil {
|
if err := driver.Cleanup(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
id := "foo"
|
id := "foo"
|
||||||
if err := driver.Create(id, ""); err != nil {
|
if err := driver.Create(id, ""); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -41,3 +64,238 @@ func TestInit(t *testing.T) {
|
||||||
t.Fatalf("Get(%V) did not return a directory", id)
|
t.Fatalf("Get(%V) did not return a directory", id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestDriverName(t *testing.T) {
|
||||||
|
d := newDriver(t)
|
||||||
|
defer cleanup(d)
|
||||||
|
|
||||||
|
if d.String() != "devicemapper" {
|
||||||
|
t.Fatalf("Expected driver name to be devicemapper got %s", d.String())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestDriverCreate(t *testing.T) {
|
||||||
|
d := newDriver(t)
|
||||||
|
defer cleanup(d)
|
||||||
|
|
||||||
|
if err := d.Create("1", ""); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestDriverRemove(t *testing.T) {
|
||||||
|
d := newDriver(t)
|
||||||
|
defer cleanup(d)
|
||||||
|
|
||||||
|
if err := d.Create("1", ""); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := d.Remove("1"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCleanup(t *testing.T) {
|
||||||
|
d := newDriver(t)
|
||||||
|
defer os.RemoveAll(d.home)
|
||||||
|
|
||||||
|
mountPoints := make([]string, 2)
|
||||||
|
|
||||||
|
if err := d.Create("1", ""); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
// Mount the id
|
||||||
|
p, err := d.Get("1")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
mountPoints[0] = p
|
||||||
|
|
||||||
|
if err := d.Create("2", "1"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
p, err = d.Get("2")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
mountPoints[1] = p
|
||||||
|
|
||||||
|
// Ensure that all the mount points are currently mounted
|
||||||
|
for _, p := range mountPoints {
|
||||||
|
if mounted, err := Mounted(p); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
} else if !mounted {
|
||||||
|
t.Fatalf("Expected %s to be mounted", p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure that devices are active
|
||||||
|
for _, p := range []string{"1", "2"} {
|
||||||
|
if !d.HasActivatedDevice(p) {
|
||||||
|
t.Fatalf("Expected %s to have an active device", p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := d.Cleanup(); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure that all the mount points are no longer mounted
|
||||||
|
for _, p := range mountPoints {
|
||||||
|
if mounted, err := Mounted(p); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
} else if mounted {
|
||||||
|
t.Fatalf("Expected %s to not be mounted", p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure that devices are no longer activated
|
||||||
|
for _, p := range []string{"1", "2"} {
|
||||||
|
if d.HasActivatedDevice(p) {
|
||||||
|
t.Fatalf("Expected %s not be an active device", p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNotMounted(t *testing.T) {
|
||||||
|
d := newDriver(t)
|
||||||
|
defer cleanup(d)
|
||||||
|
|
||||||
|
if err := d.Create("1", ""); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
mounted, err := Mounted(path.Join(d.home, "mnt", "1"))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if mounted {
|
||||||
|
t.Fatal("Id 1 should not be mounted")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMounted(t *testing.T) {
|
||||||
|
d := newDriver(t)
|
||||||
|
defer cleanup(d)
|
||||||
|
|
||||||
|
if err := d.Create("1", ""); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if _, err := d.Get("1"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
mounted, err := Mounted(path.Join(d.home, "mnt", "1"))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if !mounted {
|
||||||
|
t.Fatal("Id 1 should be mounted")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestInitCleanedDriver(t *testing.T) {
|
||||||
|
d := newDriver(t)
|
||||||
|
|
||||||
|
if err := d.Create("1", ""); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if _, err := d.Get("1"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := d.Cleanup(); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
driver, err := Init(d.home)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
d = driver.(*Driver)
|
||||||
|
defer cleanup(d)
|
||||||
|
|
||||||
|
if _, err := d.Get("1"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMountMountedDriver(t *testing.T) {
|
||||||
|
d := newDriver(t)
|
||||||
|
defer cleanup(d)
|
||||||
|
|
||||||
|
if err := d.Create("1", ""); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Perform get on same id to ensure that it will
|
||||||
|
// not be mounted twice
|
||||||
|
if _, err := d.Get("1"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if _, err := d.Get("1"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetReturnsValidDevice(t *testing.T) {
|
||||||
|
d := newDriver(t)
|
||||||
|
defer cleanup(d)
|
||||||
|
|
||||||
|
if err := d.Create("1", ""); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !d.HasDevice("1") {
|
||||||
|
t.Fatalf("Expected id 1 to be in device set")
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := d.Get("1"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !d.HasActivatedDevice("1") {
|
||||||
|
t.Fatalf("Expected id 1 to be activated")
|
||||||
|
}
|
||||||
|
|
||||||
|
if !d.HasInitializedDevice("1") {
|
||||||
|
t.Fatalf("Expected id 1 to be initialized")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestDriverGetSize(t *testing.T) {
|
||||||
|
t.Skipf("Size is currently not implemented")
|
||||||
|
|
||||||
|
d := newDriver(t)
|
||||||
|
defer cleanup(d)
|
||||||
|
|
||||||
|
if err := d.Create("1", ""); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
mountPoint, err := d.Get("1")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
size := int64(1024)
|
||||||
|
|
||||||
|
f, err := os.Create(path.Join(mountPoint, "test_file"))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := f.Truncate(size); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
f.Close()
|
||||||
|
|
||||||
|
diffSize, err := d.Size("1")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if diffSize != size {
|
||||||
|
t.Fatalf("Expected size %d got %d", size, diffSize)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue