Bug 1219719

Summary: change-media with --print-xml will produce a disordered xml segment.
Product: [Community] Virtualization Tools Reporter: yisun
Component: libvirtAssignee: Libvirt Maintainers <libvirt-maint>
Status: CLOSED NEXTRELEASE QA Contact:
Severity: low Docs Contact:
Priority: medium    
Version: unspecifiedCC: ashu.noella207, crobinso, dyuan, eblake, mkletzan, mprivozn, rbalakri, shyu, xuzhang, yanyang
Target Milestone: ---   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2015-11-26 14:12:48 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 yisun 2015-05-08 01:58:50 UTC
description:
change-media with --print-xml will produce a disordered xml segment.


Versions:
libvirt-1.2.14-1.el7.x86_64
kernel-3.10.0-246.el7.x86_64
qemu-kvm-rhev-2.3.0-1.el7.x86_64

Repro steps:
1. start a vm with empty cdrom
[root@yisun]#virsh dumpxml vm1 | grep cdrom -A10
    <disk type='file' device='cdrom'>
      <driver name='qemu' type='raw'/>
      <backingStore/>
      <target dev='hdb' bus='ide'/>
      <readonly/>
      <alias name='ide0-0-1'/>
      <address type='drive' controller='0' bus='0' target='0' unit='1'/>
    </disk>
...
2. use "change-media --insert" to insert a disk with "--print-xml"
[root@yisun]# virsh change-media vm1 hdb /tmp/a.iso --insert --print-xml
<disk type="file" device="cdrom">
      <driver name="qemu" type="raw"/>
      <backingStore/>
      <target dev="hdb" bus="ide"/>
      <readonly/>
      <alias name="ide0-0-1"/>
      <address type="drive" controller="0" bus="0" target="0" unit="1"/>
    <source file="/tmp/a.iso"/></disk>

Actual result:
 <source file="/tmp/a.iso"/>  inserted in the same line with </disk> without line break.

Expected result:
format should be like following:
 <disk type='file' device='cdrom'>
      <driver name='qemu' type='raw'/>
      <source file='/tmp/a.iso'/>    <=== put it here as what happens for cdrom insertion without "--print-xml"
      <backingStore/>
      <target dev='hdb' bus='ide'/>
      <readonly/>
      <alias name='ide0-0-1'/>
      <address type='drive' controller='0' bus='0' target='0' unit='1'/>
 </disk>

Additional info:
this also reproducible for "virsh change-media ... --update --print-xml"

Comment 1 Eric Blake 2015-05-08 14:52:31 UTC
Order should not matter as long as the RelaxNG grammar allows elements to be interleaved.  However, the odd formatting can indeed improve, and it never hurts to at least try and be consistent.

Comment 3 Noella 2015-10-22 07:46:42 UTC
Hello everyone,

I am interested in working on this task. I will like to know the files I should look at to fix the distorted xml segment and any other information required to fix this issue.

Thanks,
Noella

Comment 4 Michal Privoznik 2015-10-26 14:51:14 UTC
(In reply to Noella from comment #3)
> Hello everyone,
> 
> I am interested in working on this task. I will like to know the files I
> should look at to fix the distorted xml segment and any other information
> required to fix this issue.
> 
> Thanks,
> Noella

Firstly, you need to take look what xml does 'change-media' command produce. Then, you should compare it with the XML that already is existing in libvirt, e.g. 'dumpxml' command ran over a domain. You'll see which elements are disordered.

Comment 5 Martin Kletzander 2015-11-26 14:12:48 UTC
Fixed by:

commit adac38dbbdc3bd1dd7c1e99de0bdc1f59f940923
Author: Martin Kletzander <mkletzan>
Date:   Fri Nov 6 15:11:36 2015 +0100

    virsh: Try to keep printed XML pretty with change-media