1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Add test to ZFS for disk quota

Signed-off-by: Ken Herner <kherner@progress.com>
This commit is contained in:
Ken Herner 2016-05-19 14:47:33 -04:00
parent 373654f43e
commit 04b4e3e6d8
2 changed files with 50 additions and 0 deletions

View file

@ -5,12 +5,16 @@ package graphtest
import ( import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"math/rand"
"os" "os"
"path" "path"
"reflect"
"syscall" "syscall"
"testing" "testing"
"unsafe"
"github.com/docker/docker/daemon/graphdriver" "github.com/docker/docker/daemon/graphdriver"
"github.com/docker/go-units"
) )
var ( var (
@ -297,3 +301,45 @@ func DriverTestCreateSnap(t *testing.T, drivername string) {
t.Fatal(err) t.Fatal(err)
} }
} }
func writeRandomFile(path string, size uint64) error {
buf := make([]int64, size/8)
r := rand.NewSource(0)
for i := range buf {
buf[i] = r.Int63()
}
// Cast to []byte
header := *(*reflect.SliceHeader)(unsafe.Pointer(&buf))
header.Len *= 8
header.Cap *= 8
data := *(*[]byte)(unsafe.Pointer(&header))
return ioutil.WriteFile(path, data, 0700)
}
// DriverTestSetQuota Create a driver and test setting quota.
func DriverTestSetQuota(t *testing.T, drivername string) {
driver := GetDriver(t, drivername)
defer PutDriver(t)
createBase(t, driver, "Base")
storageOpt := make(map[string]string, 1)
storageOpt["size"] = "50M"
if err := driver.Create("zfsTest", "Base", "", storageOpt); err != nil {
t.Fatal(err)
}
mountPath, err := driver.Get("zfsTest", "")
if err != nil {
t.Fatal(err)
}
quota := uint64(50 * units.MiB)
err = writeRandomFile(path.Join(mountPath, "file"), quota*2)
if pathError, ok := err.(*os.PathError); ok && pathError.Err != syscall.EDQUOT {
t.Fatalf("expect write() to fail with %v, got %v", syscall.EDQUOT, err)
}
}

View file

@ -26,6 +26,10 @@ func TestZfsCreateSnap(t *testing.T) {
graphtest.DriverTestCreateSnap(t, "zfs") graphtest.DriverTestCreateSnap(t, "zfs")
} }
func TestZfsSetQuota(t *testing.T) {
graphtest.DriverTestSetQuota(t, "zfs")
}
func TestZfsTeardown(t *testing.T) { func TestZfsTeardown(t *testing.T) {
graphtest.PutDriver(t) graphtest.PutDriver(t)
} }