Merge pull request #102608 from gnufied/remove-test-on-unknown-block-devices

Remove block device metrics unit test
This commit is contained in:
Kubernetes Prow Robot 2021-06-04 13:56:38 -07:00 committed by GitHub
commit 8eff96dd12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -17,9 +17,6 @@ limitations under the License.
package volume_test
import (
"io/fs"
"os"
"runtime"
"testing"
. "k8s.io/kubernetes/pkg/volume"
@ -46,53 +43,3 @@ func TestGetMetricsBlockInvalid(t *testing.T) {
t.Errorf("Expected error when calling GetMetrics on incorrectly initialized MetricsBlock, actual nil")
}
}
func TestGetMetricsBlock(t *testing.T) {
// FIXME: this test is Linux specific
if runtime.GOOS == "windows" {
t.Skip("Block device detection is Linux specific, no Windows support")
}
// find a block device
// get all available block devices
// - ls /sys/block
devices, err := os.ReadDir("/dev")
if err != nil {
t.Skipf("Could not read devices from /dev: %v", err)
} else if len(devices) == 0 {
t.Skip("No devices found")
}
// for each device, check if it is available in /dev
devNode := ""
var stat fs.FileInfo
for _, device := range devices {
// if the device exists, use it, return
devNode = "/dev/" + device.Name()
stat, err = os.Stat(devNode)
if err == nil {
if stat.Mode().Type() == fs.ModeDevice {
break
}
}
// set to an empty string, so we can do validation of the last
// device too
devNode = ""
}
// if no devices are found, or none exists in /dev, skip this part
if devNode == "" {
t.Skip("Could not find a block device under /dev")
}
// when we get here, devNode points to an existing block device
metrics := NewMetricsBlock(devNode)
actual, err := metrics.GetMetrics()
if err != nil {
t.Errorf("Unexpected error when calling GetMetrics: %v", err)
}
if a := actual.Capacity.Value(); a <= 0 {
t.Errorf("Expected Capacity %d to be greater than 0.", a)
}
}