nbdsh has some advantages over qemu-io: - scriptable - allows us to more finely control NBD commands, such as making subsector-sized requests and controlling how many commands are sent on the wire - can write controlled patterns - can read NBD export flags --- README | 2 ++ tests/Makefile.am | 5 +++-- tests/test-error0.sh | 13 +++++++------ tests/test-error100.sh | 19 ++++++++++++------- tests/test-full.sh | 32 +++++++++++++++++++++++--------- 5 files changed, 47 insertions(+), 24 deletions(-) diff --git a/README b/README index b78f490..187da49 100644 --- a/README +++ b/README @@ -164,6 +164,8 @@ For non-essential enhancements to the test suite: - mke2fs (from e2fsprogs) + - nbdsh (from libnbd) + - qemu-img, qemu-io, qemu-nbd (usually shipped with qemu) - sfdisk (from util-linux) diff --git a/tests/Makefile.am b/tests/Makefile.am index b581cf6..b5806bb 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -355,12 +355,13 @@ if HAVE_LIBGUESTFS check_PROGRAMS += $(LIBGUESTFS_TESTS) TESTS += $(LIBGUESTFS_TESTS) -# Use the 'direct' backend, and ensure maximum libguestfs debugging is -# written to the *.log files in case there is a problem. +# Use the 'direct' backend, and ensure maximum libguestfs and libnbd +# debugging is written to the *.log files in case there is a problem. TESTS_ENVIRONMENT += \ LIBGUESTFS_ATTACH_METHOD=appliance \ LIBGUESTFS_DEBUG=1 \ LIBGUESTFS_TRACE=1 \ + LIBNBD_DEBUG=1 \ $(NULL) # Common test library. diff --git a/tests/test-error0.sh b/tests/test-error0.sh index fe97354..de9dca2 100755 --- a/tests/test-error0.sh +++ b/tests/test-error0.sh @@ -34,7 +34,7 @@ source ./functions.sh set -e set -x -requires qemu-io --version +requires nbdsh --version sock=`mktemp -u` files="$sock error0.pid" @@ -47,8 +47,9 @@ start_nbdkit -P error0.pid -U $sock \ pattern 1G error-rate=0% # Because error rate is 0%, reads should never fail. -qemu-io -r -f raw "nbd+unix://?socket=$sock" \ - -c "r 0M 10M" \ - -c "r 20M 10M" \ - -c "r 40M 10M" \ - -c "r 60M 10M" +nbdsh --connect "nbd+unix://?socket=$sock" \ + -c 'mbytes = 2**20' \ + -c 'h.pread(10*mbytes, 0)' \ + -c 'h.pread(10*mbytes, 20*mbytes)' \ + -c 'h.pread(10*mbytes, 40*mbytes)' \ + -c 'h.pread(10*mbytes, 60*mbytes)' diff --git a/tests/test-error100.sh b/tests/test-error100.sh index 64056ce..a2d3bdc 100755 --- a/tests/test-error100.sh +++ b/tests/test-error100.sh @@ -34,7 +34,7 @@ source ./functions.sh set -e set -x -requires qemu-io --version +requires nbdsh --version sock=`mktemp -u` files="$sock error100.pid" @@ -46,11 +46,16 @@ start_nbdkit -P error100.pid -U $sock \ --filter=error \ pattern 1G error-rate=100% -# The error rate is 100% so every operation must fail. +# The error rate is 100% so every operation must fail with error EIO. for i in {1..100}; do - if qemu-io -r -f raw "nbd+unix://?socket=$sock" \ - -c "r 0 512"; then - echo "$0: expected qemu-io command to fail" - exit 1 - fi + nbdsh --connect "nbd+unix://?socket=$sock" \ + -c ' +try: + h.pread (512, 0) + # This should not happen. + exit (1) +except nbd.Error as ex: + # Check the errno is expected. + assert ex.errno == "EIO" +' done diff --git a/tests/test-full.sh b/tests/test-full.sh index 47bff5e..8f237dd 100755 --- a/tests/test-full.sh +++ b/tests/test-full.sh @@ -36,7 +36,7 @@ source ./functions.sh set -e -requires qemu-io --version +requires nbdsh --version sock=`mktemp -u` files="full.pid $sock full.out" @@ -47,13 +47,27 @@ cleanup_fn rm -f $files start_nbdkit -P full.pid -U $sock full 1M # All reads should succeed. -qemu-io -f raw "nbd+unix://?socket=$sock" \ - -c 'r -v 0 512' \ - -c 'r -v 512 512' \ - -c 'r -v 1048064 512' +nbdsh --connect "nbd+unix://?socket=$sock" \ + -c 'h.pread (512, 0)' \ + -c 'h.pread (512, 512)' \ + -c 'h.pread (512, 1048064)' # All writes should fail with the ENOSPC error. -! LANG=C qemu-io -f raw "nbd+unix://?socket=$sock" \ - -c 'w -P 1 0 512' \ - -c 'w -P 2 1048064 512' >& full.out -grep "No space left on device" full.out +nbdsh --connect "nbd+unix://?socket=$sock" \ + -c ' +try: + h.pwrite (bytearray (512), 0) + # This should not happen. + exit (1) +except nbd.Error as ex: + # Check the errno is expected. + assert ex.errno == "ENOSPC" + +try: + h.pwrite (bytearray (512), 1048064) + # This should not happen. + exit (1) +except nbd.Error as ex: + # Check the errno is expected. + assert ex.errno == "ENOSPC" +' -- 2.23.0