Skip to content

Commit 9648d5c

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "libvirt: Only ask tpool.Proxy to autowrap vir* classes" into stable/victoria
2 parents 697ceb4 + 048a333 commit 9648d5c

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
@@ -1852,6 +1852,16 @@ def make_libvirtError(error_class, msg, error_code=None,
18521852
virSecret = Secret
18531853

18541854

1855+
# A private libvirt-python class and global only provided here for testing to
1856+
# ensure it's not returned by libvirt.host.Host.get_libvirt_proxy_classes.
1857+
class FakeHandler(object):
1858+
def __init__(self):
1859+
pass
1860+
1861+
1862+
_EventAddHandleFunc = FakeHandler
1863+
1864+
18551865
class FakeLibvirtFixture(fixtures.Fixture):
18561866
"""Performs global setup/stubbing for all libvirt tests.
18571867
"""

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)