Remove hardcode for blocksize, use stat(), fixes test failure on SLES

This commit is contained in:
Vaibhav Sood 2017-05-24 16:20:38 +05:30
parent 7c76e3994c
commit 5324dcb37b

View File

@ -23,13 +23,22 @@ import (
"os"
"path/filepath"
"testing"
"syscall"
utiltesting "k8s.io/client-go/util/testing"
. "k8s.io/kubernetes/pkg/volume"
volumetest "k8s.io/kubernetes/pkg/volume/testing"
)
const expectedBlockSize = 4096
func getExpectedBlockSize(path string) (int64) {
statfs := &syscall.Statfs_t{}
err := syscall.Statfs(path, statfs)
if err != nil {
return 0
}
return int64(statfs.Bsize)
}
// TestMetricsDuGetCapacity tests that MetricsDu can read disk usage
// for path
@ -69,7 +78,7 @@ func TestMetricsDuGetCapacity(t *testing.T) {
if err != nil {
t.Errorf("Unexpected error when calling GetMetrics %v", err)
}
if e, a := (expectedEmptyDirUsage.Value() + expectedBlockSize), actual.Used.Value(); e != a {
if e, a := (expectedEmptyDirUsage.Value() + getExpectedBlockSize(filepath.Join(tmpDir, "f1"))), actual.Used.Value(); e != a {
t.Errorf("Unexpected Used for directory with file. Expected %v, got %d.", e, a)
}
}