Bug 1077572

Summary: Python setInterfaceParameters function is broken
Product: Red Hat Enterprise Linux 7 Reporter: Michal Privoznik <mprivozn>
Component: libvirtAssignee: Michal Privoznik <mprivozn>
Status: CLOSED ERRATA QA Contact: Virtualization Bugs <virt-bugs>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 7.0CC: dyuan, honzhang, mzhan, rbalakri, weizhan, xuzhang
Target Milestone: rcKeywords: Upstream
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: libvirt-1.2.7-1.el7 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2015-03-05 07:32:48 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 Michal Privoznik 2014-03-18 09:24:06 UTC
Description of problem:
When using setInterfaceParamters from python binding, all that one can get is an error. No useful work is done.

Version-Release number of selected component (if applicable):


How reproducible:
100%

Steps to Reproduce:
1. Run:

import libvirt

conn = libvirt.open(None)
if conn == None:
        print 'Failed to connect';
        sys.exit(1)

for id in conn.listDomainsID():
        dom = conn.lookupByID(id)
        if dom == None:
                continue

        params = dom.interfaceParameters('vnet0', 0)
        print params
        dom.setInterfaceParameters('vnet0', params, 0)



2. Observe error:

libvirt.libvirtError: argument unsupported: parameter '' not supported 

Actual results:


Expected results:


Additional info:

Comment 1 Michal Privoznik 2014-03-18 13:44:29 UTC
Pushed upstream (into separate libvirt-python.git):

commit 69c4600d61fa74c4977d2471a29fb73f0fe5edb0
Author:     Michal Privoznik <mprivozn>
AuthorDate: Tue Mar 18 09:20:00 2014 +0100
Commit:     Michal Privoznik <mprivozn>
CommitDate: Tue Mar 18 14:43:10 2014 +0100

    setPyVirTypedParameter: free whole return variable on error
    
    The @ret value is built in a loop. However, if in one iteration
    there's an error, we should free all the fields built so far. For
    instance, if there's an error and the previous item was
    type of VIR_TYPED_PARAM_STRING we definitely must free it.
    
    Signed-off-by: Michal Privoznik <mprivozn>

commit 412c93a7b9111ad15c543e286f23bb5891749c42
Author:     Michal Privoznik <mprivozn>
AuthorDate: Tue Mar 18 09:12:24 2014 +0100
Commit:     Michal Privoznik <mprivozn>
CommitDate: Tue Mar 18 14:43:00 2014 +0100

    setPyVirTypedParameter: Copy full field name
    
    In the setPyVirTypedParameter we try to produce virTypedParameter
    array from a python dictionary. However, when copying field name into
    item in returned array, we use strncpy() as the field name is fixed
    length array. To determine its size we use sizeof() but mistakenly
    dereference it resulting in sizeof(char) which equals to 1 byte.
    Moreover, there's no need for using sizeof() when we have a global
    macro to tell us the length of the field name:
    VIR_TYPED_PARAM_FIELD_LENGTH.
    
    And since array is allocated using VIR_ALLOC() we are sure the memory
    is initially filled with zeros. Hence, there's no need to terminate
    string we've just copied into field name with '\0' character. It's
    there for sure too as we copy up to field length - 1.
    
    Signed-off-by: Michal Privoznik <mprivozn>


v1.2.2-3-g69c4600

Comment 3 hongming 2014-11-24 07:20:47 UTC
Verify it as follows. The result is expected. Move its status to VERIFIED.


# rpm -q libvirt libvirt-python
libvirt-1.2.8-8.el7.x86_64
libvirt-python-1.2.8-5.el7.x86_64


# virsh start r7
Domain r7 started


# virsh dumpxml r7|grep interface -A11
    <interface type='network'>
      <mac address='52:54:00:b1:ab:72'/>
      <source network='default'/>
      <bandwidth>
        <inbound average='1000' peak='5000' burst='1024'/>
        <outbound average='128' peak='256' burst='256'/>
      </bandwidth>
      <target dev='vnet0'/>
      <model type='rtl8139'/>
      <alias name='net0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>
    </interface>
    <interface type='network'>
      <mac address='52:54:00:c9:8d:7f'/>
      <source network='default'/>
      <target dev='vnet1'/>
      <model type='rtl8139'/>
      <alias name='net1'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
    </interface>



# cat test.py 
import libvirt

conn = libvirt.open(None)
if conn == None:
        print 'Failed to connect';
        sys.exit(1)

for id in conn.listDomainsID():
        dom = conn.lookupByName('r7')
        if dom == None:
                continue

        params_vnet0 = dom.interfaceParameters('vnet0', 0)
        print 'The params of vnet0 is %s' % params_vnet0

        params_vnet1 = dom.interfaceParameters('vnet1', 0)
        print 'The params of vnet1 is %s' % params_vnet1

        dom.setInterfaceParameters('vnet0', params_vnet1, 0)
        params_vnet0_new = dom.interfaceParameters('vnet0', 0)
        print 'The new params of vnet0 is %s' % params_vnet0_new
     
        dom.setInterfaceParameters('vnet1', params_vnet0, 0)
        params_vnet1_new = dom.interfaceParameters('vnet1', 0)
        print 'The new params of vnet1 is %s' % params_vnet1_new


# python test.py
The params of vnet0 is {'outbound.peak': 256, 'inbound.peak': 5000, 'inbound.burst': 1024, 'inbound.average': 1000, 'outbound.average': 128, 'outbound.burst': 256}
The params of vnet1 is {'outbound.peak': 0, 'inbound.peak': 0, 'inbound.burst': 0, 'inbound.average': 0, 'outbound.average': 0, 'outbound.burst': 0}
The new params of vnet0 is {'outbound.peak': 0, 'inbound.peak': 0, 'inbound.burst': 0, 'inbound.average': 0, 'outbound.average': 0, 'outbound.burst': 0}
The new params of vnet1 is {'outbound.peak': 256, 'inbound.peak': 5000, 'inbound.burst': 1024, 'inbound.average': 1000, 'outbound.average': 128, 'outbound.burst': 256}


# virsh dumpxml r7|grep interface -A11
    <interface type='network'>
      <mac address='52:54:00:b1:ab:72'/>
      <source network='default'/>
      <target dev='vnet0'/>
      <model type='rtl8139'/>
      <alias name='net0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>
    </interface>
    <interface type='network'>
      <mac address='52:54:00:c9:8d:7f'/>
      <source network='default'/>
      <bandwidth>
        <inbound average='1000' peak='5000' burst='1024'/>
        <outbound average='128' peak='256' burst='256'/>
      </bandwidth>
      <target dev='vnet1'/>
      <model type='rtl8139'/>
      <alias name='net1'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
    </interface>

Comment 5 errata-xmlrpc 2015-03-05 07:32:48 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/RHSA-2015-0323.html