Bug 1213274

Summary: Improve the misunderstanding error messages of virt-tar-in/virt-tar-out/virt-copy-in/virt-copy-out
Product: [Community] Virtualization Tools Reporter: Lingfei Kong <lkong>
Component: libguestfsAssignee: Richard W.M. Jones <rjones>
Status: NEW --- QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: low Docs Contact:
Priority: low    
Version: unspecifiedCC: leiwang, ptoscano, rjones, virt-maint
Target Milestone: ---Keywords: Improvement, Reopened
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Enhancement
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2016-07-19 20:53:03 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Lingfei Kong 2015-04-20 08:47:56 UTC
Description of problem:
At some situations, virt-tar-in/virt-tar-out/virt-copy-in/virt-copy-out will output some misunderstanding error messages due to the simple wrapper around the guestfish. I have wrote another simple wrapper to guestfish, it can improve this situation and give a proper error message. I have tested this version of wrapper, it works well, it can also used to virt-tar-out/virt-copy-in/virt-copy-out. Here is the new wrapper:

base_name="$(basename $0)"
requiredarg()
{
    [ -z "$2" ] && {
        echo "$base_name: option requires an argument -- '${1//-/}'" >&2
        echo "Try \`$base_name --help' for more information." >&2
        exit
    }
    
    add_disk="$1 $2"
    ((args++))
}

while [[ -n $1 ]]; do
    args=1
    case "$1" in
        -h | --help )
            exec man "$base_name"
            ;;
        -a | -d)
            requiredarg "$@"
            ;;
        -+ )
            echo "$base_name: invalid option -- '${1//-/}'" >&2
            echo "Try \`$base_name --help' for more information." >&2
            exit
            ;;
        *)
            other_opts="$other_opts $1"
            ;;
    esac
    shift "$args"
done

[ -z "$add_disk" ] && {
    echo "$base_name: error: you must give either -a or -d options." >&2
    echo "Try \`$base_name --help' for more information." >&2
    exit
}

exec guestfish --rw -i $add_disk tar-in $other_opts
        
        
Version-Release number of selected component (if applicable):
libguestfs-tools-c-1.29.33-1.fc22.x86_64
        
        
How reproducible:
100%
        
        
Steps to Reproduce:
# virt-tar-in
libguestfs: error: no libvirt domain called 'tar-in': Domain not found: no domain with matching name 'tar-in'

# virt-tar-in Fedora-20.raw
libguestfs: error: no libvirt domain called 'tar-in': Domain not found: no domain with matching name 'tar-in'

# virt-tar-in -c
guestfish: option requires an argument -- 'c'
Try `guestfish --help' for more information.


Actual results:
As above

Expected results:
# virt-tar-in
virt-tar-in: error: you must give either -a or -d options.
Try `virt-tar-in --help' for more information.

# virt-tar-in Fedora-20.raw
virt-tar-in: error: you must give either -a or -d options.
Try `virt-tar-in --help' for more information.
        
# virt-tar-in -c
virt-tar-in: error: you must give either -a or -d options.
Try `virt-tar-in --help' for more information.


Additional info:

Comment 1 Richard W.M. Jones 2015-04-20 11:39:21 UTC
Although this is better than what we've got right now, this:

>         *)
>             other_opts="$other_opts $1"

doesn't quote the parameter correctly.  For example it would fail
if passed:

  virt-tar-in -a foo.img "Some File With A Space.tar" /bar

The way around that is to use bash arrays ... bleahhh.

Probably best to post a patch to the mailing list.

Comment 2 Lingfei Kong 2015-04-20 14:14:09 UTC
(In reply to Richard W.M. Jones from comment #1)
> Although this is better than what we've got right now, this:
> 
> >         *)
> >             other_opts="$other_opts $1"
> 
> doesn't quote the parameter correctly.  For example it would fail
> if passed:
> 
>   virt-tar-in -a foo.img "Some File With A Space.tar" /bar
> 
> The way around that is to use bash arrays ... bleahhh.
> 
> Probably best to post a patch to the mailing list.

Sorry, i missed this situation, possible i will post a patch if the code is ready to use. 

Thanks!

Comment 4 Fedora End Of Life 2016-07-19 20:53:03 UTC
Fedora 22 changed to end-of-life (EOL) status on 2016-07-19. Fedora 22 is
no longer maintained, which means that it will not receive any further
security or bug fix updates. As a result we are closing this bug.

If you can reproduce this bug against a currently maintained version of
Fedora please feel free to reopen this bug against that version. If you
are unable to reopen this bug, please file a new report against the
current release. If you experience problems, please add a comment to this
bug.

Thank you for reporting this bug and we are sorry it could not be fixed.