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"
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.
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
(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.
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