[libvirt] [PATCH] tests: introduce qemucapsfixreplies helper

Pavel Hrdina phrdina at redhat.com
Thu Mar 1 18:03:39 UTC 2018


On Thu, Mar 01, 2018 at 04:06:00PM +0100, Andrea Bolognani wrote:
> On Thu, 2018-03-01 at 15:29 +0100, Pavel Hrdina wrote:
> > Sometimes we don't regenerate QEMU capabilities replies using QEMU
> > binary but we simply add a new entry manually.  In that case you need
> > to manually fix all the replies ids.  This helper will do that for you.
> > 
> > Signed-off-by: Pavel Hrdina <phrdina at redhat.com>
> > ---
> >  tests/qemucapsfixreplies | 22 ++++++++++++++++++++++
> >  1 file changed, 22 insertions(+)
> >  create mode 100755 tests/qemucapsfixreplies
> > 
> > diff --git a/tests/qemucapsfixreplies b/tests/qemucapsfixreplies
> > new file mode 100755
> > index 0000000000..25b1e597a9
> > --- /dev/null
> > +++ b/tests/qemucapsfixreplies
> > @@ -0,0 +1,22 @@
> > +#!/bin/sh
> > +
> > +if [ "$1" == "--help" ] || [ $# != 1 ] || [ ! -f $1 ]; then
> 
> "==" is a bashism and should be avoided. It's also a good idea to
> always quote variables, so I'd rewrite the above as
> 
>   if [ "$#" -ne 1 ] || [ "$1" = "--help" ] || [ ! -f "$1" ]; then
> 
> > +    echo "This script fixes replies ids in QEMU replies files."
> > +    echo ""
> 
> You don't need the quotes in the second call to echo.

I personally prefer the quotes, it looks better with them.

> > +    echo "      Usage: $0 path/to/qemu.replies"
> > +    exit 0;
> 
> The semicolon is unnecessary here, drop it.
> 
> > +fi
> > +
> > +awk -i inplace \
> > +    'BEGIN {count=1; pattern="libvirt-[0-9]+"}
> > +    {
> > +        if (match($0, "libvirt-1[^0-9]")) {
> > +            count=1;
> > +        }
> > +        if (match($0, pattern)) {
> > +            str="libvirt-" count;
> > +            sub(pattern, str, $0);
> > +            count++;
> > +        }
> > +        print
> > +    }' $1
> 
> "$1" should be quoted here too.
> 
> I won't speak for the awk part, but I've just used the script to
> fix a dozen .replies files and it worked flawlessly, so I'm going
> to assume there aren't any issues blocking its inclusion.
> 
> One last comment: tests/qemucapabilitiestest.c already contains a
> pointer to the highly-related qemucapsprobe utility; you should
> update that comment so that it mentions this script too.
> 
> With all of the above addressed, and assuming Michal doesn't speak
> up against your use of "--help",
> 
>   Reviewed-by: Andrea Bolognani <abologna at redhat.com>

I fixed the issues and updated the comment and I'll push it shortly,
thanks.

Pavel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20180301/5dfce55c/attachment-0001.sig>


More information about the libvir-list mailing list