From 5324dcb37b61a49356f4fe753e9ebd9b676f318e Mon Sep 17 00:00:00 2001 From: Vaibhav Sood Date: Wed, 24 May 2017 16:20:38 +0530 Subject: [PATCH] Remove hardcode for blocksize, use stat(), fixes test failure on SLES --- pkg/volume/metrics_du_test.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/pkg/volume/metrics_du_test.go b/pkg/volume/metrics_du_test.go index c78dad1c7fd..851494d3f3a 100644 --- a/pkg/volume/metrics_du_test.go +++ b/pkg/volume/metrics_du_test.go @@ -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) } }