Bug 1223688

Summary: virt-xml-validate should accept both DHCPv4 and static IPv4 addresses concurrently
Product: Red Hat Enterprise Linux 7 Reporter: Hu Jianwei <jiahu>
Component: libvirtAssignee: Laine Stump <laine>
Status: CLOSED ERRATA QA Contact: Virtualization Bugs <virt-bugs>
Severity: medium Docs Contact:
Priority: medium    
Version: 7.1CC: dyuan, honzhang, laine, mzhan, rbalakri, shyu
Target Milestone: rc   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: libvirt-1.2.16-1.el7 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2015-11-19 06:31:27 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 Hu Jianwei 2015-05-21 08:52:16 UTC
Description of problem:
virt-xml-validate should accept both DHCPv4 and static IPv4 addresses concurrently 

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

How reproducible:
100%

Steps to Reproduce:
[root@localhost ~]# cat eth1.xml 
<interface type='ethernet' name='eth1'>
  <start mode='none'/>
  <mac address='00:1B:21:27:4E:CE'/>
  <mtu size='1500'/>
  <protocol family='ipv4'>
    <dhcp/>
    <ip address='192.168.1.111' prefix='24'/>
  </protocol>
  <protocol family='ipv6'>
    <dhcp/>
    <ip address='2001:db8:ca2:2::1' prefix='64'/>
  </protocol>
</interface>
[root@localhost ~]# virt-xml-validate eth1.xml
Relax-NG validity error : Extra element protocol in interleave
eth1.xml:5: element protocol: Relax-NG validity error : Element interface failed to validate content
eth1.xml:3: element mac: Relax-NG validity error : Invalid sequence in interleave
eth1.xml fails to validate

Actual results:
As shown above steps, AFAIK,libvirt should be same as netcf, we need a patch for /usr/share/libvirt/schemas/interface.rng 

Expected results:
Fix it.

Additional info:
Please refer to below netcf bug:
Bug 1113983 - netcf should allow interfaces to be configured with both DHCPv4 and static IPv4 addresses at the same time
https://git.fedorahosted.org/cgit/netcf.git/commit/?id=0013d5a2ccf61e58b021feead6ed66813ee50f65

Using below schemas(/usr/share/libvirt/schemas/interface.rng), libvirt can handle the bug.
  <define name="protocol-ipv4">
    <element name="protocol">
      <attribute name="family">
        <value>ipv4</value>
      </attribute>
      <interleave>
        <optional>
          <ref name="dhcp-element"/>
        </optional>
            <oneOrMore>
              <element name="ip">
                <attribute name="address"><ref name="ipv4Addr"/></attribute>
                <optional>
                  <attribute name="prefix"><ref name="ipv4Prefix"/></attribute>
                </optional>
              </element>
            </oneOrMore>
            <optional>
              <element name="route">
                <attribute name="gateway"><ref name="ipv4Addr"/></attribute>
              </element>
            </optional>
      </interleave>
    </element>
  </define>

[root@localhost ~]# virt-xml-validate eth1.xml
eth1.xml validates

Comment 2 Laine Stump 2015-05-21 14:21:45 UTC
You are correct. libvirt's interface.rng should mirror netcf's, but I forgot to update it when I added new capabilities to netcf.

Comment 3 Laine Stump 2015-05-21 17:53:18 UTC
Fix posted upstream, awaiting review:

https://www.redhat.com/archives/libvir-list/2015-May/msg00746.html

Comment 4 Laine Stump 2015-05-26 14:46:59 UTC
Pushed upstream, will be in 1.2.16:

commit ba5566e80f95618c3bb8ac327d4a1c370539166d
Author: Laine Stump <laine>
Date:   Thu May 21 11:26:52 2015 -0400

    interface: allow multiple IPv4 addresses + dhcp on a single interface

Comment 7 Shanzhi Yu 2015-07-21 09:05:14 UTC
Verify this bug with 
libvirt-client-1.2.17-2.el7.x86_64
libvirt-1.2.17-2.el7.x86_64


# virt-xml-validate /dev/stdin <<EOF
<interface type='ethernet' name='eth1'>
  <start mode='none'/>
  <mac address='00:1B:21:27:4E:CE'/>
  <mtu size='1500'/>
  <protocol family='ipv4'>
    <dhcp/>                                  
    <ip address='192.168.1.111' prefix='24'/>
  </protocol>
  <protocol family='ipv6'>
    <dhcp/>                                      
    <ip address='2001:db8:ca2:2::1' prefix='64'/>
  </protocol>
</interface>
EOF

/dev/stdin validates

# virt-xml-validate /dev/stdin <<EOF
<interface type='ethernet' name='eth1'>
  <start mode='none'/>
  <mac address='00:1B:21:27:4E:CE'/>
  <mtu size='1500'/>
  <protocol family='ipv4'>
    <dhcp/>
    <ip address='192.168.1.111' prefix='24'/>
  </protocol>
</interface>              
EOF         

/dev/stdin validates

# virt-xml-validate /dev/stdin <<EOF
<interface type='ethernet' name='eth1'>
  <start mode='none'/>
  <mac address='00:1B:21:27:4E:CE'/>
  <mtu size='1500'/>
  <protocol family='ipv6'>
    <dhcp/>
    <ip address='2001:db8:ca2:2::1' prefix='64'/>
  </protocol>                                    
</interface>                                    
EOF                                             

/dev/stdin validates

Comment 9 errata-xmlrpc 2015-11-19 06:31:27 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