Skip to content

Commit cb3d27f

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 <kolyshkin@gmail.com>
1 parent a85b5fc commit cb3d27f

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

tests/integration/update.bats

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -895,22 +895,24 @@ 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)
900+
if [ -z "$dev" ]; then
901+
echo "=== lsblk -d ===" >&2
902+
lsblk -d >&2
903+
echo "===" >&2
904+
skip "can't get device from lsblk"
906905
fi
906+
major="${dev%:*}"
907+
minor="${dev#*:}"
908+
907909
# Add an entry to check that
908910
# - existing devices can be updated;
909911
# - duplicates are handled properly;
910912
# (see func upsert* in update.go).
911913
update_config ' .linux.resources.blockIO.throttleReadBpsDevice |= [
912-
{ major: '"$major"', minor: 0, rate: 485760 },
913-
{ major: '"$major"', minor: 0, rate: 485760 }
914+
{ major: '"$major"', minor: '"$minor"', rate: 485760 },
915+
{ major: '"$major"', minor: '"$minor"', rate: 485760 }
914916
]'
915917

916918
runc run -d --console-socket "$CONSOLE_SOCKET" test_update
@@ -922,34 +924,34 @@ EOF
922924
"throttleReadBpsDevice": [
923925
{
924926
"major": $major,
925-
"minor": 0,
927+
"minor": $minor,
926928
"rate": 10485760
927929
}
928930
],
929931
"throttleWriteBpsDevice": [
930932
{
931933
"major": $major,
932-
"minor": 0,
934+
"minor": $minor,
933935
"rate": 9437184
934936
}
935937
],
936938
"throttleReadIOPSDevice": [
937939
{
938940
"major": $major,
939-
"minor": 0,
941+
"minor": $minor,
940942
"rate": 1000
941943
}
942944
],
943945
"throttleWriteIOPSDevice": [
944946
{
945947
"major": $major,
946-
"minor": 0,
948+
"minor": $minor,
947949
"rate": 900
948950
}
949951
]
950952
}
951953
}
952954
EOF
953955
[ "$status" -eq 0 ]
954-
check_cgroup_dev_iops "$major:0" 10485760 9437184 1000 900
956+
check_cgroup_dev_iops $major:$minor 10485760 9437184 1000 900
955957
}

0 commit comments

Comments
 (0)