snapshots: separate implementations into packages
Signed-off-by: Stephen J Day <stephen.day@docker.com>
This commit is contained in:
parent
c7f77f475a
commit
e3f83fd53d
8 changed files with 22 additions and 16 deletions
|
@ -1,6 +1,7 @@
|
|||
package snapshot
|
||||
package btrfs
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
@ -26,7 +27,6 @@ func (lm *Btrfs) Prepare(key, parent string) ([]containerd.Mount, error) {
|
|||
|
||||
dir := filepath.Join(active, hash(key))
|
||||
|
||||
fmt.Println("dir", dir)
|
||||
if parent == "" {
|
||||
// create new subvolume
|
||||
// btrfs subvolume create /dir
|
||||
|
@ -69,3 +69,7 @@ func (lm *Btrfs) Commit(name, key string) error {
|
|||
|
||||
return btrfs.SubvolDelete(dir)
|
||||
}
|
||||
|
||||
func hash(k string) string {
|
||||
return fmt.Sprintf("%x", sha256.Sum224([]byte(k)))
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package snapshot
|
||||
package btrfs
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
@ -10,6 +10,7 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/docker/containerd"
|
||||
"github.com/docker/containerd/snapshot/testutil"
|
||||
btrfs "github.com/stevvooe/go-btrfs"
|
||||
)
|
||||
|
||||
|
@ -53,7 +54,7 @@ func TestBtrfs(t *testing.T) {
|
|||
if err := containerd.MountAll(mounts...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer unmountAll(t, mounts)
|
||||
defer testutil.UnmountAll(t, mounts)
|
||||
|
||||
// write in some data
|
||||
if err := ioutil.WriteFile(filepath.Join(mounts[0].Target, "foo"), []byte("content"), 0777); err != nil {
|
||||
|
@ -89,7 +90,7 @@ func TestBtrfs(t *testing.T) {
|
|||
if err := containerd.MountAll(mounts...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer unmountAll(t, mounts)
|
||||
defer testutil.UnmountAll(t, mounts)
|
||||
|
||||
// TODO(stevvooe): Verify contents of "foo"
|
||||
if err := ioutil.WriteFile(filepath.Join(mounts[0].Target, "bar"), []byte("content"), 0777); err != nil {
|
||||
|
@ -182,7 +183,7 @@ func setupBtrfsLoopbackDevice(t *testing.T) *testDevice {
|
|||
// file holding the disk image.
|
||||
func removeBtrfsLoopbackDevice(t *testing.T, device *testDevice) {
|
||||
// unmount
|
||||
unmount(t, device.mountPoint)
|
||||
testutil.Unmount(t, device.mountPoint)
|
||||
|
||||
// detach device
|
||||
t.Log("Removing loop device")
|
|
@ -8,6 +8,7 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/docker/containerd"
|
||||
"github.com/docker/containerd/snapshot/testutil"
|
||||
)
|
||||
|
||||
// TestSnapshotManagerBasic implements something similar to the conceptual
|
||||
|
@ -58,7 +59,7 @@ func TestSnapshotManagerBasic(t *testing.T) {
|
|||
if err := containerd.MountAll(mounts...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer unmountAll(t, mounts)
|
||||
defer testutil.UnmountAll(t, mounts)
|
||||
|
||||
if err := ioutil.WriteFile(filepath.Join(preparing, "foo"), []byte("foo\n"), 0777); err != nil {
|
||||
t.Fatal(err)
|
||||
|
@ -88,7 +89,7 @@ func TestSnapshotManagerBasic(t *testing.T) {
|
|||
if err := containerd.MountAll(mounts...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer unmountAll(t, mounts)
|
||||
defer testutil.UnmountAll(t, mounts)
|
||||
|
||||
for _, mount := range mounts {
|
||||
if !strings.HasPrefix(mount.Target, next) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package snapshot
|
||||
package naive
|
||||
|
||||
import (
|
||||
"fmt"
|
|
@ -1,4 +1,4 @@
|
|||
package snapshot
|
||||
package naive
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
|
@ -1,4 +1,4 @@
|
|||
package snapshot
|
||||
package overlay
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
|
@ -1,4 +1,4 @@
|
|||
package snapshot
|
||||
package overlay
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
|
@ -1,4 +1,4 @@
|
|||
package snapshot
|
||||
package testutil
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
|
@ -7,13 +7,13 @@ import (
|
|||
"github.com/docker/containerd"
|
||||
)
|
||||
|
||||
func unmountAll(t *testing.T, mounts []containerd.Mount) {
|
||||
func UnmountAll(t *testing.T, mounts []containerd.Mount) {
|
||||
for _, mount := range mounts {
|
||||
unmount(t, mount.Target)
|
||||
Unmount(t, mount.Target)
|
||||
}
|
||||
}
|
||||
|
||||
func unmount(t *testing.T, mountPoint string) {
|
||||
func Unmount(t *testing.T, mountPoint string) {
|
||||
t.Log("unmount", mountPoint)
|
||||
umount := exec.Command("umount", mountPoint)
|
||||
err := umount.Run()
|
Loading…
Reference in a new issue