Skip to content
Merged
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
13 changes: 7 additions & 6 deletions mantle/kola/tests/misc/multipath.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ systemd:

[Service]
Type=oneshot
ExecStart=/usr/sbin/mpathconf --enable
ExecStart=/usr/sbin/mpathconf --enable --user_friendly_names n

[Install]
WantedBy=multi-user.target
Expand All @@ -61,8 +61,8 @@ systemd:
[Unit]
Description=Set Up Multipath On /var/lib/containers
ConditionFirstBoot=true
Requires=dev-mapper-mpatha.device
After=dev-mapper-mpatha.device
Requires=dev-disk-by\x2did-dm\x2duuid\x2dmpath\x2d0x0000000000000001.device
After=dev-disk-by\x2did-dm\x2duuid\x2dmpath\x2d0x0000000000000001.device
# See https://github.com/coreos/coreos-assembler/pull/2457
# and https://github.com/openshift/os/issues/743
After=ostree-remount.service
Expand All @@ -71,7 +71,7 @@ systemd:

[Service]
Type=oneshot
ExecStart=/usr/sbin/mkfs.xfs -L containers -m reflink=1 /dev/mapper/mpatha
ExecStart=/usr/sbin/mkfs.xfs -L containers -m reflink=1 /dev/disk/by-id/dm-uuid-mpath-0x0000000000000001
# This is usually created by tmpfiles.d, but we run earlier than that.
ExecStart=/usr/bin/mkdir -p /var/lib/containers

Expand Down Expand Up @@ -119,7 +119,7 @@ func init() {
ClusterSize: 1,
Platforms: []string{"qemu"},
UserData: mpath_on_var_lib_containers,
AdditionalDisks: []string{"1G:mpath"},
AdditionalDisks: []string{"1G:mpath,wwn=1"},
})
}

Expand Down Expand Up @@ -151,7 +151,8 @@ func verifyBootDropins(c cluster.TestCluster, m platform.Machine, checkBootuuid

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") {
udevinfo := string(c.MustSSHf(m, "udevadm info %s", srcdev))
if !strings.Contains(udevinfo, "/dev/disk/by-id/dm-uuid-mpath-") && !strings.Contains(udevinfo, "DM_MPATH") {
c.Fatalf("mount %s has non-multipath source %s", path, srcdev)
}
Comment on lines 153 to 157
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

There are a couple of issues in this function:

  1. Bug: The output from c.MustSSHf can include a trailing newline. When srcdev is passed to the udevadm info command, this newline is included, which will likely cause the command to fail because the path is incorrect (e.g., /dev/dm-0\n).
  2. Efficiency: The function makes two separate SSH calls. These can be combined into a single call to improve test efficiency by reducing network round-trips.

The suggested change below addresses both points by combining the commands into a single shell command and parsing the output in Go. The $(...) command substitution in the shell correctly handles stripping the newline from findmnt's output.

Suggested change
srcdev := string(c.MustSSHf(m, "findmnt -nvr %s -o SOURCE", path))
if !strings.HasPrefix(srcdev, "/dev/mapper/mpath") {
udevinfo := string(c.MustSSHf(m, "udevadm info %s", srcdev))
if !strings.Contains(udevinfo, "/dev/disk/by-id/dm-uuid-mpath-") && !strings.Contains(udevinfo, "DM_MPATH") {
c.Fatalf("mount %s has non-multipath source %s", path, srcdev)
}
out := string(c.MustSSHf(m, "srcdev=$(findmnt -nvr %s -o SOURCE) && echo \"$srcdev\" && udevadm info \"$srcdev\"", path))
parts := strings.SplitN(out, "\n", 2)
if len(parts) < 2 {
c.Fatalf("could not get device and udev info for mount %s: %s", path, out)
}
srcdev, udevinfo := parts[0], parts[1]
if !strings.Contains(udevinfo, "/dev/disk/by-id/dm-uuid-mpath-") && !strings.Contains(udevinfo, "DM_MPATH") {
c.Fatalf("mount %s has non-multipath source %s", path, srcdev)
}

}
Expand Down
Loading