kola/boot-mirror: simplify check for RAID1 mountpoint
To check if a mountpoint is on RAID1, instead of going from the top and
querying all devices on the system, we can directly check the type of
the device backing the mountpoint.
package misc
import (
- "encoding/json"
"strings"
"time"
@@ -228,68 +227,12 @@ func verifyBootMirrorAfterReboot(c cluster.TestCluster, m platform.Machine) {
})
}
-type lsblkOutput struct {
- Blockdevices []blockdevice `json:"blockdevices"`
-}
-
-type blockdevice struct {
- Name string `json:"name"`
- Type string `json:"type"`
- Mountpoint *string `json:"mountpoint"`
- // new lsblk outputs `mountpoints` instead of
- // `mountpoint`; we handle both
- Mountpoints []string `json:"mountpoints"`
- Children []blockdevice `json:"children"`
-}
-
// checkIfMountpointIsRaid will check if a given machine has a device of type
// raid1 mounted at the given mountpoint. If it does not, the test is failed.
func checkIfMountpointIsRaid(c cluster.TestCluster, m platform.Machine, mountpoint string) {
- output := c.MustSSH(m, "lsblk --json")
-
- l := lsblkOutput{}
- err := json.Unmarshal(output, &l)
- if err != nil {
- c.Fatalf("couldn't unmarshal lsblk output: %v", err)
- }
-
- foundDevice := checkIfMountpointIsRaidWalker(c, l.Blockdevices, mountpoint)
- if !foundDevice {
- c.Fatalf("didn't find %q mountpoint in lsblk output", mountpoint)
- }
-}
-
-// checkIfMountpointIsRaidWalker will iterate over bs and recurse into its
-// children, looking for a device mounted at / with type raid1. true is returned
-// if such a device is found. The test is failed if a device of a different type
-// is found to be mounted at /.
-func checkIfMountpointIsRaidWalker(c cluster.TestCluster, bs []blockdevice, mountpoint string) bool {
- for _, b := range bs {
- if checkIfBlockdevHasMountPoint(b, mountpoint) {
- if b.Type != "raid1" {
- c.Fatalf("device %q is mounted at %q with type %q (was expecting raid1)", b.Name, mountpoint, b.Type)
- }
- return true
- }
- foundDevice := checkIfMountpointIsRaidWalker(c, b.Children, mountpoint)
- if foundDevice {
- return true
- }
- }
- return false
-}
-
-// checkIfBlockdevHasMountPoint checks if a given block device has the
-// required mountpoint.
-func checkIfBlockdevHasMountPoint(b blockdevice, mountpoint string) bool {
- if b.Mountpoint != nil && *b.Mountpoint == mountpoint {
- return true
- } else if len(b.Mountpoints) != 0 {
- for _, mnt := range b.Mountpoints {
- if mnt != "" && mnt == mountpoint {
- return true
- }
- }
+ backing_device := string(c.MustSSH(m, "findmnt -no SOURCE "+mountpoint))
+ device_type := string(c.MustSSH(m, "lsblk -no TYPE "+backing_device))
+ if device_type != "raid1" {
+ c.Fatalf("expected mountpoint backed by raid1, but got %q", device_type)
}
- return false
}
