Skip to content

Commit

Permalink
libvirt: Only ask tpool.Proxy to autowrap vir* classes
Browse files Browse the repository at this point in the history
I668643c836d46a25df46d4c99a973af5e50a39db attempted to fix service wide
pauses by providing a more complete list of classes to tpool.Proxy.

While this excluded libvirtError it can include internal libvirt-python
classes pointed to by private globals that have been introduced with the
use of type checking within the module.

Any attempt to wrap these internal classes will result in the failure
seen in bug #1901383. As a result this change simply ignores any class
found during inspection that doesn't start with the `vir` string, used
by libvirt to denote public methods and classes.

Closes-Bug: #1901383
Co-Authored-By: Daniel Berrange <[email protected]>
Change-Id: I568b0c4fd6069b9118ff116532f14abb46cc42ab
(cherry picked from commit 0d2ca53)
(cherry picked from commit 048a333)
  • Loading branch information
lyarwood committed Nov 3, 2020
1 parent 29425d6 commit 36cb57d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
10 changes: 10 additions & 0 deletions nova/tests/unit/virt/libvirt/fakelibvirt.py
Original file line number Diff line number Diff line change
Expand Up @@ -1714,6 +1714,16 @@ def make_libvirtError(error_class, msg, error_code=None,
virNWFilter = NWFilter


# A private libvirt-python class and global only provided here for testing to
# ensure it's not returned by libvirt.host.Host.get_libvirt_proxy_classes.
class FakeHandler(object):
def __init__(self):
pass


_EventAddHandleFunc = FakeHandler


class FakeLibvirtFixture(fixtures.Fixture):
"""Performs global setup/stubbing for all libvirt tests.
"""
Expand Down
3 changes: 2 additions & 1 deletion nova/tests/unit/virt/libvirt/test_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -1322,8 +1322,9 @@ def test_get_libvirt_proxy_classes(self):
self.assertIn(fakelibvirt.virSecret, proxy_classes)
self.assertIn(fakelibvirt.virNWFilter, proxy_classes)

# Assert that we filtered out libvirtError
# Assert that we filtered out libvirtError and any private classes
self.assertNotIn(fakelibvirt.libvirtError, proxy_classes)
self.assertNotIn(fakelibvirt._EventAddHandleFunc, proxy_classes)

def test_tpool_get_connection(self):
# Test that Host.get_connection() returns a tpool.Proxy
Expand Down
8 changes: 4 additions & 4 deletions nova/virt/libvirt/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,15 @@ def __init__(self, uri, read_only=False,
@staticmethod
def _get_libvirt_proxy_classes(libvirt_module):
"""Return a tuple for tpool.Proxy's autowrap argument containing all
classes defined by the libvirt module except libvirtError.
public vir* classes defined by the libvirt module.
"""

# Get a list of (name, class) tuples of libvirt classes
classes = inspect.getmembers(libvirt_module, inspect.isclass)

# Return a list of just the classes, filtering out libvirtError because
# we don't need to proxy that
return tuple([cls[1] for cls in classes if cls[0] != 'libvirtError'])
# Return a list of just the vir* classes, filtering out libvirtError
# and any private globals pointing at private internal classes.
return tuple([cls[1] for cls in classes if cls[0].startswith("vir")])

def _wrap_libvirt_proxy(self, obj):
"""Return an object wrapped in a tpool.Proxy using autowrap appropriate
Expand Down

0 comments on commit 36cb57d

Please sign in to comment.