Bug 1140894

Summary: No error messages output if append '--format qcow2' after '-a guest.img', guest.img is a raw format image file
Product: Red Hat Enterprise Linux 7 Reporter: Lingfei Kong <lkong>
Component: libguestfsAssignee: Richard W.M. Jones <rjones>
Status: CLOSED ERRATA QA Contact: Virtualization Bugs <virt-bugs>
Severity: low Docs Contact:
Priority: low    
Version: 7.1CC: huzhan, leiwang, mbooth, ptoscano, wshi
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: libguestfs-1.27.45-1.1.el7 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
: 1203595 (view as bug list) Environment:
Last Closed: 2015-03-05 13:44:31 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:
Bug Depends On:    
Bug Blocks: 1203595    

Description Lingfei Kong 2014-09-12 01:27:37 UTC
Description of problem:
No error messages output if append '--format qcow2' after '-a guest.img', but if i put '--format qcow2' before '-a guest.img', virt-sysprep will detect the image format and print a error.


Version-Release number of selected component (if applicable):
libguestfs-1.27.39-1.1.el7


How reproducible:
100%


Steps to Reproduce:
1. Create a raw format guest image: rhel6.6.img
2. #virt-sysprep --operations net-hostname -a rhel6.6.img --format qcow2
[   0.0] Examining the guest ...
[   7.0] Performing "net-hostname" ...


Here is the trace information:
[   0.0] Examining the guest ...
libguestfs: trace: set_verbose true
libguestfs: trace: set_verbose = 0
libguestfs: create: flags = 0, handle = 0x1d5fcf0, program = virt-sysprep
libguestfs: trace: add_drive "rhel6.6.img" "readonly:false" "protocol:file" "discard:besteffort"
libguestfs: trace: add_drive = 0
libguestfs: trace: launch
..........................................
supermin: if-newer: output does not need rebuilding
libguestfs: [00081ms] finished building supermin appliance
libguestfs: trace: disk_create "/tmp/libguestfsteZwlw/overlay1" "qcow2" -1 "backingfile:/var/tmp/.guestfs-0/appliance.d/root" "backingformat:raw"
libguestfs: command: run: qemu-img
libguestfs: command: run: \ create
libguestfs: command: run: \ -f qcow2
libguestfs: command: run: \ -o backing_file=/var/tmp/.guestfs-0/appliance.d/root,backing_fmt=raw
libguestfs: command: run: \ /tmp/libguestfsteZwlw/overlay1
Formatting '/tmp/libguestfsteZwlw/overlay1', fmt=qcow2 size=4294967296 backing_file='/var/tmp/.guestfs-0/appliance.d/root' backing_fmt='raw' encryption=off cluster_size=65536 lazy_refcounts=off
libguestfs: trace: disk_create = 0
libguestfs: [00148ms] create libvirt XML
libguestfs: trace: disk_format "rhel6.6.img"
libguestfs: command: run: qemu-img
libguestfs: command: run: \ --help
libguestfs: which_parser: g->qemu_img_info_parser = 1
libguestfs: command: run: qemu-img
libguestfs: command: run: \ info
libguestfs: command: run: \ --output json
libguestfs: command: run: \ /dev/fd/9
libguestfs: parse_json: qemu-img info JSON output:\n{\n    "virtual-size": 10486808576, \n    "filename": "/dev/fd/9", \n    "format": "raw", \n    "actual-size": 10486808576\n}\n\n
libguestfs: trace: disk_format = "raw" 
libguestfs: trace: get_cachedir
libguestfs: trace: get_cachedir = "/var/tmp"


3. #virt-sysprep --operations net-hostname --format qcow2 -a rhel6.6.img
[   0.0] Examining the guest ...
Fatal error: exception Guestfs.Error("could not create appliance through libvirt.

Try running qemu directly without libvirt using this environment variable:
export LIBGUESTFS_BACKEND=direct

Original error from libvirt: internal error: process exited while connecting to monito

Here is the trace information:
[   0.0] Examining the guest ...
libguestfs: trace: set_verbose true
libguestfs: trace: set_verbose = 0
libguestfs: create: flags = 0, handle = 0x25d4cf0, program = virt-sysprep
libguestfs: trace: add_drive "rhel6.6.img" "readonly:false" "format:qcow2" "protocol:file" "discard:besteffort"
libguestfs: trace: add_drive = 0
libguestfs: trace: launch
......................................................
libguestfs: command: run: \ --if-newer
libguestfs: command: run: \ --lock /var/tmp/.guestfs-0/lock
libguestfs: command: run: \ --copy-kernel
libguestfs: command: run: \ -f ext2
libguestfs: command: run: \ --host-cpu x86_64
libguestfs: command: run: \ /usr/lib64/guestfs/supermin.d
libguestfs: command: run: \ -o /var/tmp/.guestfs-0/appliance.d
supermin: version: 5.1.9
supermin: rpm: detected RPM version 4.11
supermin: package handler: fedora/rpm
supermin: acquiring lock on /var/tmp/.guestfs-0/lock
supermin: if-newer: output does not need rebuilding
libguestfs: [00058ms] finished building supermin appliance
libguestfs: trace: disk_create "/tmp/libguestfsfGdQiJ/overlay1" "qcow2" -1 "backingfile:/var/tmp/.guestfs-0/appliance.d/root" "backingformat:raw"
libguestfs: command: run: qemu-img
libguestfs: command: run: \ create
libguestfs: command: run: \ -f qcow2
libguestfs: command: run: \ -o backing_file=/var/tmp/.guestfs-0/appliance.d/root,backing_fmt=raw
libguestfs: command: run: \ /tmp/libguestfsfGdQiJ/overlay1
Formatting '/tmp/libguestfsfGdQiJ/overlay1', fmt=qcow2 size=4294967296 backing_file='/var/tmp/.guestfs-0/appliance.d/root' backing_fmt='raw' encryption=off cluster_size=65536 lazy_refcounts=off
libguestfs: trace: disk_create = 0
libguestfs: [00112ms] create libvirt XML
libguestfs: trace: get_cachedir
libguestfs: trace: get_cachedir = "/var/tmp"


Actual results:
Step 2 have no message output, it seems virt-sysprep use auto-detection model even though you append '--format qcow2' at the end of the command line.


Expected results:
Step 2 have a error message output, because you specify '--format qcow2', but guest.img is a raw format file

Additional info:

Comment 2 Richard W.M. Jones 2014-09-13 08:11:12 UTC
(In reply to Lingfei Kong from comment #0)
> Actual results:
> Step 2 have no message output, it seems virt-sysprep use auto-detection
> model even though you append '--format qcow2' at the end of the command line.

As it says in the manual page, you have to put the --format before
the -a parameter:

       --format raw|qcow2|..
       --format auto
           The default for the -a option is to auto-detect the format of the
           disk image.  Using this forces the disk format for -a options which
           follow on the command line.  Using --format auto switches back to
           auto-detection for subsequent -a options.

           For example:

            virt-sysprep --format raw -a disk.img

           forces raw format (no auto-detection) for "disk.img".

            virt-sysprep --format raw -a disk.img --format auto -a another.img

           forces raw format (no auto-detection) for "disk.img" and reverts to
           auto-detection for "another.img".

However we should probably give an error if there is a useless '--format'
after the last -a parameter.  I will see if this is a low-risk change.

Comment 3 Richard W.M. Jones 2014-09-13 09:52:03 UTC
Upstream fix is:
https://github.com/libguestfs/libguestfs/commit/b7bdb63d8967762a5b234049c4dda911150cc199
which will appear in >= 1.27.45.

Comment 5 Lingfei Kong 2014-10-22 07:09:40 UTC
Verify with libguestfs-1.28.1-1.2.el7

Steps to verify:
#virt-sysprep --hostname unused -a rhel.img --format raw
virt-sysprep: error: --format parameter must appear before -a parameter

If reporting bugs, run virt-sysprep with debugging enabled and include the 
complete output:

  virt-sysprep -v -x [...]
#virt-sysprep --hostname unused -a rhel.img --format qcow2
virt-sysprep: error: --format parameter must appear before -a parameter

If reporting bugs, run virt-sysprep with debugging enabled and include the 
complete output:

  virt-sysprep -v -x [...]

There is a proper error messages, so bug is fixed.

Comment 7 errata-xmlrpc 2015-03-05 13:44:31 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://rhn.redhat.com/errata/RHBA-2015-0303.html