Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RAID1 and multipath coverage for bootfs dropins from rdcore bind-boot #2594

Merged
merged 3 commits into from
Mar 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 17 additions & 64 deletions mantle/kola/tests/misc/boot-mirror.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
package misc

import (
"encoding/json"
"fmt"
"strings"
"time"

Expand Down Expand Up @@ -118,7 +118,7 @@ func runBootMirrorTest(c cluster.TestCluster) {
if strings.Compare(string(fsTypeForRoot), "xfs") != 0 {
c.Fatalf("didn't match fstype for root")
}
bootMirrorSanityTest(c, m)
bootMirrorSanityTest(c, m, []string{"/dev/vda", "/dev/vdb", "/dev/vdc"})

detachPrimaryBlockDevice(c, m)
// Check if there are two devices with the active raid
Expand Down Expand Up @@ -159,7 +159,7 @@ func runBootMirrorLUKSTest(c cluster.TestCluster) {
if !strings.Contains(string(bootOutput), "/dev/vda3") || !strings.Contains(string(bootOutput), "/dev/vdb3") {
c.Fatalf("boot raid device missing; found devices: %v", string(bootOutput))
}
bootMirrorSanityTest(c, m)
bootMirrorSanityTest(c, m, []string{"/dev/vda", "/dev/vdb"})
luksTPMTest(c, m, true)

detachPrimaryBlockDevice(c, m)
Expand Down Expand Up @@ -187,13 +187,22 @@ func luksTPMTest(c cluster.TestCluster, m platform.Machine, tpm2 bool) {
util.LUKSSanityTest(c, tangd, m, true, false, rootPart)
}

func bootMirrorSanityTest(c cluster.TestCluster, m platform.Machine) {
func bootMirrorSanityTest(c cluster.TestCluster, m platform.Machine, devices []string) {
c.Run("sanity-check", func(c cluster.TestCluster) {
// Check for boot
checkIfMountpointIsRaid(c, m, "/boot")
c.AssertCmdOutputContains(m, "findmnt -nvr /boot -o FSTYPE", "ext4")
// Check that growpart didn't run
c.RunCmdSync(m, "if [ -e /run/coreos-growpart.stamp ]; then exit 1; fi")
// Check for binding dropins
c.RunCmdSync(m, "sudo test -f /boot/.root_uuid")
c.RunCmdSync(m, "sudo test -f /boot/grub2/bootuuid.cfg")
for _, dev := range devices {
c.RunCmdSync(m, fmt.Sprintf(`
sudo mount -o ro %s2 /boot/efi
sudo sh -c 'test -f /boot/efi/EFI/*/bootuuid.cfg'
sudo umount /boot/efi`, dev))
}
})
}

Expand Down Expand Up @@ -228,68 +237,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
}
13 changes: 13 additions & 0 deletions mantle/kola/tests/misc/multipath.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,17 @@ func verifyMultipathBoot(c cluster.TestCluster, m platform.Machine) {
c.MustSSH(m, "test -f /etc/multipath.conf")
}

func verifyBootDropins(c cluster.TestCluster, m platform.Machine, checkBootuuid bool) {
c.RunCmdSync(m, "sudo test -f /boot/.root_uuid")
if checkBootuuid {
c.RunCmdSync(m, "sudo test -f /boot/grub2/bootuuid.cfg")
c.RunCmdSync(m, `
sudo mount -o ro /dev/disk/by-label/EFI-SYSTEM /boot/efi
sudo sh -c 'test -f /boot/efi/EFI/*/bootuuid.cfg'
sudo umount /boot/efi`)
}
}

func verifyMultipath(c cluster.TestCluster, m platform.Machine, path string) {
srcdev := string(c.MustSSHf(m, "findmnt -nvr %s -o SOURCE", path))
if !strings.HasPrefix(srcdev, "/dev/mapper/mpath") {
Expand All @@ -138,6 +149,7 @@ func runMultipathDay1(c cluster.TestCluster) {
c.Fatalf("Failed to reboot the machine: %v", err)
}
verifyMultipathBoot(c, m)
verifyBootDropins(c, m, true)
}

func runMultipathDay2(c cluster.TestCluster) {
Expand All @@ -147,6 +159,7 @@ func runMultipathDay2(c cluster.TestCluster) {
c.Fatalf("Failed to reboot the machine: %v", err)
}
verifyMultipathBoot(c, m)
verifyBootDropins(c, m, false)
}

func runMultipathPartition(c cluster.TestCluster) {
Expand Down