mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
The test was not very useful and required elevated access
This commit is contained in:
parent
7ed2ed1b45
commit
f5739a15d1
@ -17,9 +17,6 @@ limitations under the License.
|
|||||||
package volume_test
|
package volume_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/fs"
|
|
||||||
"os"
|
|
||||||
"runtime"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
. "k8s.io/kubernetes/pkg/volume"
|
. "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")
|
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user