Merge "libvirt: Only ask tpool.Proxy to autowrap vir* classes" into stable/train

This commit is contained in:
Zuul 2021-02-20 06:30:38 +00:00 committed by Gerrit Code Review
commit 09d228d73c
3 changed files with 16 additions and 5 deletions

View File

@ -1702,6 +1702,16 @@ virSecret = Secret
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.
"""

View File

@ -1322,8 +1322,9 @@ class LibvirtTpoolProxyTestCase(test.NoDBTestCase):
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

View File

@ -124,15 +124,15 @@ class Host(object):
@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