Skip to content

Commit 048a333

Browse files
lyarwoodberrange
andcommitted
libvirt: Only ask tpool.Proxy to autowrap vir* classes
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)
1 parent 61717ff commit 048a333

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

nova/tests/unit/virt/libvirt/fakelibvirt.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1803,6 +1803,16 @@ def make_libvirtError(error_class, msg, error_code=None,
18031803
virSecret = Secret
18041804

18051805

1806+
# A private libvirt-python class and global only provided here for testing to
1807+
# ensure it's not returned by libvirt.host.Host.get_libvirt_proxy_classes.
1808+
class FakeHandler(object):
1809+
def __init__(self):
1810+
pass
1811+
1812+
1813+
_EventAddHandleFunc = FakeHandler
1814+
1815+
18061816
class FakeLibvirtFixture(fixtures.Fixture):
18071817
"""Performs global setup/stubbing for all libvirt tests.
18081818
"""

nova/tests/unit/virt/libvirt/test_host.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1387,8 +1387,9 @@ def test_get_libvirt_proxy_classes(self):
13871387
self.assertIn(fakelibvirt.virNodeDevice, proxy_classes)
13881388
self.assertIn(fakelibvirt.virSecret, proxy_classes)
13891389

1390-
# Assert that we filtered out libvirtError
1390+
# Assert that we filtered out libvirtError and any private classes
13911391
self.assertNotIn(fakelibvirt.libvirtError, proxy_classes)
1392+
self.assertNotIn(fakelibvirt._EventAddHandleFunc, proxy_classes)
13921393

13931394
def test_tpool_get_connection(self):
13941395
# Test that Host.get_connection() returns a tpool.Proxy

nova/virt/libvirt/host.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,15 @@ def __init__(self, uri, read_only=False,
127127
@staticmethod
128128
def _get_libvirt_proxy_classes(libvirt_module):
129129
"""Return a tuple for tpool.Proxy's autowrap argument containing all
130-
classes defined by the libvirt module except libvirtError.
130+
public vir* classes defined by the libvirt module.
131131
"""
132132

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

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

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

0 commit comments

Comments
 (0)