Merge pull request #46342 from vaibhavsood/master

Automatic merge from submit-queue (batch tested with PRs 47075, 46342)

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

**What this PR does / why we need it**:
Removes hardcoding for blocksize, fixes test failure on SLES
**Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes #44022

**Special notes for your reviewer**:

**Release note**:

```release-note
```
This commit is contained in:
Kubernetes Submit Queue 2017-06-12 23:50:03 -07:00 committed by GitHub
commit 0b0ec9b581

View File

@ -22,6 +22,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"syscall"
"testing"
utiltesting "k8s.io/client-go/util/testing"
@ -29,7 +30,15 @@ import (
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)
}
}