Skip to content

Commit 46dac58

Browse files
committed
tests/int/update: fix getting block major
Apparently, having a minor of 0 does not always mean it's the whole device (not a partition): === /proc/partitions (using major: 259) === major minor #blocks name 8 16 78643200 sdb 8 17 77593583 sdb1 8 30 4096 sdb14 8 31 108544 sdb15 259 0 934912 sdb16 8 0 78643200 sda 8 1 78641152 sda1 Rewrite the test to not assume minor is 0, and use lsblk -d to find out whole devices. This fixes a test case which was added in commit 7696402. Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent 8a1335c commit 46dac58

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

tests/integration/update.bats

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -895,22 +895,23 @@ EOF
895895
@test "update per-device iops/bps values" {
896896
[ $EUID -ne 0 ] && requires rootless_cgroup
897897

898-
# We need a major number of any disk device. Usually those are partitioned,
899-
# with the device itself having minor of 0, and partitions are 1, 2...
900-
major=$(awk '$2 == 0 {print $1; exit}' /proc/partitions)
901-
if [ "$major" = "0" ] || [ "$major" = "" ]; then
902-
echo "=== /proc/partitions ==="
903-
cat /proc/partitions
904-
echo "==="
905-
skip "can't get device major number from /proc/partitions (got $major)"
898+
# Need major:minor for any block device (but not a partition).
899+
dev=$(lsblk -dno MAJ:MIN | head -1 | tr -d ' \t\n')
900+
if [ -z "$dev" ]; then
901+
echo "=== lsblk -d ===" >&2
902+
lsblk -d >&2
903+
echo "===" >&2
904+
fail "can't get device from lsblk"
906905
fi
906+
IFS=':' read -r major minor <<<"$dev"
907+
907908
# Add an entry to check that
908909
# - existing devices can be updated;
909910
# - duplicates are handled properly;
910911
# (see func upsert* in update.go).
911912
update_config ' .linux.resources.blockIO.throttleReadBpsDevice |= [
912-
{ major: '"$major"', minor: 0, rate: 485760 },
913-
{ major: '"$major"', minor: 0, rate: 485760 }
913+
{ major: '"$major"', minor: '"$minor"', rate: 485760 },
914+
{ major: '"$major"', minor: '"$minor"', rate: 485760 }
914915
]'
915916

916917
runc run -d --console-socket "$CONSOLE_SOCKET" test_update
@@ -922,34 +923,34 @@ EOF
922923
"throttleReadBpsDevice": [
923924
{
924925
"major": $major,
925-
"minor": 0,
926+
"minor": $minor,
926927
"rate": 10485760
927928
}
928929
],
929930
"throttleWriteBpsDevice": [
930931
{
931932
"major": $major,
932-
"minor": 0,
933+
"minor": $minor,
933934
"rate": 9437184
934935
}
935936
],
936937
"throttleReadIOPSDevice": [
937938
{
938939
"major": $major,
939-
"minor": 0,
940+
"minor": $minor,
940941
"rate": 1000
941942
}
942943
],
943944
"throttleWriteIOPSDevice": [
944945
{
945946
"major": $major,
946-
"minor": 0,
947+
"minor": $minor,
947948
"rate": 900
948949
}
949950
]
950951
}
951952
}
952953
EOF
953954
[ "$status" -eq 0 ]
954-
check_cgroup_dev_iops "$major:0" 10485760 9437184 1000 900
955+
check_cgroup_dev_iops "$dev" 10485760 9437184 1000 900
955956
}

0 commit comments

Comments
 (0)