NoneType is returned from libvirt while get_vcpu_used

Bug #1294509 reported by wangpan
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Compute (nova)
In Progress
Undecided
wangpan

Bug Description

166825 2014-03-19 14:44:46.132 43907 TRACE nova.openstack.common.periodic_task File "/usr/lib/python2.7/dist-packages/nova/virt/libvirt/driver.py", line 4528, in get_available_resource
166826 2014-03-19 14:44:46.132 43907 TRACE nova.openstack.common.periodic_task stats = self.host_state.get_host_stats(refresh=True)
166827 2014-03-19 14:44:46.132 43907 TRACE nova.openstack.common.periodic_task File "/usr/lib/python2.7/dist-packages/nova/virt/libvirt/driver.py", line 5603, in get_host_stats
166828 2014-03-19 14:44:46.132 43907 TRACE nova.openstack.common.periodic_task self.update_status()
166829 2014-03-19 14:44:46.132 43907 TRACE nova.openstack.common.periodic_task File "/usr/lib/python2.7/dist-packages/nova/virt/libvirt/driver.py", line 5639, in update_status
166830 2014-03-19 14:44:46.132 43907 TRACE nova.openstack.common.periodic_task data["vcpus_used"] = self.driver.get_vcpu_used()
166831 2014-03-19 14:44:46.132 43907 TRACE nova.openstack.common.periodic_task File "/usr/lib/python2.7/dist-packages/nova/virt/libvirt/driver.py", line 4207, in get_vcpu_used
166832 2014-03-19 14:44:46.132 43907 TRACE nova.openstack.common.periodic_task total += len(vcpus[1])
166833 2014-03-19 14:44:46.132 43907 TRACE nova.openstack.common.periodic_task TypeError: 'NoneType' object has no attribute '__getitem__'
166834 2014-03-19 14:44:46.132 43907 TRACE nova.openstack.common.periodic_task

this bug is because of my commit as below,
Reviewed: https://review.openstack.org/67361
Committed: https://git.openstack.org/cgit/openstack/nova/commit/?id=844df860c38ac38550b8d1739fd53131cd7fd864
Submitter: Jenkins
Branch: master

commit 844df860c38ac38550b8d1739fd53131cd7fd864
Author: Wangpan <email address hidden>
Date: Fri Jan 17 10:35:12 2014 +0800

    libvirt: handle exception while get vcpu info

    If an exception is raised while get a libvirt domain's vcpu info,
    the update_available_resource periodic task will be failed, which
    will result in the resource of this compute node will never be
    reported.

    This patch add an exception handling to avoid this situation.
    Closes-bug: #1270008

the checking of return value is None was removed, but old python-libvirt(e.g. 0.9.x) only raise libvirtError while the libvirt api return -1, and the old libvirt return None rather than -1 while get vcpu info failed, please see the libvirt codes below:
python/libvirt-override.c:
static PyObject *
libvirt_virDomainGetVcpus(PyObject *self ATTRIBUTE_UNUSED,
                          PyObject *args) {
    virDomainPtr domain;
    PyObject *pyobj_domain, *pyretval = NULL, *pycpuinfo = NULL, *pycpumap = NULL;
    virNodeInfo nodeinfo;
    virDomainInfo dominfo;
    virVcpuInfoPtr cpuinfo = NULL;
    unsigned char *cpumap = NULL;
    size_t cpumaplen, i;
    int i_retval;

    if (!PyArg_ParseTuple(args, (char *)"O:virDomainGetVcpus",
                          &pyobj_domain))
        return NULL;
    domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);

    LIBVIRT_BEGIN_ALLOW_THREADS;
    i_retval = virNodeGetInfo(virDomainGetConnect(domain), &nodeinfo);
    LIBVIRT_END_ALLOW_THREADS;
    if (i_retval < 0)
        return VIR_PY_NONE;

    LIBVIRT_BEGIN_ALLOW_THREADS;
    i_retval = virDomainGetInfo(domain, &dominfo);
    LIBVIRT_END_ALLOW_THREADS;
    if (i_retval < 0)
        return VIR_PY_NONE;

    if (VIR_ALLOC_N(cpuinfo, dominfo.nrVirtCpu) < 0)
        return VIR_PY_NONE;

so we should add the None type checking to libvirt driver for the compatibility of old libvirt.

wangpan (hzwangpan)
description: updated
Changed in nova:
assignee: nobody → wangpan (hzwangpan)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to nova (master)

Fix proposed to branch: master
Review: https://review.openstack.org/81475

Changed in nova:
status: New → In Progress
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.