Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Jun 13, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 11 additions & 2 deletions pkg/volume/metrics_du_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,23 @@ import (
"io/ioutil"
"os"
"path/filepath"
"syscall"
"testing"

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
Expand Down Expand Up @@ -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)
}
}
Expand Down