Bug 1592737

Summary: Cannot use a xml file with XML declaration as a input of cpu-compare
Product: Red Hat Enterprise Linux 7 Reporter: Luyao Huang <lhuang>
Component: libvirtAssignee: Jiri Denemark <jdenemar>
Status: CLOSED ERRATA QA Contact: jiyan <jiyan>
Severity: medium Docs Contact:
Priority: medium    
Version: 7.6CC: bugproxy, chwen, dyuan, dzheng, fjin, hannsj_uhl, jdenemar, jiyan, jomurphy, lmen, xuzhang, yalzhang, yanqzhan
Target Milestone: rcKeywords: Automation, Regression
Target Release: 7.7   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: libvirt-4.5.0-12.el7 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2019-08-06 13:13:52 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: 1598750, 1619379, 1651787, 1659045, 1659048    

Description Luyao Huang 2018-06-19 08:03:57 UTC
Description of problem:
Cannot use a xml file with XML declaration as a input of cpu-compare

Version-Release number of selected component (if applicable):
libvirt-4.4.0-2.el7.x86_64

How reproducible:
100%

Steps to Reproduce:
1. prepare a xml with XML declaration for cpu-compare cmd:

# cat /tmp/cpu.xml
<?xml version='1.0' encoding='UTF-8'?><cpu><vendor>Intel</vendor><model>Haswell-noTSX-IBRS</model><feature name="vme" policy="require" /><feature name="ds" policy="require" /><feature name="acpi" policy="require" /><feature name="ss" policy="require" /><feature name="ht" policy="require" /><feature name="tm" policy="require" /><feature name="pbe" policy="require" /><feature name="dtes64" policy="require" /><feature name="monitor" policy="require" /><feature name="ds_cpl" policy="require" /><feature name="vmx" policy="require" /><feature name="smx" policy="require" /><feature name="est" policy="require" /><feature name="tm2" policy="require" /><feature name="xtpr" policy="require" /><feature name="pdcm" policy="require" /><feature name="dca" policy="require" /><feature name="osxsave" policy="require" /><feature name="f16c" policy="require" /><feature name="rdrand" policy="require" /><feature name="arat" policy="require" /><feature name="tsc_adjust" policy="require" /><feature name="cmt" policy="require" /><feature name="stibp" policy="require" /><feature name="xsaveopt" policy="require" /><feature name="pdpe1gb" policy="require" /><feature name="abm" policy="require" /><feature name="invtsc" policy="require" /></cpu>

2. use cpu-compare

# virsh cpu-compare /tmp/cpu.xml
error: /tmp/cpu.xml:1: XML declaration allowed only at the start of the document
<container><?xml version='1.0' encoding='UTF-8'?>
 ----------------^

3.

Actual results:
libvirt direct put the string in input xml file in <container>%s</container>, and this will cause the xml with XML declaration cannot work with this command anymore

Expected results:
return cpu compare result in step 2

Additional info:

Caught by avocado, and cannot be reproduced in 4.3.0

Comment 3 Jiri Denemark 2018-09-06 15:13:40 UTC
The cpu-compare and cpu-baseline virsh commands were made user friendly so
that the user can pass various XMLs generated by other libvirt commands to
them. The cpu-compare command takes a single XML document, while cpu-baseline
accepts several concatenated XMLs. Thus there were two separate pieces of code
dealing with the same. When I was adding the hypervisor variants of these
commands I had to add support for parsing one more type of XML document
generated by libvirt. While doing that, I merged the code for all the commands
to reduce duplication. And because libvirt never produces the <?xml ?>
declaration, the code does not work correctly when it sees <?xml ?>.

I will try to look at this and come up with a fix which would not be too
hacky. However, I don't see this as a big priority. Only virsh is affected,
calling libvirt API (even using some of the bindings) directly would just
work. And all avocado tests should really be rewritten to use libvirt's python
bindings.

Comment 4 Jiri Denemark 2018-11-23 11:54:34 UTC
Patch sent upstream for review:
https://www.redhat.com/archives/libvir-list/2018-November/msg00838.html

Comment 5 Jiri Denemark 2018-11-29 12:58:24 UTC
Fixed upstream by

commit fcd1c865e168bdb9763b19e790c15e80aa29be66
Refs: v4.10.0-rc1-5-gfcd1c865e1
Author:     Jiri Denemark <jdenemar>
AuthorDate: Thu Nov 22 16:28:56 2018 +0100
Commit:     Jiri Denemark <jdenemar>
CommitDate: Thu Nov 29 11:46:42 2018 +0100

    virsh: Strip XML declaration when extracting CPU XMLs

    Since commit v4.3.0-336-gc84726fbdd all
    {hypervisor-,}cpu-{baseline,compare} commands use a generic
    vshExtractCPUDefXMLs helper for extracting individual CPU definitions
    from the provided input file. The helper wraps the input file in a
    <container> element so that several independent elements can be easily
    parsed from the file. This works fine except when the file starts with
    XML declaration (<?xml version="1.0" ... ?>) because the XML declaration
    cannot be put inside any element. In fact it has to be at the very
    beginning of the XML document without any preceding white space
    characters. We can just simply skip the XML declaration.

    https://bugzilla.redhat.com/show_bug.cgi?id=1592737

    Signed-off-by: Jiri Denemark <jdenemar>
    Reviewed-by: Ján Tomko <jtomko>

Comment 7 Jiri Denemark 2018-12-13 13:18:54 UTC
*** Bug 1659045 has been marked as a duplicate of this bug. ***

Comment 8 IBM Bug Proxy 2018-12-13 13:24:27 UTC
------- Comment From satheera.com 2018-12-13 08:08 EDT-------
Fixed by upstream commit

Comment 13 jiyan 2019-04-10 05:53:01 UTC
Verified on libvirt-4.5.0-12.el7.x86_64.

Version:
kernel-3.10.0-1036.el7.x86_64
libvirt-4.5.0-12.el7.x86_64
qemu-kvm-rhev-2.12.0-25.el7.x86_64

Steps:
1. Prepare 2 intel/AMD hosts, and get the output of 'virsh capabilities' on each host
# virsh capabilities >> cap_1.xml

# virsh capabilities >> cap_2.xml

# cat cap_1.xml >> cap.xml 

# cat cap_2.xml >> cap.xml

2. Test {hypervisor-,}cpu-{baseline,compare} commands with the 'cpu.xml' above
# virsh hypervisor-cpu-baseline cap.xml 
<cpu mode='custom' match='exact'>
  <model fallback='forbid'>Penryn</model>
  <vendor>Intel</vendor>
  <feature policy='require' name='vme'/>
  <feature policy='require' name='ds'/>
  <feature policy='require' name='acpi'/>
  <feature policy='require' name='ss'/>
  <feature policy='require' name='ht'/>
  <feature policy='require' name='tm'/>
  <feature policy='require' name='pbe'/>
  <feature policy='require' name='dtes64'/>
  <feature policy='require' name='monitor'/>
  <feature policy='require' name='ds_cpl'/>
  <feature policy='require' name='vmx'/>
  <feature policy='require' name='tm2'/>
  <feature policy='require' name='xtpr'/>
  <feature policy='require' name='pdcm'/>
  <feature policy='require' name='xsave'/>
  <feature policy='require' name='osxsave'/>
</cpu>

# virsh hypervisor-cpu-compare cap.xml 
CPU described in cap.xml is incompatible with the CPU provided by hypervisor on the host

# virsh cpu-baseline cap.xml 
<cpu mode='custom' match='exact'>
  <model fallback='allow'>Penryn</model>
  <vendor>Intel</vendor>
  <feature policy='require' name='vme'/>
  <feature policy='require' name='ds'/>
  <feature policy='require' name='acpi'/>
  <feature policy='require' name='ss'/>
  <feature policy='require' name='ht'/>
  <feature policy='require' name='tm'/>
  <feature policy='require' name='pbe'/>
  <feature policy='require' name='dtes64'/>
  <feature policy='require' name='monitor'/>
  <feature policy='require' name='ds_cpl'/>
  <feature policy='require' name='vmx'/>
  <feature policy='require' name='tm2'/>
  <feature policy='require' name='xtpr'/>
  <feature policy='require' name='pdcm'/>
  <feature policy='require' name='xsave'/>
  <feature policy='require' name='osxsave'/>
</cpu>

# virsh cpu-compare cap.xml 
CPU described in cap.xml is incompatible with host CPU

All the test results are as expected, move this bug to be verified.

Comment 14 jiyan 2019-06-18 06:00:30 UTC
In step-1, Add the <?xml version='1.0' encoding='UTF-8'?> XMl declaration at the first of each file.

Comment 16 errata-xmlrpc 2019-08-06 13:13:52 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://access.redhat.com/errata/RHSA-2019:2294