Bug 1219719 - change-media with --print-xml will produce a disordered xml segment.
Summary: change-media with --print-xml will produce a disordered xml segment.
Keywords:
Status: CLOSED NEXTRELEASE
Alias: None
Product: Virtualization Tools
Classification: Community
Component: libvirt
Version: unspecified
Hardware: x86_64
OS: Linux
medium
low
Target Milestone: ---
Assignee: Libvirt Maintainers
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2015-05-08 01:58 UTC by yisun
Modified: 2016-03-18 18:44 UTC (History)
10 users (show)

Fixed In Version:
Clone Of:
Environment:
Last Closed: 2015-11-26 14:12:48 UTC
Embargoed:


Attachments (Terms of Use)

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


Note You need to log in before you can comment on or make changes to this bug.