Where qemu-img 4.0 used to say 'virtual size: 100M', the 4.1 release now says 'virtual size: 100 MiB'. Similarly, '5.0G' turned into '5 GiB'. But rather than worry about potential future changes to the human-readable output, we can just use --output=json (at which point we no longer even have to force qemu-img to the C locale). It might be slightly more robust to find our specific information using jq, but for now a grep of the output json is still reliable enough for our needs. If the '\b' is a problem on BSD, we could use '([, ]|$)' instead. Or that's where jq would make it easier to parse off a given number without worrying about what comes after the number. Signed-off-by: Eric Blake <eblake@redhat.com> --- We could still use jq if desired, but it was easy enough to let these tests pass instead of skip when jq is not present. tests/test-ip.sh | 10 ++++++---- tests/test-nbd-tls-psk.sh | 6 +++--- tests/test-nbd-tls.sh | 6 +++--- tests/test-tls-psk.sh | 7 +++---- tests/test-tls.sh | 7 +++---- tests/test-truncate3.sh | 4 ++-- 6 files changed, 20 insertions(+), 20 deletions(-) diff --git a/tests/test-ip.sh b/tests/test-ip.sh index 636d3d3f..5a00a2ec 100755 --- a/tests/test-ip.sh +++ b/tests/test-ip.sh @@ -57,15 +57,17 @@ kill -s 0 $pid # Check we can connect over the IPv4 loopback interface. ipv4_lo="$(ip -o -4 addr show scope host)" if test -n "$ipv4_lo"; then - qemu-img info --image-opts "file.driver=nbd,file.host=127.0.0.1,file.port=$port" > ipv4.out + qemu-img info --output=json \ + --image-opts "file.driver=nbd,file.host=127.0.0.1,file.port=$port" > ipv4.out cat ipv4.out - grep -sq "^virtual size: 100M" ipv4.out + grep -sq '"virtual-size": *104857600\b' ipv4.out fi # Check we can connect over the IPv6 loopback interface. ipv6_lo="$(ip -o -6 addr show scope host)" if test -n "$ipv6_lo"; then - qemu-img info --image-opts "file.driver=nbd,file.host=::1,file.port=$port" > ipv6.out + qemu-img info --output=json \ + --image-opts "file.driver=nbd,file.host=::1,file.port=$port" > ipv6.out cat ipv6.out - grep -sq "^virtual size: 100M" ipv6.out + grep -sq '"virtual-size": *104857600\b' ipv6.out fi diff --git a/tests/test-nbd-tls-psk.sh b/tests/test-nbd-tls-psk.sh index d0bbc468..82822d11 100755 --- a/tests/test-nbd-tls-psk.sh +++ b/tests/test-nbd-tls-psk.sh @@ -73,9 +73,9 @@ LIBNBD_DEBUG=1 start_nbdkit -P "$pid2" -U "$sock2" --tls=off \ nbd tls=require tls-psk=keys.psk tls-username=qemu socket="$sock1" # Run unencrypted client -LANG=C qemu-img info -f raw "nbd+unix:///?socket=$sock2" > nbd-tls-psk.out +qemu-img info --output=json -f raw "nbd+unix:///?socket=$sock2" > nbd-tls-psk.out cat nbd-tls-psk.out -grep -sq "^file format: raw" nbd-tls-psk.out -grep -sq "^virtual size: 100M" nbd-tls-psk.out +grep -sq '"format": *"raw"' nbd-tls-psk.out +grep -sq '"virtual-size": *104857600\b' nbd-tls-psk.out diff --git a/tests/test-nbd-tls.sh b/tests/test-nbd-tls.sh index af824d23..c4f4faca 100755 --- a/tests/test-nbd-tls.sh +++ b/tests/test-nbd-tls.sh @@ -74,9 +74,9 @@ LIBNBD_DEBUG=1 start_nbdkit -P "$pid2" -U "$sock2" --tls=off \ nbd tls=require tls-certificates="$pkidir" socket="$sock1" # Run unencrypted client -LANG=C qemu-img info -f raw "nbd+unix:///?socket=$sock2" > nbd-tls.out +qemu-img info --output=json -f raw "nbd+unix:///?socket=$sock2" > nbd-tls.out cat nbd-tls.out -grep -sq "^file format: raw" nbd-tls.out -grep -sq "^virtual size: 100M" nbd-tls.out +grep -sq '"format": *"raw"' nbd-tls.out +grep -sq '"virtual-size": *104857600\b' nbd-tls.out diff --git a/tests/test-tls-psk.sh b/tests/test-tls-psk.sh index 393f5893..a4ecb604 100755 --- a/tests/test-tls-psk.sh +++ b/tests/test-tls-psk.sh @@ -72,12 +72,11 @@ start_nbdkit -P tls-psk.pid -p $port -n \ --tls=require --tls-psk=keys.psk example1 # Run qemu-img against the server. -LANG=C \ -qemu-img info \ +qemu-img info --output=json \ --object "tls-creds-psk,id=tls0,endpoint=client,dir=$PWD" \ --image-opts "file.driver=nbd,file.host=localhost,file.port=$port,file.tls-creds=tls0" > tls-psk.out cat tls-psk.out -grep -sq "^file format: raw" tls-psk.out -grep -sq "^virtual size: 100M" tls-psk.out +grep -sq '"format": *"raw"' tls-psk.out +grep -sq '"virtual-size": *104857600\b' tls-psk.out diff --git a/tests/test-tls.sh b/tests/test-tls.sh index 70d40aea..2718e552 100755 --- a/tests/test-tls.sh +++ b/tests/test-tls.sh @@ -65,12 +65,11 @@ start_nbdkit -P tls.pid -p $port -n --tls=require \ --tls-certificates="$pkidir" example1 # Run qemu-img against the server. -LANG=C \ -qemu-img info \ +qemu-img info --output=json \ --object "tls-creds-x509,id=tls0,endpoint=client,dir=$pkidir" \ --image-opts "file.driver=nbd,file.host=localhost,file.port=$port,file.tls-creds=tls0" > tls.out cat tls.out -grep -sq "^file format: raw" tls.out -grep -sq "^virtual size: 100M" tls.out +grep -sq '"format": *"raw"' tls.out +grep -sq '"virtual-size": *104857600\b' tls.out diff --git a/tests/test-truncate3.sh b/tests/test-truncate3.sh index 0a7fba8b..885d58f0 100755 --- a/tests/test-truncate3.sh +++ b/tests/test-truncate3.sh @@ -50,8 +50,8 @@ start_nbdkit -P truncate3.pid -U $sock \ pattern 5G \ round-up=512 -LANG=C qemu-img info nbd:unix:$sock > truncate3.out -if ! grep "virtual size: 5.0G" truncate3.out; then +qemu-img info --output=json nbd:unix:$sock > truncate3.out +if ! grep '"virtual-size": *5368709120' truncate3.out; then echo "$0: unexpected output from truncate3 regression test:" cat truncate3.out exit 1 -- 2.20.1