[Libguestfs] [PATCH v2 nbdkit] tests: Add generic ‘requires’ function for test prerequisites.

Eric Blake eblake at redhat.com
Wed Jan 23 16:37:30 UTC 2019


On 1/23/19 10:26 AM, Richard W.M. Jones wrote:

>>> -if ! command -v qemu-img; then
>>> -    echo "$0: 'qemu-img' command not available"
>>> -    exit 77
>>> -fi
>>>  if ! qemu-img --help | grep -- --image-opts; then
>>>      echo "$0: 'qemu-img' command does not have the --image-opts option"
>>>      exit 77
>>
>> The old test insists on --image-opts,
>>
>>>  fi
>>> -if ! ip -V; then
>>> -    echo "$0: 'ip' command not available"
>>> -    exit 77
>>> -fi
>>> +
>>> +rm -f ip.pid ipv4.out ipv6.out
>>> +cleanup_fn rm -f ip.pid ipv4.out ipv6.out
>>
>> ...but the rewrite does not.  Could be solved with:
>>
>> requires qemu-img info --image-opts driver=file,filename=functions.sh
> 
> Yes - as you can see I didn't convert the old test, it's still there.

Ah, my fault for not noticing the - lines, and thinking one entire block
was replaced by another.

> However I will try your variation to see if that works instead.

Can be a separate patch on top, as needed (in general, it's always nice
to do feature tests for features that are not universally available),
the real trick is coming up with harmless command line probes for those
features where the answer can be given via $?.


>>> -
>>>  # Create partitions before and after.
>>>  truncate -s 1 partitioning2.p1
>>
>> 'truncate' is not universally available; that may be something for a
>> future patch to add a requires line for (but not this patch, which
>> should be just the mechanical rewrites).
> 
> We had a problem on FreeBSD where truncate --size does not work (their
> binary only understands truncate -s).  That was fixed by commit
> f62e3712428.  Do you know what platforms would lack truncate entirely?

POSIX doesn't require it to exist, but yeah, these days, most platforms
include BSD or GNU truncate by default.  I also note that 'requires od'
in test-eflags.sh is probably pointless, since POSIX does require od to
exist.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libguestfs/attachments/20190123/670b74cb/attachment.sig>


More information about the Libguestfs mailing list