libvirt unit tests are failing if no real libvirt installed

Bug #1414708 reported by Matt Riedemann
12
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Compute (nova)
Fix Released
Low
Matt Riedemann

Bug Description

Something changed since 1/20 where the nova.tests.unit.virt.libvirt.test_driver tests would pass if you didn't have a real libvirt installed but now they fail if you don't have libvirt installed, e.g.:

    Traceback (most recent call last):
      File "nova/tests/unit/virt/libvirt/test_driver.py", line 4062, in test_xml_and_uri_rescue_no_kernel
        expect_ramdisk=True, rescue=instance_data)
      File "/home/mriedem/git/nova/.tox/py27/local/lib/python2.7/site-packages/mock.py", line 1201, in patched
        return func(*args, **keywargs)
      File "nova/tests/unit/virt/libvirt/test_driver.py", line 5601, in _check_xml_and_uri
        rescue=rescue)
      File "nova/virt/libvirt/driver.py", line 4006, in _get_guest_xml
        context, flavor=flavor)
      File "nova/virt/libvirt/driver.py", line 3819, in _get_guest_config
        instance.numa_topology, flavor, allowed_cpus)
      File "nova/virt/libvirt/driver.py", line 3384, in _get_guest_numa_config
        topology = self._get_host_numa_topology()
      File "nova/virt/libvirt/driver.py", line 4580, in _get_host_numa_topology
        if not self._host.has_min_version(MIN_LIBVIRT_NUMA_TOPOLOGY_VERSION):
      File "nova/virt/libvirt/host.py", line 433, in has_min_version
        conn = self.get_connection()
      File "nova/virt/libvirt/host.py", line 415, in get_connection
        raise exception.HypervisorUnavailable(host=CONF.host)
    HypervisorUnavailable: Connection to the hypervisor is broken on host: fake-mini

I suspect something was missed in this change:

https://github.com/openstack/nova/commit/4b9bec3a1c819e7006af6bfa1de6928bde91b2c7

Revision history for this message
Matt Riedemann (mriedem) wrote :

Actually this is probably invalid, I don't have libvirt-python in my test-requirements.txt and that's what should satisfy the requirement - even though we *should* be able to resolve this with something in the fakelibvirt fixture.

Revision history for this message
Matt Riedemann (mriedem) wrote :

To recreate with the master branch, simply comment out or remove the libvirt-python entry from test-requirements.txt and then:

tox -r -e py27 -- nova.tests.unit.virt.libvirt.test_driver

I think we should just mock out host.Host.has_min_version to always return True for the LibvirtConnTestCase since we should assume any code we're unit testing should be available on the latest libvirt available from a/the distro we're running integration tests against.

Changed in nova:
status: New → Triaged
importance: Undecided → Low
assignee: nobody → Matt Riedemann (mriedem)
Revision history for this message
Matt Riedemann (mriedem) wrote :

Mocking out has_min_version doesn't fix it all, there is code trying to get capabilities that blows up and I'm also hitting some weird issues in the init method of the fakelibvirt Connection class where it's getting xen:/// as the uri (no system or session string in the uri).

Revision history for this message
Matt Riedemann (mriedem) wrote :

Oh I see, the uri is coming from the LibvirtDriver.uri() static method:

    @staticmethod
    def uri():
        if CONF.libvirt.virt_type == 'uml':
            uri = CONF.libvirt.connection_uri or 'uml:///system'
        elif CONF.libvirt.virt_type == 'xen':
            uri = CONF.libvirt.connection_uri or 'xen:///'
        elif CONF.libvirt.virt_type == 'lxc':
            uri = CONF.libvirt.connection_uri or 'lxc:///'
        else:
            uri = CONF.libvirt.connection_uri or 'qemu:///system'
        return uri

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/150148

Changed in nova:
status: Triaged → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to nova (master)

Reviewed: https://review.openstack.org/150148
Committed: https://git.openstack.org/cgit/openstack/nova/commit/?id=50861d3221f625a5cc589d903054bb2c440b4026
Submitter: Jenkins
Branch: master

commit 50861d3221f625a5cc589d903054bb2c440b4026
Author: Matt Riedemann <email address hidden>
Date: Mon Jan 26 13:12:52 2015 -0800

    libvirt: update uri_whitelist in fakelibvirt.Connection

    Commit 4b9bec3a1c819e7006af6bfa1de6928bde91b2c7 removed the mocking of
    nova.virt.libvirt.host.Host.get_connection to use fakelibvirt instead,
    but if you don't have libvirt-python in your venv the tests fail, so
    fakelibvirt in it's current form wasn't actually working for all tests.

    This change updates the uri_whitelist in the init method of the
    fakelibvirt Connection class to add some other URIs found in other parts
    of the libvirt code (the LibvirtDriver.uri static method).

    Removes the unnecessary 'xen:///system' whitelisted URI.

    Since libvirt-python is no longer needed to run the libvirt driver
    unit tests, it's removed from test-requirements.txt.

    Closes-Bug: #1414708

    Change-Id: Id7aefe9bf21dc3d0e2db42e668faf28e926aea43

Changed in nova:
status: In Progress → Fix Committed
Thierry Carrez (ttx)
Changed in nova:
milestone: none → kilo-2
status: Fix Committed → Fix Released
Thierry Carrez (ttx)
Changed in nova:
milestone: kilo-2 → 2015.1.0
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

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