mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 17:30:00 +00:00
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:
commit
0b0ec9b581
@ -22,6 +22,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"syscall"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
utiltesting "k8s.io/client-go/util/testing"
|
utiltesting "k8s.io/client-go/util/testing"
|
||||||
@ -29,7 +30,15 @@ import (
|
|||||||
volumetest "k8s.io/kubernetes/pkg/volume/testing"
|
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
|
// TestMetricsDuGetCapacity tests that MetricsDu can read disk usage
|
||||||
// for path
|
// for path
|
||||||
@ -69,7 +78,7 @@ func TestMetricsDuGetCapacity(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Unexpected error when calling GetMetrics %v", err)
|
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)
|
t.Errorf("Unexpected Used for directory with file. Expected %v, got %d.", e, a)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user