Unit tests can fail if python guestfs is installed in the test environment
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
OpenStack Compute (nova) |
Fix Released
|
Undecided
|
melanie witt |
Bug Description
Ran into this downstream [1] where a unit test failed because it actually tried to call libvirt, which of course failed:
libguestfs: error: could not create appliance through libvirt.
Try running qemu directly without libvirt using this environment variable:
export LIBGUESTFS_
Original error from libvirt: internal error: qemu unexpectedly closed the monitor: 2022-10-
{5} nova.tests.
Captured traceback:
~~~~~~~~~~~~~~~~~~~
Traceback (most recent call last):
File "/home/
File "/home/
File "/home/
File "/usr/lib/
result = proxy_call(
File "/usr/lib/
rv = execute(f, *args, **kwargs)
File "/usr/lib/
rv = e.wait()
File "/usr/lib/
result = hub.switch()
File "/usr/lib/
return self.greenlet.
File "/usr/lib/
File "/usr/lib/
presult = self.do_
File "/usr/lib/
return self.poll.
File "/usr/lib/
raise TimeoutException()
fixtures.
That ^ was with libguestfs 1.46.1.
Repro steps (not identical traceback but close):
1. Make sure you have libguestfs header files
$ sudo apt install libguestfs-dev
2. Enter the unit test venv
$ source .tox/py38/
3. Install the libguestfs python bindings into the venv. This has to be done by tarball [2]. Note that the bindings were not built for python 3 until version 1.40 [3]
$ pip install http://
4. Run the unit test
$ tox -epy38 test_can_
5. The test should fail
The code in nova will call libvirt if guestfs is installed [4] and if it is not installed, it will emit a warning and move on [5]. In my repro environment it didn't get as far as a call to libvirt though.
Upstream the test doesn't fail because neither libvirt nor guestfs are installed in the CI environment for unit test jobs.
A unit test shouldn't be able to call out to real guestfs or libvirt and it wasn't mocked out properly.
We can address it by adding mocking to the unit test and create a fixture that will poison future imports by unit or func tests.
[1] https:/
[2] https:/
[3] https:/
[4] https:/
[5] https:/
description: | updated |
Fix proposed to branch: master /review. opendev. org/c/openstack /nova/+ /862769
Review: https:/