Bug 1190590

Summary: Generate the redundant record in guest's xml while configure many same metadatas in guest's xml
Product: Red Hat Enterprise Linux 7 Reporter: zhenfeng wang <zhwang>
Component: libvirtAssignee: Peter Krempa <pkrempa>
Status: CLOSED ERRATA QA Contact: Virtualization Bugs <virt-bugs>
Severity: low Docs Contact:
Priority: low    
Version: 7.1CC: dyuan, gsun, lhuang, mzhan, pkrempa, rbalakri
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: libvirt-1.2.14-1.el7 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2015-11-19 06:14:26 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 zhenfeng wang 2015-02-09 08:52:38 UTC
Description of problem:
Generate the redundant record in guest's xml while configure many same metadatas in guest's xml

Version-Release number:
qemu-kvm-rhev-2.1.2-23.el7.x86_64
kernel-3.10.0-226.el7.x86_64
libvirt-1.2.8-16.el7.x86_64h

How reproducible:
100%

Steps to Reproduce:

1.Prepare a shutoff guest
# virsh list --all
 Id    Name                           State
----------------------------------------------------
 -     7.0                          shut off

2.Edit guest's xml, add multi same metadata in guest's xml, It will generate many redundant records
in guest's xml
# virsh dumpxml 7.0
--
  <metadata>
    <herp2erp xmlns:foobar="http://foo.bar3/" xmlns:herp2="http://herp.derp/"/>
    <herp2erp xmlns:foobar="http://foo.bar3/" xmlns:herp2="http://herp.derp/"/>
    <herp2erp xmlns:foobar="http://foo.bar3/" xmlns:herp2="http://herp.derp/"/>
    <herp2erp xmlns:foobar="http://foo.bar3/" xmlns:herp2="http://herp.derp/"/>
    <herp2erp xmlns:foobar="http://foo.bar3/" xmlns:herp2="http://herp.derp/"/>
    <herp2erp xmlns:foobar="http://foo.bar3/" xmlns:herp2="http://herp.derp/"/>
    <herp2erp xmlns:foobar="http://foo.bar3/" xmlns:herp2="http://herp.derp/"/>
  </metadata>



Actual results:
Generate the redundant record in guest's xml while configure many same metadatas in guest's xml

Expected results:
Should generate only 1 record while configure the same metadatas in guest's xml

Comment 1 Peter Krempa 2015-02-09 16:19:13 UTC
When parsing the complete XML document the contents of the <metadata> element are taken as-is. When using the API the individual members are carefully selected. Fixing this issue will require to add post-parse code that will fix the metadata element section.

Comment 2 Peter Krempa 2015-03-05 15:30:04 UTC
Fixed upstream:

commit 7909300498fc216bbf8fcafb2b770799fb8daf2c
Author: Peter Krempa <pkrempa>
Date:   Tue Mar 3 17:50:59 2015 +0100

    conf: Remove duplicate entries in <metadata> by namespace
    
    Since the APIs support just one element per namespace and while
    modifying an element all duplicates would be removed, let's do this
    right away in the post parse callback.

v1.2.13-61-g7909300

Comment 4 zhenfeng wang 2015-06-16 08:28:07 UTC
Hi peter
Verify this bug with libvirt-1.2.16-1.el7.x86_64, still could hit the comment0's issue, can you help check it? thanks

Comment 5 Peter Krempa 2015-07-17 13:12:58 UTC
The problem with the scenario that reproduces even with the patched libvirt is that the elements aren't actually in the described namespace but in the global one. To add the element to the namespace the following syntax needs to be used:

<foobar:herp2erp xmlns:foobar="http://foo.bar3/"/>

or similar.

Comment 7 zhenfeng wang 2015-07-22 09:09:22 UTC
Thanks peter's advise, so file a new bug 1245525 to track that issue  and verify this bug by adding the element to the namespace, the verify steps as following

pkginfo
libvirt-1.2.17-2.el7.x86_64

steps
1.Prepare a shutoff guest
# virsh list --all
 Id    Name                           State
----------------------------------------------------
 -     7.0                          shut off

2.Edit guest's xml, add multi same metadata in guest's xml, save the guest's xml, only 1 record will generated
#virsh edit 7.0
--
  <metadata>
<foobar:herp2erp xmlns:foobar="http://foo.bar3/"/>
<foobar:herp2erp xmlns:foobar="http://foo.bar3/"/>
<foobar:herp2erp xmlns:foobar="http://foo.bar3/"/>
<foobar:herp2erp xmlns:foobar="http://foo.bar3/"/>
<foobar:herp2erp xmlns:foobar="http://foo.bar3/"/>
<foobar:herp2erp xmlns:foobar="http://foo.bar3/"/>
<foobar:herp2erp xmlns:foobar="http://foo.bar3/"/>
  </metadata>

#virsh dumpxml 7.0
  <metadata>
    <foobar:herp2erp xmlns:foobar="http://foo.bar3/"/>
  </metadata>


3.Do some basic check the metadata command, all command could get expect result.
# virsh metadata virt-tests-vm1 --uri http://foo.bar3/
<herp2erp/>

# virsh metadata virt-tests-vm1 --uri http://foo.bar3/ --edit --key foobar
<herp2erp1/>

# virsh metadata virt-tests-vm1 --uri http://foo.bar3/ 
<herp2erp1/>

# virsh metadata virt-tests-vm1 --uri http://foo.bar3/  --remove
Metadata removed

# virsh metadata virt-tests-vm1 --uri http://foo.bar3/ 
error: metadata not found: Requested metadata element is not present

According to upper steps, mark this bug veried

Comment 9 errata-xmlrpc 2015-11-19 06:14:26 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-2202.html